Skip to content

Commit

Permalink
feat: Add a way to specify the team key for config fetches (experimen…
Browse files Browse the repository at this point in the history
…tal) (#1410)

## Which problem is this PR solving?

To fetch a configuration from Honeycomb, we're going to need a way to
specify a header for the team key. This allows the key to be specified
in an environment variable called `HONEYCOMB_CONFIG_KEY`. This is
deliberately different from the telemetry key because the key will have
to have special permissions.

If the key is not blank, then the header `x-honeycomb-team` will be set
and used for the config requests. The header will not be used if the key
is blank.

We are deliberately not adding this to public documentation because this
feature is still experimental and we may well change it.

## Short description of the changes

- Fetch `HONEYCOMB_CONFIG_KEY` from the environment
- Set `x-honeycomb-team` header if the key is non-blank.
  • Loading branch information
kentquirk authored Nov 5, 2024
1 parent 2327f73 commit 4ffe107
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion config/configLoadHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,25 @@ func getReaderFor(u string) (io.ReadCloser, Format, error) {
}
return r, formatFromFilename(uu.Path), nil
case "http", "https":
resp, err := http.Get(u)
// We need to make an HTTP request but we might need to add the
// x-honeycomb-team header which we get from the environment; we use the
// same header for all requests. This isn't particularly flexible, but
// we think that it's good enough for the experimental stage of this
// feature.
req, err := http.NewRequest("GET", u, nil)
if err != nil {
return nil, FormatUnknown, err
}

// We use a different envvar for the team key because it's not the same
// key used for ingestion. This is not currently documented because it's
// experimental and we might change it later.
key := os.Getenv("HONEYCOMB_CONFIG_KEY")
if key != "" {
req.Header.Set("X-Honeycomb-Team", key)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, FormatUnknown, err
}
Expand Down

0 comments on commit 4ffe107

Please sign in to comment.