diff --git a/auth/.env.example b/auth/.env.example index 76eae223..bf462faa 100644 --- a/auth/.env.example +++ b/auth/.env.example @@ -1,6 +1,9 @@ # vi: ft=sh # shellcheck disable=SC2034 +# http route prefix (will listen to $KEIBI_PREFIX/users for example) +KEIBI_PREFIX="" + # Database things POSTGRES_USER=kyoo POSTGRES_PASSWORD=password diff --git a/auth/config.go b/auth/config.go index 927a4827..f49352db 100644 --- a/auth/config.go +++ b/auth/config.go @@ -6,6 +6,7 @@ import ( "crypto/rsa" "crypto/x509" "encoding/pem" + "os" "time" "github.com/golang-jwt/jwt/v5" @@ -13,6 +14,7 @@ import ( ) type Configuration struct { + Prefix string JwtPrivateKey *rsa.PrivateKey JwtPublicKey *rsa.PublicKey Issuer string @@ -52,6 +54,8 @@ func LoadConfiguration(db *dbc.Queries) (*Configuration, error) { } } + ret.Prefix = os.Getenv("KEIBI_PREFIX") + if ret.JwtPrivateKey == nil { ret.JwtPrivateKey, err = rsa.GenerateKey(rand.Reader, 4096) if err != nil { diff --git a/auth/main.go b/auth/main.go index a6a04ae8..14a1bea8 100644 --- a/auth/main.go +++ b/auth/main.go @@ -163,29 +163,30 @@ func main() { } h.config = conf - r := e.Group("") + g := e.Group(conf.Prefix) + r := e.Group(conf.Prefix) r.Use(echojwt.WithConfig(echojwt.Config{ SigningMethod: "RS256", SigningKey: h.config.JwtPublicKey, })) - e.GET("/health", h.CheckHealth) + g.GET("/health", h.CheckHealth) r.GET("/users", h.ListUsers) r.GET("/users/:id", h.GetUser) r.GET("/users/me", h.GetMe) r.DELETE("/users/:id", h.DeleteUser) r.DELETE("/users/me", h.DeleteSelf) - e.POST("/users", h.Register) + g.POST("/users", h.Register) - e.POST("/sessions", h.Login) + g.POST("/sessions", h.Login) r.DELETE("/sessions", h.Logout) r.DELETE("/sessions/:id", h.Logout) - e.GET("/jwt", h.CreateJwt) - e.GET("/info", h.GetInfo) + g.GET("/jwt", h.CreateJwt) + g.GET("/info", h.GetInfo) - e.GET("/swagger/*", echoSwagger.WrapHandler) + g.GET("/swagger/*", echoSwagger.WrapHandler) e.Logger.Fatal(e.Start(":4568")) } diff --git a/docker-compose.build.yml b/docker-compose.build.yml index ef919785..44f31a7e 100644 --- a/docker-compose.build.yml +++ b/docker-compose.build.yml @@ -69,12 +69,11 @@ services: condition: service_healthy env_file: - ./.env + environment: + - KEIBI_PREFIX=/auth labels: - "traefik.enable=true" - "traefik.http.routers.auth.rule=PathPrefix(`/auth/`)" - - "traefik.http.routers.auth.middlewares=auth-sp" - - "traefik.http.middlewares.auth-sp.stripprefix.prefixes=/auth" - - "traefik.http.middlewares.auth-sp.stripprefix.forceSlash=false" profiles: - "v5" diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 88d10383..79523ac4 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -97,14 +97,13 @@ services: - "4568:4568" env_file: - ./.env + environment: + - KEIBI_PREFIX=/auth volumes: - ./auth:/app labels: - "traefik.enable=true" - "traefik.http.routers.auth.rule=PathPrefix(`/auth/`)" - - "traefik.http.routers.auth.middlewares=auth-sp" - - "traefik.http.middlewares.auth-sp.stripprefix.prefixes=/auth" - - "traefik.http.middlewares.auth-sp.stripprefix.forceSlash=false" scanner: build: ./scanner