Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow SendKey to be set via command line and env var #1323

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,33 @@ 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 TestSendKeyEnvvart(t *testing.T) {
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
cm := makeYAML("General.ConfigurationVersion", 2, "AccessKeys.SendKey", "my-send-key")
rm := makeYAML("ConfigVersion", 2)
cfg, rules := createTempConfigs(t, cm, rm)

oldenv := os.Getenv("REFINERY_SEND_KEY")
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
os.Setenv("REFINERY_SEND_KEY", "another-send-key")
defer os.Setenv("REFINERY_SEND_KEY", oldenv)

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
Loading