From df61b1de000b460c4d156476c99af526df3b28d3 Mon Sep 17 00:00:00 2001 From: Faisal Memon Date: Fri, 23 Aug 2024 22:20:27 -0700 Subject: [PATCH] Make some function part of struct Signed-off-by: Faisal Memon --- cmd/spiffe-helper/config/config.go | 4 ++-- cmd/spiffe-helper/config/config_test.go | 6 +++--- cmd/spiffe-helper/main.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/spiffe-helper/config/config.go b/cmd/spiffe-helper/config/config.go index a8f1c8e..fbc3c3b 100644 --- a/cmd/spiffe-helper/config/config.go +++ b/cmd/spiffe-helper/config/config.go @@ -65,7 +65,7 @@ func ParseConfig(file string) (*Config, error) { } // ParseConfigFlagOverrides handles command line arguments that override config file settings -func ParseConfigFlagOverrides(c *Config, daemonModeFlag bool, daemonModeFlagName string) { +func (c *Config) ParseConfigFlagOverrides(daemonModeFlag bool, daemonModeFlagName string) { if isFlagPassed(daemonModeFlagName) { // If daemon mode is set by CLI this takes precedence c.DaemonMode = &daemonModeFlag @@ -76,7 +76,7 @@ func ParseConfigFlagOverrides(c *Config, daemonModeFlag bool, daemonModeFlagName } } -func ValidateConfig(c *Config, log logrus.FieldLogger) error { +func (c *Config) ValidateConfig(log logrus.FieldLogger) error { if err := validateOSConfig(c); err != nil { return err } diff --git a/cmd/spiffe-helper/config/config_test.go b/cmd/spiffe-helper/config/config_test.go index e11479c..73950a8 100644 --- a/cmd/spiffe-helper/config/config_test.go +++ b/cmd/spiffe-helper/config/config_test.go @@ -299,7 +299,7 @@ func TestValidateConfig(t *testing.T) { } { t.Run(tt.name, func(t *testing.T) { log, hook := test.NewNullLogger() - err := ValidateConfig(tt.config, log) + err := tt.config.ValidateConfig(log) require.ElementsMatch(t, tt.expectLogs, getShortEntries(hook.AllEntries())) @@ -350,7 +350,7 @@ func TestDefaultAgentAddress(t *testing.T) { SVIDBundleFileName: "bundle.pem", } log, _ := test.NewNullLogger() - err := ValidateConfig(config, log) + err := config.ValidateConfig(log) require.NoError(t, err) assert.Equal(t, config.AgentAddress, tt.expectedAgentAddress) }) @@ -406,7 +406,7 @@ func TestDaemonModeFlag(t *testing.T) { err := flag.Set(daemonModeFlagName, "false") require.NoError(t, err) - ParseConfigFlagOverrides(config, *daemonModeFlag, daemonModeFlagName) + config.ParseConfigFlagOverrides(*daemonModeFlag, daemonModeFlagName) require.NotNil(t, config.DaemonMode) assert.Equal(t, false, *config.DaemonMode) } diff --git a/cmd/spiffe-helper/main.go b/cmd/spiffe-helper/main.go index 483f00b..6ca529c 100644 --- a/cmd/spiffe-helper/main.go +++ b/cmd/spiffe-helper/main.go @@ -40,9 +40,9 @@ func startSidecar(configFile string, daemonModeFlag bool, log logrus.FieldLogger if err != nil { return fmt.Errorf("failed to parse %q: %w", configFile, err) } - config.ParseConfigFlagOverrides(hclConfig, daemonModeFlag, daemonModeFlagName) + hclConfig.ParseConfigFlagOverrides(daemonModeFlag, daemonModeFlagName) - if err := config.ValidateConfig(hclConfig, log); err != nil { + if err := hclConfig.ValidateConfig(log); err != nil { return fmt.Errorf("invalid configuration: %w", err) }