Skip to content

Commit

Permalink
use name as a string, not pointer.
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Jan 29, 2025
1 parent 559e86e commit 242f5c4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pkg/dto/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var secretAgentConfig = SecretAgentConfig{
SecretAgentName: util.Ptr("agent1"),
SecretAgentName: "agent1",
}

var originalConfig = &Config{
Expand Down
24 changes: 12 additions & 12 deletions pkg/dto/restore_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ func (r *RestoreRequest) ToModel(config *model.Config) (*model.RestoreRequest, e
type DestinationClusterConfig struct {
// The details of the Aerospike destination cluster.
// Mutually exclusive with 'destination-name'.
Cluster *AerospikeCluster `json:"destination,omitempty"`
Cluster *AerospikeCluster `json:"destination"`
// Link to one of preconfigured clusters.
// Mutually exclusive with 'destination'.
Name *string `json:"destination-name,omitempty"`
Name string `json:"destination-name"`
}

func (c *DestinationClusterConfig) Validate() error {
if c.Cluster == nil && c.Name == nil {
if c.Cluster == nil && c.Name == "" {
return errValidationRequiredEither("destination", "destination-name")
}
if c.Cluster != nil && c.Name != nil {
if c.Cluster != nil && c.Name != "" {
return errValidationMutuallyExclusive("destination", "destination-name")
}
if c.Cluster != nil {
Expand All @@ -151,9 +151,9 @@ func (c *DestinationClusterConfig) ToModel(config *model.Config) (*model.Aerospi
return c.Cluster.ToModel(config)
}

configCluster, exists := config.BackupConfigCopy().AerospikeClusters[*c.Name]
configCluster, exists := config.BackupConfigCopy().AerospikeClusters[c.Name]
if !exists {
return nil, errValidationNotFound("cluster", *c.Name)
return nil, errValidationNotFound("cluster", c.Name)
}

return configCluster, nil
Expand All @@ -163,17 +163,17 @@ func (c *DestinationClusterConfig) ToModel(config *model.Config) (*model.Aerospi
type StorageConfig struct {
// The details of the storage configuration.
// Mutually exclusive with 'source-name'.
Storage *Storage `json:"source,omitempty"`
Storage *Storage `json:"source"`
// Link to one of preconfigured storages.
// Mutually exclusive with 'source'.
Name *string `json:"source-name,omitempty"`
Name string `json:"source-name"`
}

func (c *StorageConfig) Validate() error {
if c.Storage == nil && c.Name == nil {
if c.Storage == nil && c.Name == "" {
return errValidationRequiredEither("source", "source-name")
}
if c.Storage != nil && c.Name != nil {
if c.Storage != nil && c.Name != "" {
return errValidationMutuallyExclusive("source", "source-name")
}
if c.Storage != nil {
Expand All @@ -190,9 +190,9 @@ func (c *StorageConfig) ToModel(config *model.Config) (model.Storage, error) {
return c.Storage.ToModel(config)
}

configStorage, exists := config.BackupConfigCopy().Storage[*c.Name]
configStorage, exists := config.BackupConfigCopy().Storage[c.Name]
if !exists {
return nil, errValidationNotFound("storage", *c.Name)
return nil, errValidationNotFound("storage", c.Name)
}
return configStorage, nil
}
34 changes: 17 additions & 17 deletions pkg/dto/restore_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func TestDestinationClusterConfig_Validate(t *testing.T) {
name: "both fields set",
config: DestinationClusterConfig{
Cluster: &AerospikeCluster{},
Name: util.Ptr("test-cluster"),
Name: "test-cluster",
},
err: errMutuallyExclusive,
},
{
name: "only name set",
config: DestinationClusterConfig{
Name: util.Ptr("test-cluster"),
Name: "test-cluster",
},
},
{
Expand Down Expand Up @@ -72,14 +72,14 @@ func TestStorageConfig_Validate(t *testing.T) {
name: "both fields set",
storageConfig: StorageConfig{
Storage: &Storage{},
Name: util.Ptr("test-storage"),
Name: "test-storage",
},
err: errMutuallyExclusive,
},
{
name: "only name set",
storageConfig: StorageConfig{
Name: util.Ptr("test-storage"),
Name: "test-storage",
},
},
{
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestDestinationClusterConfig_ToModel(t *testing.T) {
{
name: "convert from name",
dstCluster: DestinationClusterConfig{
Name: util.Ptr("test-cluster"),
Name: "test-cluster",
},
want: cluster,
},
Expand All @@ -139,7 +139,7 @@ func TestDestinationClusterConfig_ToModel(t *testing.T) {
{
name: "non-existent cluster name",
dstCluster: DestinationClusterConfig{
Name: util.Ptr("non-existent"),
Name: "non-existent",
},
err: errNotFound,
},
Expand Down Expand Up @@ -227,10 +227,10 @@ func TestRestoreRequest_Validate(t *testing.T) {
request: RestoreRequest{
BackupDataPath: "test/path",
DestinationClusterConfig: DestinationClusterConfig{
Name: util.Ptr("test-cluster"),
Name: "test-cluster",
},
StorageConfig: StorageConfig{
Name: util.Ptr("test-storage"),
Name: "test-storage",
},
Policy: validPolicy,
},
Expand Down Expand Up @@ -341,10 +341,10 @@ func TestRestoreRequest_ToModel(t *testing.T) {
name: "convert from names",
request: RestoreRequest{
DestinationClusterConfig: DestinationClusterConfig{
Name: &clusterName,
Name: clusterName,
},
StorageConfig: StorageConfig{
Name: &storageName,
Name: storageName,
},
BackupDataPath: "test/path",
Policy: &RestorePolicy{},
Expand Down Expand Up @@ -382,10 +382,10 @@ func TestRestoreRequest_ToModel(t *testing.T) {
name: "non-existent cluster",
request: RestoreRequest{
DestinationClusterConfig: DestinationClusterConfig{
Name: util.Ptr("non-existent"),
Name: "non-existent",
},
StorageConfig: StorageConfig{
Name: &storageName,
Name: storageName,
},
BackupDataPath: "test/path",
},
Expand All @@ -395,10 +395,10 @@ func TestRestoreRequest_ToModel(t *testing.T) {
name: "non-existent storage",
request: RestoreRequest{
DestinationClusterConfig: DestinationClusterConfig{
Name: &clusterName,
Name: clusterName,
},
StorageConfig: StorageConfig{
Name: util.Ptr("non-existent"),
Name: "non-existent",
},
BackupDataPath: "test/path",
},
Expand Down Expand Up @@ -440,7 +440,7 @@ func TestRestoreTimestampRequest_ToModel(t *testing.T) {
name: "valid conversion",
request: RestoreTimestampRequest{
DestinationClusterConfig: DestinationClusterConfig{
Name: util.Ptr("test-cluster"),
Name: "test-cluster",
},
Time: 1739538000000,
Routine: "daily",
Expand All @@ -457,7 +457,7 @@ func TestRestoreTimestampRequest_ToModel(t *testing.T) {
name: "non-existent cluster",
request: RestoreTimestampRequest{
DestinationClusterConfig: DestinationClusterConfig{
Name: util.Ptr("non-existent"),
Name: "non-existent",
},
Time: 1739538000000,
Routine: "daily",
Expand All @@ -468,7 +468,7 @@ func TestRestoreTimestampRequest_ToModel(t *testing.T) {
name: "non-existent routine",
request: RestoreTimestampRequest{
DestinationClusterConfig: DestinationClusterConfig{
Name: util.Ptr("test-cluster"),
Name: "test-cluster",
},
Time: 1739538000000,
Routine: "non-existent",
Expand Down
12 changes: 6 additions & 6 deletions pkg/dto/secret_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type SecretAgentConfig struct {
SecretAgent *SecretAgent `yaml:"secret-agent,omitempty" json:"secret-agent,omitempty"`
// Secret Agent configuration (optional). Link to one of preconfigured agents.
// Mutually exclusive with 'secret-agent'.
SecretAgentName *string `yaml:"secret-agent-name,omitempty" json:"secret-agent-name,omitempty"`
SecretAgentName string `yaml:"secret-agent-name,omitempty" json:"secret-agent-name,omitempty"`
}

func (c SecretAgentConfig) validate() error {
if c.SecretAgent != nil && c.SecretAgentName != nil {
if c.SecretAgent != nil && c.SecretAgentName != "" {
return errValidationMutuallyExclusive("secret-agent-name", "secret-agent")
}
if err := c.SecretAgent.validate(); err != nil {
Expand All @@ -38,10 +38,10 @@ func (c *SecretAgentConfig) ToModel(config *model.Config) (*model.SecretAgent, e
return c.SecretAgent.ToModel(), nil
}

if c.SecretAgentName != nil {
agent, exists := config.BackupConfigCopy().SecretAgents[*c.SecretAgentName]
if c.SecretAgentName != "" {
agent, exists := config.BackupConfigCopy().SecretAgents[c.SecretAgentName]
if !exists {
return nil, fmt.Errorf("unknown secret agent %q", *c.SecretAgentName)
return nil, fmt.Errorf("unknown secret agent %q", c.SecretAgentName)
}
return agent, nil
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func ResolveSecretAgentFromModel(s *model.SecretAgent, config *model.BackupConfi
secretAgentName := findKeyByValue(config.SecretAgents, s)
if secretAgentName != "" {
return SecretAgentConfig{
SecretAgentName: &secretAgentName,
SecretAgentName: secretAgentName,
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/dto/secret_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestValidSecretAgentName(t *testing.T) {
agentName := "predefined-agent"

config := SecretAgentConfig{
SecretAgentName: &agentName,
SecretAgentName: agentName,
}

err := config.validate()
Expand All @@ -37,7 +37,7 @@ func TestMutuallyExclusive(t *testing.T) {
agentName := "predefined-agent"
config := SecretAgentConfig{
SecretAgent: &SecretAgent{},
SecretAgentName: &agentName,
SecretAgentName: agentName,
}

err := config.validate()
Expand Down

0 comments on commit 242f5c4

Please sign in to comment.