Skip to content

Commit

Permalink
feat: Allow SendKey to be set via command line and env var (#1323)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeGoldsmith authored Sep 13, 2024
1 parent 8d916ed commit f4ca704
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/cmdenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type CmdEnv struct {
OTelTracesAPIKey string `long:"otel-traces-api-key" env:"REFINERY_OTEL_TRACES_API_KEY" description:"API key for OTel traces if being sent to Honeycomb. Setting this value via a flag may expose credentials - it is recommended to use the env var or a configuration file."`
QueryAuthToken string `long:"query-auth-token" env:"REFINERY_QUERY_AUTH_TOKEN" description:"Token for debug/management queries. Setting this value via a flag may expose credentials - it is recommended to use the env var or a configuration file."`
AvailableMemory MemorySize `long:"available-memory" env:"REFINERY_AVAILABLE_MEMORY" description:"The maximum memory available for Refinery to use (ex: 4GiB)."`
SendKey string `long:"send-key" env:"REFINERY_SEND_KEY" description:"The Honeycomb API key that Refinery can use to send data to Honeycomb."`
Debug bool `short:"d" long:"debug" description:"Runs debug service (on the first open port between localhost:6060 and :6069 by default)"`
Version bool `short:"v" long:"version" description:"Print version number and exit"`
InterfaceNames bool `long:"interface-names" description:"Print system's network interface names and exit."`
Expand Down
25 changes: 25 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,31 @@ func TestAvailableMemoryCmdLine(t *testing.T) {
assert.Equal(t, expected, inMemConfig.AvailableMemory)
}

func TestSendKeyCmdLine(t *testing.T) {
cm := makeYAML("General.ConfigurationVersion", 2, "AccessKeys.SendKey", "my-send-key")
rm := makeYAML("ConfigVersion", 2)
cfg, rules := createTempConfigs(t, cm, rm)
c, err := getConfig([]string{"--no-validate", "--config", cfg, "--rules_config", rules, "--send-key", "another-send-key"})
assert.NoError(t, err)

accessKeysConfig := c.GetAccessKeyConfig()
assert.Equal(t, "another-send-key", accessKeysConfig.SendKey)
}

func TestSendKeyEnvVar(t *testing.T) {
cm := makeYAML("General.ConfigurationVersion", 2, "AccessKeys.SendKey", "my-send-key")
rm := makeYAML("ConfigVersion", 2)
cfg, rules := createTempConfigs(t, cm, rm)

t.Setenv("REFINERY_SEND_KEY", "another-send-key")

c, err := getConfig([]string{"--no-validate", "--config", cfg, "--rules_config", rules})
assert.NoError(t, err)

accessKeysConfig := c.GetAccessKeyConfig()
assert.Equal(t, "another-send-key", accessKeysConfig.SendKey)
}

func TestGetSamplerTypes(t *testing.T) {
cm := makeYAML("General.ConfigurationVersion", 2)
rm := makeYAML(
Expand Down
2 changes: 1 addition & 1 deletion config/file_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type NetworkConfig struct {

type AccessKeyConfig struct {
ReceiveKeys []string `yaml:"ReceiveKeys" default:"[]"`
SendKey string `yaml:"SendKey"`
SendKey string `yaml:"SendKey" cmdenv:"SendKey"`
SendKeyMode string `yaml:"SendKeyMode" default:"none"`
AcceptOnlyListedKeys bool `yaml:"AcceptOnlyListedKeys"`
}
Expand Down

0 comments on commit f4ca704

Please sign in to comment.