tomMoulard / htransformation

A Traefik plugin to change on the fly header's value of a request
MIT License
77 stars 13 forks source link

Example labels based configuration #37

Closed thaDude closed 1 year ago

thaDude commented 1 year ago

Hello,

Can the configuration for this plugin be provided through labels instead of yaml? This would match our current way of configuring Traefik and its middlewares on our services deployed through Docker Swarm. The only example for configuration I found was here.

Where can I find some more (official) examples?

Thank you,

David

tomMoulard commented 1 year ago

Hello @thaDude,

Thanks for your interest in this Traefik plugin!

Indeed, we are missing a label example in the documentation.

Either way, here is an example:

version: '3.9'

services:
  traefik:
    image: traefik:v2.8
    command:
      - --providers.docker
      - --experimental.plugins.htransformation.modulename=github.com/tomMoulard/htransformation
      - --experimental.plugins.htransformation.version=v0.2.5
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  whoami:
    image: traefik/whoami
    labels:
      traefik.http.routers.whoami.rule: Host(`whoami.localhost`)
      traefik.http.routers.whoami.middlewares: myhtransformation

      traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Header: NewHeader
      traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Name: header addition
      traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Type: Set
      traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Value: True
$ curl http://whoami.localhost
GET / HTTP/1.1
Host: whoami.localhost
...
Newheader: true