Skip to content

Commit

Permalink
clean comments
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Nov 5, 2024
1 parent ee77301 commit 0af3de1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
3 changes: 0 additions & 3 deletions pkg/dto/aerospike_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,12 @@ func (c *Credentials) fromModel(m *model.Credentials) {

// Validate validates the credentials configuration
func (c *Credentials) Validate() error {
// Allow anonymous access (nil or empty credentials)
if c == nil {
return nil
}

// Check if any auth method is specified
hasAuth := c.Password != nil || c.PasswordPath != nil || c.SecretAgent != nil || c.KeySecret != nil

// If using auth, username is required
if hasAuth && c.User == nil {
return errors.New("username is required when using authentication")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dto/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *Config) validate() error {
return emptyFieldValidationError("policy name")
}
if err := policy.Validate(); err != nil {
return err
return fmt.Errorf("policy '%s' validation error: %s", name, err.Error())
}
}

Expand All @@ -124,7 +124,7 @@ func (c *Config) validate() error {
return emptyFieldValidationError("secret agent name")
}
if err := agent.validate(); err != nil {
return err
return fmt.Errorf("secret agent '%s' validation error: %s", name, err.Error())
}
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/model/aerospike_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,18 @@ func (c *AerospikeCluster) loadSecretAgentPassword() *string {
return nil
}

password, err := getPasswordFromSecretAgent(c.Credentials.SecretAgent, c.Credentials.KeySecret)
agent := *c.Credentials.SecretAgent
password, err := backup.ParseSecret(agent.ToSecretAgentConfig(), *c.Credentials.KeySecret)
if err != nil {
slog.Error("Failed to get password from secret agent",
"agent", *c.Credentials.SecretAgent,
"agent", agent,
"err", err)
return nil
}

return &password
}

func getPasswordFromSecretAgent(agent *SecretAgent, secret *string) (string, error) {
return backup.ParseSecret(agent.ToSecretAgentConfig(), *secret)
}

// GetAuthMode safely returns the authentication mode.
func (c *AerospikeCluster) GetAuthMode() *string {
if c.Credentials != nil {
Expand Down

0 comments on commit 0af3de1

Please sign in to comment.