Skip to content

Commit

Permalink
Also load config using WithEnvLiteralLoader (#4000)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Cohen <[email protected]>
  • Loading branch information
predictiple and scudette authored Jan 14, 2025
1 parent 786e656 commit c741cf9
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bin/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func doBanner() {
}

switch pair[0] {
case // Ignore this one as it is the actual configuration "VELOCIRAPTOR_CONFIG",
case // Ignore this one as it is the actual configuration
"VELOCIRAPTOR_LITERAL_CONFIG",
"VELOCIRAPTOR_SLOW_FILESYSTEM",
"VELOCIRAPTOR_DISABLE_CSRF", "VELOCIRAPTOR_INJECT_API_SLEEP",
"GOGC", "GOTRACEBACK", "GOMAXPROCS", "GODEBUG", "GOMEMLIMIT",
Expand Down
10 changes: 10 additions & 0 deletions bin/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ func TestGenerateConfigWithMerge(t *testing.T) {
require.NoError(t, err)
require.Contains(t, string(out), "Foo")

// Specify the literal config in the environment
cmd = exec.Command(binary, "config", "show")
cmd.Env = append(os.Environ(),
"VELOCIRAPTOR_LITERAL_CONFIG="+string(config_file_content),
"VELOCIRAPTOR_CONFIG=",
)
out, err = cmd.Output()
require.NoError(t, err)
require.Contains(t, string(out), "Foo")

// Specifying invalid config in the flag is a hard stop - even
// if there is a valid environ.
cmd = exec.Command(binary, "config", "show", "--config", "XXXX")
Expand Down
1 change: 1 addition & 0 deletions bin/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func generateGUIConfig(datastore_directory, server_config_path, client_config_pa
func doGUI() error {
// Start from a clean slate
os.Setenv("VELOCIRAPTOR_CONFIG", "")
os.Setenv("VELOCIRAPTOR_LITERAL_CONFIG", "")

datastore_directory := *gui_command_datastore
if datastore_directory == "" {
Expand Down
2 changes: 2 additions & 0 deletions bin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func main() {
WithFileLoader(*config_path).
WithEmbedded(*embedded_config_path).
WithEnvLoader("VELOCIRAPTOR_CONFIG").
WithEnvLiteralLoader("VELOCIRAPTOR_LITERAL_CONFIG").
WithConfigMutator("Mutator mergeFlagConfig",
func(config_obj *config_proto.Config) error {
return mergeFlagConfig(config_obj, default_config)
Expand Down Expand Up @@ -246,6 +247,7 @@ func makeDefaultConfigLoader() *config.Loader {
WithFileLoader(*config_path).
WithEmbedded(*embedded_config_path).
WithEnvLoader("VELOCIRAPTOR_CONFIG").
WithEnvLiteralLoader("VELOCIRAPTOR_LITERAL_CONFIG").
WithConfigMutator("Mutator mergeFlagConfig",
func(config_obj *config_proto.Config) error {
return mergeFlagConfig(config_obj, default_config)
Expand Down
1 change: 1 addition & 0 deletions bin/offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func doCollector() error {

// Start from a clean slate
os.Setenv("VELOCIRAPTOR_CONFIG", "")
os.Setenv("VELOCIRAPTOR_LITERAL_CONFIG", "")

datastore_directory := *collector_command_datastore
if datastore_directory == "" {
Expand Down
1 change: 1 addition & 0 deletions bin/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func writeLogOnPanic() error {
config_obj, err := new(config.Loader).
WithFileLoader(*config_path).
WithEmbedded(*embedded_config_path).
WithEnvLiteralLoader("VELOCIRAPTOR_LITERAL_CONFIG").
WithEnvLoader("VELOCIRAPTOR_CONFIG").
LoadAndValidate()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions datastore/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ type RemoteTestSuite struct {

func (self *RemoteTestSuite) SetupTest() {
var err error
os.Setenv("VELOCIRAPTOR_CONFIG", test_utils.SERVER_CONFIG)
os.Setenv("VELOCIRAPTOR_LITERAL_CONFIG", test_utils.SERVER_CONFIG)
self.ConfigObj, err = new(config.Loader).
WithEnvLiteralLoader("VELOCIRAPTOR_CONFIG").WithRequiredFrontend().
WithEnvLiteralLoader("VELOCIRAPTOR_LITERAL_CONFIG").WithRequiredFrontend().
WithVerbose(true).LoadAndValidate()
require.NoError(self.T(), err)

Expand Down
4 changes: 2 additions & 2 deletions file_store/test_utils/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func (self *TestSuite) CreateFlow(client_id, flow_id string) {
}

func (self *TestSuite) LoadConfig() *config_proto.Config {
os.Setenv("VELOCIRAPTOR_CONFIG", SERVER_CONFIG)
os.Setenv("VELOCIRAPTOR_LITERAL_CONFIG", SERVER_CONFIG)
config_obj, err := new(config.Loader).
WithEnvLiteralLoader("VELOCIRAPTOR_CONFIG").WithRequiredFrontend().
WithEnvLiteralLoader("VELOCIRAPTOR_LITERAL_CONFIG").WithRequiredFrontend().
WithWriteback().WithVerbose(true).
LoadAndValidate()
require.NoError(self.T(), err)
Expand Down
4 changes: 2 additions & 2 deletions services/journal/journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func (self *JournalTestSuite) SetupTest() {

file_store.ClearGlobalFilestore()

os.Setenv("VELOCIRAPTOR_CONFIG", test_utils.SERVER_CONFIG)
os.Setenv("VELOCIRAPTOR_LITERAL_CONFIG", test_utils.SERVER_CONFIG)
self.ConfigObj, err = new(config.Loader).
WithEnvLiteralLoader("VELOCIRAPTOR_CONFIG").WithRequiredFrontend().
WithEnvLiteralLoader("VELOCIRAPTOR_LITERAL_CONFIG").WithRequiredFrontend().
WithVerbose(true).LoadAndValidate()
require.NoError(self.T(), err)

Expand Down

0 comments on commit c741cf9

Please sign in to comment.