From 61094cb867c40bc682d45bfcd59f08ba512af25a Mon Sep 17 00:00:00 2001 From: Brian Ojeda <9335829+sgtoj@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:26:59 -0500 Subject: [PATCH] feat: add support for base path --- .env.example | 3 +++ cmd/lambda/main.go | 13 +++++++++++-- internal/config/config.go | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index c0fe879..a3868a7 100644 --- a/.env.example +++ b/.env.example @@ -26,3 +26,6 @@ APP_OKTA_SYNC_RULES=[{"name":"sync-eng","enabled":true,"okta_group_pattern":"^gi # slack configuration (optional) APP_SLACK_TOKEN=xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx APP_SLACK_CHANNEL=C01234ABCDE + +# api gateway base path (optional, for lambda deployments with stage prefix) +# APP_BASE_PATH=v1 diff --git a/cmd/lambda/main.go b/cmd/lambda/main.go index 8a1375c..01e6fc9 100644 --- a/cmd/lambda/main.go +++ b/cmd/lambda/main.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "log/slog" + "strings" "sync" awsevents "github.com/aws/aws-lambda-go/events" @@ -57,11 +58,19 @@ func APIGatewayHandler(ctx context.Context, req awsevents.APIGatewayProxyRequest logger.Debug("received api gateway request", slog.String("request", string(j))) } - if req.Path == "/server/status" { + path := req.Path + if appInst.Config.BasePath != "" { + path = strings.TrimPrefix(path, appInst.Config.BasePath) + if path == "" { + path = "/" + } + } + + if path == "/server/status" { return handleServerStatus(ctx, req) } - if req.Path == "/server/config" { + if path == "/server/config" { return handleServerConfig(ctx, req) } diff --git a/internal/config/config.go b/internal/config/config.go index 11731b8..8014239 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -49,6 +49,8 @@ type Config struct { SlackToken string SlackChannel string SlackAPIURL string + + BasePath string } var ( @@ -246,6 +248,12 @@ func NewConfigWithContext(ctx context.Context) (*Config, error) { cfg.SlackEnabled = cfg.SlackToken != "" && cfg.SlackChannel != "" + basePath := os.Getenv("APP_BASE_PATH") + if basePath != "" { + basePath = "/" + strings.Trim(basePath, "/") + } + cfg.BasePath = basePath + orphanedUserNotifications, _ := strconv.ParseBool(os.Getenv("APP_OKTA_ORPHANED_USER_NOTIFICATIONS")) if os.Getenv("APP_OKTA_ORPHANED_USER_NOTIFICATIONS") == "" { orphanedUserNotifications = cfg.IsOktaSyncEnabled() @@ -345,6 +353,8 @@ type RedactedConfig struct { SlackToken string `json:"slack_token"` SlackChannel string `json:"slack_channel"` SlackAPIURL string `json:"slack_api_url"` + + BasePath string `json:"base_path"` } // Redacted returns a copy of the config with secrets redacted. @@ -386,5 +396,6 @@ func (c *Config) Redacted() RedactedConfig { SlackToken: redact(c.SlackToken), SlackChannel: c.SlackChannel, SlackAPIURL: c.SlackAPIURL, + BasePath: c.BasePath, } }