Skip to content

Commit

Permalink
obfuscate license key
Browse files Browse the repository at this point in the history
  • Loading branch information
iamemilio committed Nov 27, 2023
1 parent d752b7e commit df3f664
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion v3/newrelic/internal_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (app *app) doHarvest(h *harvest, harvestStart time.Time, run *appRun) {
if resp.Err != nil {
app.Warn("harvest failure", map[string]interface{}{
"cmd": cmd,
"error": resp.Err.Error(),
"error": obfuscateLicenseKeyCollectorRequest(resp.Err.Error()),
"retain_data": resp.ShouldSaveHarvestData(),
})
}
Expand All @@ -132,6 +132,17 @@ func (app *app) doHarvest(h *harvest, harvestStart time.Time, run *appRun) {
}
}

func obfuscateLicenseKeyCollectorRequest(responseErrorString string) string {
licenseKeyIndex := strings.Index(responseErrorString, "license_key=")
marshalFormatIndex := strings.Index(responseErrorString, "&marshal_format=")

if licenseKeyIndex == -1 || marshalFormatIndex == -1 {
return responseErrorString
}

return responseErrorString[0:licenseKeyIndex] + "license_key=**REDACTED**" + responseErrorString[marshalFormatIndex:]
}

func (app *app) connectRoutine() {
attempts := 0
for {
Expand Down

0 comments on commit df3f664

Please sign in to comment.