Skip to content

Commit

Permalink
feat: Use licenseKey if present in configuration (#1631)
Browse files Browse the repository at this point in the history
Co-authored-by: Noah <[email protected]>
  • Loading branch information
pschrimpf and noahmmcgivern authored Jul 29, 2024
1 parent a305573 commit 08ec6d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/bits-and-blooms/bloom/v3 v3.3.1 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/client9/misspell v0.3.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
18 changes: 11 additions & 7 deletions internal/install/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func validateProfile(maxTimeoutSeconds int, sg *segment.Segment) *types.DetailEr
accountID := configAPI.GetActiveProfileAccountID()
APIKey := configAPI.GetActiveProfileString(config.APIKey)
region := configAPI.GetActiveProfileString(config.Region)
licenseKey := configAPI.GetActiveProfileString(config.LicenseKey)
errorOccured := false
var detailErr *types.DetailError

Expand Down Expand Up @@ -159,13 +160,16 @@ func validateProfile(maxTimeoutSeconds int, sg *segment.Segment) *types.DetailEr
return detailErr
}

licenseKey, err := client.FetchLicenseKey(accountID, config.FlagProfileName, &maxTimeoutSeconds)
if err != nil {
errorOccured = true
message := fmt.Sprintf("could not fetch license key for account %d:, license key: %v %s", accountID, utils.Obfuscate(licenseKey), err)
log.Debug(message)
detailErr = types.NewDetailError(types.EventTypes.UnableToFetchLicenseKey, fmt.Sprintf("%s", err))
return detailErr
if licenseKey == "" {
_licenseKey, err := client.FetchLicenseKey(accountID, config.FlagProfileName, &maxTimeoutSeconds)
if err != nil {
errorOccured = true
message := fmt.Sprintf("could not fetch license key for account %d:, license key: %v %s", accountID, utils.Obfuscate(licenseKey), err)
log.Debug(message)
detailErr = types.NewDetailError(types.EventTypes.UnableToFetchLicenseKey, fmt.Sprintf("%s", err))
return detailErr
}
licenseKey = _licenseKey
}

os.Setenv("NEW_RELIC_LICENSE_KEY", licenseKey)
Expand Down

0 comments on commit 08ec6d4

Please sign in to comment.