Skip to content

Commit

Permalink
Make some function part of struct
Browse files Browse the repository at this point in the history
Signed-off-by: Faisal Memon <[email protected]>
  • Loading branch information
faisal-memon committed Aug 24, 2024
1 parent f3a736f commit df61b1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/spiffe-helper/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/spiffe-helper/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/spiffe-helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit df61b1d

Please sign in to comment.