Skip to content

Commit

Permalink
feat(config): add env vars for red and ops apikeys
Browse files Browse the repository at this point in the history
  • Loading branch information
s0up4200 committed Oct 21, 2024
1 parent 3f7f8b0 commit f3c491b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ services:
#- REDACTEDHOOK__HOST=127.0.0.1 # Override the host from config.toml
#- REDACTEDHOOK__PORT=42135 # Override the port from config.toml
#- REDACTEDHOOK__API_TOKEN= # Override the api_token from config.toml
#- REDACTEDHOOK__RED_APIKEY= # Override the red api_key from config.toml
#- REDACTEDHOOK__OPS_APIKEY= # Override the ops api_key from config.toml
- TZ=UTC
ports:
- "42135:42135"
Expand Down
4 changes: 4 additions & 0 deletions cmd/redactedhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ func main() {
host := getEnv("REDACTEDHOOK__HOST", config.GetConfig().Server.Host)
port := getEnv("REDACTEDHOOK__PORT", fmt.Sprintf("%d", config.GetConfig().Server.Port))
apiToken := getEnv("REDACTEDHOOK__API_TOKEN", config.GetConfig().Authorization.APIToken)
redApiKey := getEnv("REDACTEDHOOK__RED_APIKEY", config.GetConfig().IndexerKeys.REDKey)
opsApiKey := getEnv("REDACTEDHOOK__OPS_APIKEY", config.GetConfig().IndexerKeys.OPSKey)

config.GetConfig().Authorization.APIToken = apiToken
config.GetConfig().IndexerKeys.REDKey = redApiKey
config.GetConfig().IndexerKeys.OPSKey = opsApiKey

address := fmt.Sprintf("%s:%s", host, port)

Expand Down
13 changes: 11 additions & 2 deletions internal/config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,20 @@ func ValidateConfig() error {
if apiToken == "" {
validationErrors = append(validationErrors, "Authorization API Token is required.")
}
if viper.IsSet("indexer_keys.red_apikey") && viper.GetString("indexer_keys.red_apikey") == "" {

redApiKey := viper.GetString("indexer_keys.red_apikey")
if envRedKey, exists := os.LookupEnv("REDACTEDHOOK__RED_APIKEY"); exists {
redApiKey = envRedKey
}
if redApiKey == "" {
validationErrors = append(validationErrors, "Indexer REDKey should not be empty")
}

if viper.IsSet("indexer_keys.ops_apikey") && viper.GetString("indexer_keys.ops_apikey") == "" {
opsApiKey := viper.GetString("indexer_keys.ops_apikey")
if envOpsKey, exists := os.LookupEnv("REDACTEDHOOK__OPS_APIKEY"); exists {
opsApiKey = envOpsKey
}
if opsApiKey == "" {
validationErrors = append(validationErrors, "Indexer OPSKey should not be empty")
}

Expand Down

0 comments on commit f3c491b

Please sign in to comment.