Skip to content

Commit

Permalink
Change environment variable validation logic to applicable for prod o…
Browse files Browse the repository at this point in the history
…nly for now.
  • Loading branch information
james03160927 committed Dec 31, 2024
1 parent b18dea2 commit f824133
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ func validateEnvVars(env string) {
"JWT_SECRET",
}

// TODO: Add staging specific variables

// Additional variables mandatory for production and staging
prodStagingVars := []string{
prodVars := []string{
"CLOUD_STORAGE_BUCKET_NAME",
"SLACK_REGISTRY_CHANNEL_WEBHOOK",
"SECRET_SCANNER_URL",
Expand All @@ -38,13 +40,13 @@ func validateEnvVars(env string) {
"ID_TOKEN_AUDIENCE",
}

// Add production and staging-specific variables
if env == "prod" || env == "staging" {
mandatoryVars = append(mandatoryVars, prodStagingVars...)
// Add production specific variables
if env == "prod" {
mandatoryVars = append(mandatoryVars, prodVars...)
}

// Validate that all mandatory environment variables are set
missingVars := []string{}
var missingVars []string
for _, key := range mandatoryVars {
if os.Getenv(key) == "" {
missingVars = append(missingVars, key)
Expand Down Expand Up @@ -75,17 +77,17 @@ func main() {

// Build the application configuration
appConfig := config.Config{
ProjectID: os.Getenv("PROJECT_ID"),
DripEnv: dripEnv,
SlackRegistryChannelWebhook: os.Getenv("SLACK_REGISTRY_CHANNEL_WEBHOOK"),
JWTSecret: os.Getenv("JWT_SECRET"),
SecretScannerURL: os.Getenv("SECRET_SCANNER_URL"),
DiscordSecurityChannelWebhook: os.Getenv("SECURITY_COUNCIL_DISCORD_WEBHOOK"),
ProjectID: os.Getenv("PROJECT_ID"),
DripEnv: dripEnv,
SlackRegistryChannelWebhook: os.Getenv("SLACK_REGISTRY_CHANNEL_WEBHOOK"),
JWTSecret: os.Getenv("JWT_SECRET"),
SecretScannerURL: os.Getenv("SECRET_SCANNER_URL"),
DiscordSecurityChannelWebhook: os.Getenv("SECURITY_COUNCIL_DISCORD_WEBHOOK"),
DiscordSecurityPrivateChannelWebhook: os.Getenv("SECURITY_COUNCIL_DISCORD_PRIVATE_WEBHOOK"),
AlgoliaAppID: os.Getenv("ALGOLIA_APP_ID"),
AlgoliaAPIKey: os.Getenv("ALGOLIA_API_KEY"),
IDTokenAudience: os.Getenv("ID_TOKEN_AUDIENCE"),
CloudStorageBucketName: os.Getenv("CLOUD_STORAGE_BUCKET_NAME"),
AlgoliaAppID: os.Getenv("ALGOLIA_APP_ID"),
AlgoliaAPIKey: os.Getenv("ALGOLIA_API_KEY"),
IDTokenAudience: os.Getenv("ID_TOKEN_AUDIENCE"),
CloudStorageBucketName: os.Getenv("CLOUD_STORAGE_BUCKET_NAME"),
}

// Construct the database connection string
Expand Down

0 comments on commit f824133

Please sign in to comment.