Skip to content

Commit

Permalink
Add gitlab-health-url flag and envvar (#800)
Browse files Browse the repository at this point in the history
Because GitLab requires a token for readiness and liveness checks so it might be desirable to store it in a Secret / environment variable instead of in the plaintext config.
This option is already documented in configuration_syntax.md but wasn't implemented.
  • Loading branch information
Thor77 committed Apr 17, 2024
1 parent 8f790ea commit 3ecfd66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/cli/cli.go
Expand Up @@ -64,6 +64,11 @@ func NewApp(version string, start time.Time) (app *cli.App) {
EnvVars: []string{"GCPE_WEBHOOK_SECRET_TOKEN"},
Usage: "`token` used to authenticate legitimate requests (overrides config file parameter)",
},
&cli.StringFlag{
Name: "gitlab-health-url",
EnvVars: []string{"GCPE_GITLAB_HEALTH_URL"},
Usage: "GitLab health URL (overrides config file parameter)",
},
},
},
{
Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/utils.go
Expand Up @@ -121,6 +121,11 @@ func configCliOverrides(ctx *cli.Context, cfg *config.Config) {
if ctx.String("redis-url") != "" {
cfg.Redis.URL = ctx.String("redis-url")
}

if healthURL := ctx.String("gitlab-health-url"); healthURL != "" {
cfg.Gitlab.HealthURL = healthURL
cfg.Gitlab.EnableHealthCheck = true
}
}

func assertStringVariableDefined(ctx *cli.Context, k string) {
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/utils_test.go
Expand Up @@ -84,6 +84,15 @@ server:
cfg, err = configure(ctx)
assert.NoError(t, err)
assert.Equal(t, "secret", cfg.Server.Webhook.SecretToken)

// Test health url flag
healthURL := "https://gitlab.com/-/readiness?token"
flags.String("gitlab-health-url", healthURL, "")

cfg, err = configure(ctx)
assert.NoError(t, err)
assert.Equal(t, cfg.Gitlab.HealthURL, healthURL)
assert.True(t, cfg.Gitlab.EnableHealthCheck)
}

func TestExit(t *testing.T) {
Expand Down

0 comments on commit 3ecfd66

Please sign in to comment.