Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
NEW_RELIC_LICENSE_KEY Priority and bypass Secrets Manager check if NEW_RELIC_LICENSE_KEY is set
  • Loading branch information
ashishsinghnr committed Jun 19, 2024
1 parent a8461c8 commit ab6722e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions checks/sanity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ func sanityCheck(ctx context.Context, conf *config.Configuration, res *api.Regis

envKeyExists := util.EnvVarExists("NEW_RELIC_LICENSE_KEY")
var timeout = 1 * time.Second

//Secret Manager
ctxSecret, cancelSecret := context.WithTimeout(ctx, timeout)
defer cancelSecret()
isSecretConfigured := credentials.IsSecretConfigured(ctxSecret, conf)

isSecretConfigured := false
if conf.LicenseKeySecretId != "" {
isSecretConfigured = credentials.IsSecretConfigured(ctxSecret, conf)
}

// SSM Parameter
ctxSSMParameter, cancelSSMParameter := context.WithTimeout(ctx, timeout)
defer cancelSSMParameter()

isSSMParameterConfigured := false
if conf.LicenseKeySSMParameterName != "" {
isSSMParameterConfigured = credentials.IsSSMParameterConfigured(ctxSSMParameter, conf)
}


if isSecretConfigured && envKeyExists {
return fmt.Errorf("There is both a AWS Secrets Manager secret and a NEW_RELIC_LICENSE_KEY environment variable set. Recommend removing the NEW_RELIC_LICENSE_KEY environment variable and using the AWS Secrets Manager secret.")
Expand All @@ -55,5 +61,9 @@ func sanityCheck(ctx context.Context, conf *config.Configuration, res *api.Regis
return fmt.Errorf("There is both a AWS Secrets Manager secret and a AWS Parameter Store parameter set. Recommend using just one.")
}

if !envKeyExists || !isSecretConfigured || !isSSMParameterConfigured {
return fmt.Errorf("No configured license key found, attempting fallback to default AWS Secrets Manager secret with NEW_RELIC_LICENSE_KEY")
}

return nil
}
2 changes: 1 addition & 1 deletion credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func GetNewRelicLicenseKey(ctx context.Context, conf *config.Configuration) (str
return envLicenseKey, nil
}

util.Debugln("No configured license key found, attempting fallbacks")
util.Debugln("No configured license key found, attempting fallbacks to default")

licenseKey, err := tryLicenseKeyFromSecret(ctx, defaultSecretId)
if err == nil {
Expand Down

0 comments on commit ab6722e

Please sign in to comment.