Ambassador: Implement Envoy regex_rewrite in Ambassador

Created on 14 May 2020  路  1Comment  路  Source: datawire/ambassador

Please describe your use case / problem.
I have an API which exposes multiple entities. For example /clients and /contacts we want both of these exposed on a separate URL for portability (might split them into separate services) but they are now answered by the same service.

Currently this is possible like this:

---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: api-contacts
spec:
  prefix: /v1/contacts
  rewrite: /contacts
  service: api
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: api-clients
spec:
  prefix: /v1/clients
  rewrite: /clients
  service: api

But this results in Ambassador crawling the docs at api/contacts/.ambassador-internal/openapi-docs which isn't right since the docs for the api live at the root api/.ambassador-internal/openapi-docs.
Also in the developer portal these show up as two APIs but it is just one with two exposed entities.

The current regex implementation does not resolve this:

---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: api
spec:
  prefix: /v1/(clients|contacts)
  prefix_regex: true
  service: api

This will get the docs correctly crawled but the entity request ambassador/clients will end up at api/ and not api/clients

Describe the solution you'd like
Implement the new regex_rewrite of Envoy into Ambassador.
PR: envoyproxy/envoy/pull/10050
Docs section: https://www.envoyproxy.io/docs/envoy/v1.14.1/api-v2/api/v2/route/route_components.proto#envoy-api-field-route-routeaction-regex-rewrite

That should make a mapping like this possible:

---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: api
spec:
  prefix: /v1/(clients|contacts)
  prefix_regex: true
  regex_rewrite: /\1
  service: api

But this still doesn't resolve the docs being crawled at api/clients/.ambassador-internal/openapi-docs

Additional context
Related issue more or less asking the same feature: #1162 #805 #2136

feature

Most helpful comment

The Ambassador's regex_rewrite feature is released today.

Now you can change your Mapping to something like:

apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: api
spec:
  prefix: /v1/
  regex_rewrite:
    pattern: "/v1/(clients|contacts)"
    substitution: "/\\1"
  service: api

Given the prefix v1 in this Mapping, your docs will be crawled at v1/.ambassador-internal/openapi-docs as specified here.

For more information about URL rewrites in Ambassador, please check the Rewrites page.

>All comments

The Ambassador's regex_rewrite feature is released today.

Now you can change your Mapping to something like:

apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: api
spec:
  prefix: /v1/
  regex_rewrite:
    pattern: "/v1/(clients|contacts)"
    substitution: "/\\1"
  service: api

Given the prefix v1 in this Mapping, your docs will be crawled at v1/.ambassador-internal/openapi-docs as specified here.

For more information about URL rewrites in Ambassador, please check the Rewrites page.

Was this page helpful?
0 / 5 - 0 ratings