From d4c093be5629b6b6394063fb02a71528d0accc8a Mon Sep 17 00:00:00 2001 From: Laurent Luce Date: Sun, 25 Aug 2024 19:31:33 -0400 Subject: [PATCH] Add env vars for dev mode and analytics write key --- kontrol-service/api/analytics.go | 4 ++-- kontrol-service/main.go | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kontrol-service/api/analytics.go b/kontrol-service/api/analytics.go index 65c4919..28ff9f3 100644 --- a/kontrol-service/api/analytics.go +++ b/kontrol-service/api/analytics.go @@ -19,12 +19,12 @@ const ( ) // NewAnalyticsWrapper creates a new AnalyticsWrapper -func NewAnalyticsWrapper(isDevMode bool) *AnalyticsWrapper { +func NewAnalyticsWrapper(isDevMode bool, writeKey string) *AnalyticsWrapper { if !isDevMode { // This is the Segment write key for the "kontrol-service" project. It is not // a sensitive value, but it could be extracted to an env var in the future // to separate dev and prod traffic if desired. - client := analytics.New("1TeZVRY3ta9VYaNknKTCCKBZtcBllE6U") + client := analytics.New(writeKey) logrus.Info("Segment analytics client initialized") return &AnalyticsWrapper{client: &client} } diff --git a/kontrol-service/main.go b/kontrol-service/main.go index 25313e7..4a46999 100644 --- a/kontrol-service/main.go +++ b/kontrol-service/main.go @@ -13,16 +13,23 @@ import ( ) func main() { - devMode := flag.Bool("dev-mode", false, "Allow to run the service in local mode.") + var devMode bool + devMode = *flag.Bool("dev-mode", false, "Allow to run the service in local mode.") + if !devMode { + devModeEnvVarStr := os.Getenv("DEV_MODE") + if devModeEnvVarStr == "true" { + devMode = true + } + } flag.Parse() - if *devMode { + if devMode { logrus.Warn("Running in dev mode. CORS fully open.") logrus.SetLevel(logrus.DebugLevel) } - startServer(*devMode) + startServer(devMode) } func startServer(isDevMode bool) { @@ -62,7 +69,8 @@ func startServer(isDevMode bool) { // Create a new Segment analytics client instance. // analyticsClient is not initialized in dev mode so events are not reported to Segment - analyticsWrapper := api.NewAnalyticsWrapper(isDevMode) + analyticsWriteKeyEnvVarStr := os.Getenv("ANALYTICS_WRITE_KEY") + analyticsWrapper := api.NewAnalyticsWrapper(isDevMode, analyticsWriteKeyEnvVarStr) defer analyticsWrapper.Close() // create a type that satisfies the `api.ServerInterface`, which contains an implementation of every operation from the generated code