name: ImageHubRateLimit
version: 0.0.1
services:
  generic-istio-filter:
    type: EnvoyFilterIstio
    namespace: istio-test
    settings:
      configPatches:
        - applyTo: HTTP_FILTER
          match:
            context: SIDECAR_INBOUND
            proxy:
              proxyVersion: '^1\.9.*'
            listener:
              portNumber: 9091
              filterChain:
                filter:
                  name: envoy.http_connection_manager
                  subFilter:
                    name: envoy.router
          patch:
            operation: INSERT_BEFORE
            value:
              name: envoy.filter.http.wasm
              config_discovery:
                config_source:
                  ads: {}
                  initial_fetch_timeout: 0s
                type_urls: ["type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm"]
      workloadSelector:
        labels:
          app: api
          version: v1

  ratelimit-filter:
    type: EnvoyFilterIstio
    namespace: istio-test
    settings:
      configPatches:
        - applyTo: EXTENSION_CONFIG
          match:
            context: SIDECAR_INBOUND
          patch:
            operation: ADD
            value:
              name: envoy.filter.http.wasm
              typed_config:
                "@type": type.googleapis.com/udpa.type.v1.TypedStruct
                type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
                value:
                  config:
                    configuration:
                      "@type": type.googleapis.com/google.protobuf.StringValue
                      value: "rate_limit_filter"
                    root_id: "rate_limit_filter"
                    vm_config:
                      code:
                        remote:
                          http_uri:
                            uri: https://github.com/layer5io/image-hub/raw/master/rate-limit-filter/pkg/rate_limit_filter_bg.wasm
                          
                      runtime: envoy.wasm.runtime.v8
                      vm_id: rate_limit_filter
                      configuration:
                        "@type": type.googleapis.com/google.protobuf.StringValue
                        value: "WwogIHsKICAgICJuYW1lIjogIi9wdWxsIiwKICAgICJydWxlIjp7CiAgICAgICJydWxlVHlwZSI6ICJyYXRlLWxpbWl0ZXIiLAogICAgICAicGFyYW1ldGVycyI6WwogICAgICAgIHsiaWRlbnRpZmllciI6ICJFbnRlcnByaXNlIiwgImxpbWl0IjogMTAwMH0sCiAgICAgICAgeyJpZGVudGlmaWVyIjogIlRlYW0iLCAibGltaXQiOiAxMDB9LAogICAgICAgIHsiaWRlbnRpZmllciI6ICJQZXJzb25hbCIsICJsaW1pdCI6IDEwfQogICAgICBdCiAgICB9CiAgfSwKICB7CiAgICAibmFtZSI6ICIvYXV0aCIsCiAgICAicnVsZSI6ewogICAgICAicnVsZVR5cGUiOiAibm9uZSIKICAgIH0KICB9LAogIHsKICAgICJuYW1lIjogIi9zaWdudXAiLAogICAgInJ1bGUiOnsKICAgICAgInJ1bGVUeXBlIjogIm5vbmUiCiAgICB9CiAgfSwKICB7CiAgICAibmFtZSI6ICIvdXBncmFkZSIsCiAgICAicnVsZSI6ewogICAgICAicnVsZVR5cGUiOiAibm9uZSIKICAgIH0KICB9Cl0="
                      allow_precompiled: true
      workloadSelector:
        labels:
          app: api
          version: v1
    dependsOn:
      - generic-istio-filter