Skip to content

Commit cf06dd7

Browse files
authored
Merge pull request #4 from cruxstack/dev
feat: add support for base path
2 parents 0b22ac7 + 61094cb commit cf06dd7

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ APP_OKTA_SYNC_RULES=[{"name":"sync-eng","enabled":true,"okta_group_pattern":"^gi
2626
# slack configuration (optional)
2727
APP_SLACK_TOKEN=xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2828
APP_SLACK_CHANNEL=C01234ABCDE
29+
30+
# api gateway base path (optional, for lambda deployments with stage prefix)
31+
# APP_BASE_PATH=v1

cmd/lambda/main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"fmt"
1010
"log/slog"
11+
"strings"
1112
"sync"
1213

1314
awsevents "github.com/aws/aws-lambda-go/events"
@@ -57,11 +58,19 @@ func APIGatewayHandler(ctx context.Context, req awsevents.APIGatewayProxyRequest
5758
logger.Debug("received api gateway request", slog.String("request", string(j)))
5859
}
5960

60-
if req.Path == "/server/status" {
61+
path := req.Path
62+
if appInst.Config.BasePath != "" {
63+
path = strings.TrimPrefix(path, appInst.Config.BasePath)
64+
if path == "" {
65+
path = "/"
66+
}
67+
}
68+
69+
if path == "/server/status" {
6170
return handleServerStatus(ctx, req)
6271
}
6372

64-
if req.Path == "/server/config" {
73+
if path == "/server/config" {
6574
return handleServerConfig(ctx, req)
6675
}
6776

internal/config/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type Config struct {
4949
SlackToken string
5050
SlackChannel string
5151
SlackAPIURL string
52+
53+
BasePath string
5254
}
5355

5456
var (
@@ -246,6 +248,12 @@ func NewConfigWithContext(ctx context.Context) (*Config, error) {
246248

247249
cfg.SlackEnabled = cfg.SlackToken != "" && cfg.SlackChannel != ""
248250

251+
basePath := os.Getenv("APP_BASE_PATH")
252+
if basePath != "" {
253+
basePath = "/" + strings.Trim(basePath, "/")
254+
}
255+
cfg.BasePath = basePath
256+
249257
orphanedUserNotifications, _ := strconv.ParseBool(os.Getenv("APP_OKTA_ORPHANED_USER_NOTIFICATIONS"))
250258
if os.Getenv("APP_OKTA_ORPHANED_USER_NOTIFICATIONS") == "" {
251259
orphanedUserNotifications = cfg.IsOktaSyncEnabled()
@@ -345,6 +353,8 @@ type RedactedConfig struct {
345353
SlackToken string `json:"slack_token"`
346354
SlackChannel string `json:"slack_channel"`
347355
SlackAPIURL string `json:"slack_api_url"`
356+
357+
BasePath string `json:"base_path"`
348358
}
349359

350360
// Redacted returns a copy of the config with secrets redacted.
@@ -386,5 +396,6 @@ func (c *Config) Redacted() RedactedConfig {
386396
SlackToken: redact(c.SlackToken),
387397
SlackChannel: c.SlackChannel,
388398
SlackAPIURL: c.SlackAPIURL,
399+
BasePath: c.BasePath,
389400
}
390401
}

0 commit comments

Comments
 (0)