/Traefik unleash plugin

Traefik unleash plugin

4
v0.1.0

Quality Gate Status Coverage Code Smells Bugs Security Rating Vulnerabilities Duplicated Lines (%)

Traefik Unleash Middleware

This Traefik middleware validates requests against an Unleash (feature flag) server and rewrites the path, headers and host of the request based on input parameters defined in the YAML configuration file.

Table of Contents

Installation

Follow the Traefik instructions for installing plugins.

Configuration

To configure this middleware, you need to define the parameters in the dynamic.yml file.

Input Parameters

ParameterTypeRequiredDescription
urlstringYesURL of the Unleash server
appstringYesName of the application in Unleash
intervalintNoUpdate interval in seconds
metrics.intervalintNoMetrics reporting interval in seconds
toggleslistYesList of feature flag toggles
toggles[].featurestringYesName of the feature flag
toggles[].pathRewrite.pathMatcherstringNoPath to be validated
toggles[].pathRewrite.rewriteRulestringNoPath to redirect to if the feature flag is active
toggles[].hostRewrite.hostMatcherstringNoHost to be validated
toggles[].hostRewrite.rewriteRulestringNoHost to redirect to if the feature flag is active
toggles[].headerModiferslistNoList of headers to be added to the request or response
toggles[].headerModifiers[].headerNamestringYesHeader key
toggles[].headerModifiers[].headerValuestringYesHeader value
toggles[].headerModifiers[].contextstringYesContext of the header (either "request" or "response")
offlineModebooleanNoThe plugin is configured in local mode without external dependencies

Usage

  1. Define the configuration in the dynamic.yml file:

    unleash:
    url: "http://unleash:4242/api/"
    app: "test-app"
    interval: 10
    metrics:
    interval: 10
    toggles:
    - feature: "test-toggle-user-id"
    pathRewrite:
    pathMatcher: "/foo"
    rewriteRule: "/bar"
    hostRewrite:
    hostMatcher: "localhost"
    rewriteRule: "whoami2"
    - feature: "test-toggle"
    pathRewrite:
    pathMatcher: "/bar"
    rewriteRule: "/foo"
    hostRewrite:
    hostMatcher: "localhost"
    rewriteRule: "whoami2"
    - feature: "test-toggle-path"
    pathRewrite:
    pathMatcher: "/john"
    rewriteRule: "/doe"
    - feature: "test-toggle-host"
    hostRewrite:
    hostMatcher: "localhost"
    rewriteRule: "whoami1"
  2. Apply the middleware to your routers in the Traefik configuration:

    http:
    routers:
    my-router:
    rule: "Host(`example.com`)"
    service: "my-service"
    middlewares:
    - "unleash"

Example

Here is a complete configuration example:

http:
routers:
my-router:
rule: "Host(`example.com`)"
service: "my-service"
middlewares:
- "unleash"
middlewares:
unleash:
plugin:
unleash:
url: "http://unleash:4242/api/"
app: "test-app"
interval: 10
metrics:
interval: 10
toggles:
- feature: "test-toggle-user-id"
pathRewrite:
pathMatcher: "/foo"
rewriteRule: "/bar"
hostRewrite:
hostMatcher: "localhost"
rewriteRule: "whoami2"
headerModifiers:
- headerName: "X-Foo"
headerValue: "Bar"
context: "request"
- headerName: "X-Served-By"
headerValue: "whoami2"
context: "response"
- feature: "test-toggle"
pathRewrite:
pathMatcher: "/bar"
rewriteRule: "/foo"
hostRewrite:
value: "localhost"
rewrite: "whoami2"
- feature: "test-toggle-path"
pathRewrite:
pathMatcher: "/john"
rewriteRule: "/doe"
- feature: "test-toggle-host"
hostRewrite:
hostMatcher: "localhost"
rewriteRule: "whoami1"

Contributing

Contributions are welcome! If you want to contribute, please open an issue or a pull request in this repository.

License

This project is licensed under the MIT License.