From ebbb018935bd5910e29f37f2caacefce0dc01511 Mon Sep 17 00:00:00 2001 From: Anton Korotkov <106995168+korotkov-aerospike@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:19:25 +0200 Subject: [PATCH] APPS-1378 Make `dto` pkg compatible for external use (#279) * extract aerospike namespace validator * extract aerospike to top level * move read cluster * move aerospiek back into service * check nil config * check nil request --- cmd/backup/main.go | 5 +- .../configuration/configuration_manager.go | 8 +-- .../configuration_manager_http.go | 6 +-- .../configuration_manager_local.go | 6 +-- .../server/configuration/storage_manager.go | 6 +-- internal/server/handlers/service.go | 5 +- pkg/dto/backup_routine.go | 4 +- pkg/dto/config.go | 4 +- pkg/service/{ => aerospike}/client_manager.go | 12 ++--- .../{ => aerospike}/client_manager_test.go | 4 +- .../namespace_validator.go} | 49 ++--------------- .../namespace_validator_test.go} | 2 +- pkg/service/backup_routine_handler.go | 7 +-- pkg/service/cluster_config_writer.go | 2 +- pkg/service/cluster_configuration.go | 52 +++++++++++++++++++ pkg/service/config_applier.go | 9 ++-- pkg/service/restore_data.go | 9 ++-- pkg/validation/config_validation.go | 26 ++++++++-- 18 files changed, 124 insertions(+), 92 deletions(-) rename pkg/service/{ => aerospike}/client_manager.go (93%) rename pkg/service/{ => aerospike}/client_manager_test.go (97%) rename pkg/service/{aerospike_service.go => aerospike/namespace_validator.go} (72%) rename pkg/service/{aerospike_service_test.go => aerospike/namespace_validator_test.go} (96%) create mode 100644 pkg/service/cluster_configuration.go diff --git a/cmd/backup/main.go b/cmd/backup/main.go index 4f92805a..815e63fa 100644 --- a/cmd/backup/main.go +++ b/cmd/backup/main.go @@ -17,6 +17,7 @@ import ( "github.com/aerospike/aerospike-backup-service/v2/internal/util" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "github.com/reugn/go-quartz/logger" "github.com/spf13/cobra" ) @@ -64,8 +65,8 @@ func run() int { func startService(configFile string, remote bool) error { ctx := systemCtx() - clientManager := service.NewClientManager(&service.DefaultClientFactory{}, 10*time.Second) - nsValidator := service.NewNamespaceValidator(clientManager) + clientManager := aerospike.NewClientManager(&aerospike.DefaultClientFactory{}, 10*time.Second) + nsValidator := aerospike.NewNamespaceValidator(clientManager) config, configurationManager, err := configuration.Load(ctx, configFile, remote, nsValidator) if err != nil { diff --git a/internal/server/configuration/configuration_manager.go b/internal/server/configuration/configuration_manager.go index 1302b21f..30310ffd 100644 --- a/internal/server/configuration/configuration_manager.go +++ b/internal/server/configuration/configuration_manager.go @@ -11,7 +11,7 @@ import ( "github.com/aerospike/aerospike-backup-service/v2/pkg/dto" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" - "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "gopkg.in/yaml.v3" ) @@ -26,7 +26,7 @@ func Load( ctx context.Context, configFile string, remote bool, - nsValidator service.NamespaceValidator, + nsValidator aerospike.NamespaceValidator, ) (*model.Config, Manager, error) { slog.Info("Read service configuration from", slog.String("file", configFile), @@ -45,7 +45,7 @@ func Load( return config, manager, nil } -func readConfig(reader io.Reader, nsValidator service.NamespaceValidator) (*model.Config, error) { +func readConfig(reader io.Reader, nsValidator aerospike.NamespaceValidator) (*model.Config, error) { configBytes, err := io.ReadAll(reader) if err != nil { return nil, fmt.Errorf("failed to read configuration content: %w", err) @@ -75,7 +75,7 @@ func writeConfig(writer io.Writer, config *model.Config) error { return err } -func newConfigManager(configFile string, remote bool, nsValidator service.NamespaceValidator) (Manager, error) { +func newConfigManager(configFile string, remote bool, nsValidator aerospike.NamespaceValidator) (Manager, error) { if remote { storage, err := readStorage(configFile) if err != nil { diff --git a/internal/server/configuration/configuration_manager_http.go b/internal/server/configuration/configuration_manager_http.go index ba0d3662..d0bfb2da 100644 --- a/internal/server/configuration/configuration_manager_http.go +++ b/internal/server/configuration/configuration_manager_http.go @@ -7,20 +7,20 @@ import ( "net/http" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" - "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" ) // httpConfigurationManager implements the Manager interface, // performing I/O operations via the HTTP(S) protocol. type httpConfigurationManager struct { configURL string - nsValidator service.NamespaceValidator + nsValidator aerospike.NamespaceValidator } var _ Manager = (*httpConfigurationManager)(nil) // newHTTPConfigurationManager returns a new httpConfigurationManager. -func newHTTPConfigurationManager(uri string, nsValidator service.NamespaceValidator) Manager { +func newHTTPConfigurationManager(uri string, nsValidator aerospike.NamespaceValidator) Manager { return &httpConfigurationManager{ configURL: uri, nsValidator: nsValidator, diff --git a/internal/server/configuration/configuration_manager_local.go b/internal/server/configuration/configuration_manager_local.go index 879f39e7..56342d95 100644 --- a/internal/server/configuration/configuration_manager_local.go +++ b/internal/server/configuration/configuration_manager_local.go @@ -8,7 +8,7 @@ import ( "sync" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" - "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" ) // fileConfigurationManager implements the Manager interface, @@ -16,13 +16,13 @@ import ( type fileConfigurationManager struct { sync.Mutex FilePath string - nsValidator service.NamespaceValidator + nsValidator aerospike.NamespaceValidator } var _ Manager = (*fileConfigurationManager)(nil) // newFileConfigurationManager returns a new fileConfigurationManager. -func newFileConfigurationManager(path string, nsValidator service.NamespaceValidator) Manager { +func newFileConfigurationManager(path string, nsValidator aerospike.NamespaceValidator) Manager { return &fileConfigurationManager{ FilePath: path, nsValidator: nsValidator, diff --git a/internal/server/configuration/storage_manager.go b/internal/server/configuration/storage_manager.go index becf37fd..b7fd6028 100644 --- a/internal/server/configuration/storage_manager.go +++ b/internal/server/configuration/storage_manager.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" - "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "github.com/aerospike/aerospike-backup-service/v2/pkg/service/storage" ) @@ -14,11 +14,11 @@ import ( // it stores service configuration in provided Storage (Local, s3 aws etc.) type storageManager struct { storage model.Storage - nsValidator service.NamespaceValidator + nsValidator aerospike.NamespaceValidator } // newStorageManager returns new instance of storageManager -func newStorageManager(configStorage model.Storage, nsValidator service.NamespaceValidator) Manager { +func newStorageManager(configStorage model.Storage, nsValidator aerospike.NamespaceValidator) Manager { return &storageManager{ storage: configStorage, nsValidator: nsValidator, diff --git a/internal/server/handlers/service.go b/internal/server/handlers/service.go index cc7c25d3..85b12b2b 100644 --- a/internal/server/handlers/service.go +++ b/internal/server/handlers/service.go @@ -7,6 +7,7 @@ import ( "github.com/aerospike/aerospike-backup-service/v2/internal/server/configuration" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "github.com/reugn/go-quartz/quartz" ) @@ -20,7 +21,7 @@ type Service struct { handlerHolder service.BackupHandlerHolder configurationManager configuration.Manager logger *slog.Logger - nsValidator service.NamespaceValidator + nsValidator aerospike.NamespaceValidator } func NewService( @@ -32,7 +33,7 @@ func NewService( handlerHolder service.BackupHandlerHolder, configurationManager configuration.Manager, logger *slog.Logger, - nsValidator service.NamespaceValidator, + nsValidator aerospike.NamespaceValidator, ) *Service { return &Service{ config: config, diff --git a/pkg/dto/backup_routine.go b/pkg/dto/backup_routine.go index ecb8b6b3..fc259c8d 100644 --- a/pkg/dto/backup_routine.go +++ b/pkg/dto/backup_routine.go @@ -5,7 +5,7 @@ import ( "io" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" - "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "github.com/aws/smithy-go/ptr" "github.com/reugn/go-quartz/quartz" ) @@ -83,7 +83,7 @@ func (r *BackupRoutine) Validate() error { func (r *BackupRoutine) ToModel( config *model.Config, - nsValidator service.NamespaceValidator, + nsValidator aerospike.NamespaceValidator, ) (*model.BackupRoutine, error) { policy, found := config.BackupPolicies[r.BackupPolicy] if !found { diff --git a/pkg/dto/config.go b/pkg/dto/config.go index 03f1a760..dd00afd2 100644 --- a/pkg/dto/config.go +++ b/pkg/dto/config.go @@ -5,7 +5,7 @@ import ( "io" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" - "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" ) // Config represents the service configuration file. @@ -139,7 +139,7 @@ func NewConfigWithDefaultValues() *Config { } } -func (c *Config) ToModel(nsValidator service.NamespaceValidator) (*model.Config, error) { +func (c *Config) ToModel(nsValidator aerospike.NamespaceValidator) (*model.Config, error) { if err := c.validate(); err != nil { return nil, fmt.Errorf("configuration validation failed: %w", err) } diff --git a/pkg/service/client_manager.go b/pkg/service/aerospike/client_manager.go similarity index 93% rename from pkg/service/client_manager.go rename to pkg/service/aerospike/client_manager.go index d1851586..1abe5ae5 100644 --- a/pkg/service/client_manager.go +++ b/pkg/service/aerospike/client_manager.go @@ -1,4 +1,4 @@ -package service +package aerospike import ( "errors" @@ -20,13 +20,13 @@ type ClientManager interface { Close(*backup.Client) } -// AerospikeClientFactory defines an interface for creating and checking clients. -type AerospikeClientFactory interface { +// ClientFactory defines an interface for creating and checking clients. +type ClientFactory interface { NewClientWithPolicyAndHost(policy *as.ClientPolicy, hosts ...*as.Host) (backup.AerospikeClient, error) IsClusterHealthy(client backup.AerospikeClient) bool } -// DefaultClientFactory is the default implementation of AerospikeClientFactory. +// DefaultClientFactory is the default implementation of ClientFactory. type DefaultClientFactory struct{} // NewClientWithPolicyAndHost creates a new Aerospike client with the given policy and hosts. @@ -61,7 +61,7 @@ func (f *DefaultClientFactory) IsClusterHealthy(client backup.AerospikeClient) b type ClientManagerImpl struct { mu sync.RWMutex clients map[*model.AerospikeCluster]*clientInfo - clientFactory AerospikeClientFactory + clientFactory ClientFactory closeDelay time.Duration } @@ -72,7 +72,7 @@ type clientInfo struct { } // NewClientManager creates a new ClientManagerImpl. -func NewClientManager(aerospikeClientFactory AerospikeClientFactory, closeDelay time.Duration) *ClientManagerImpl { +func NewClientManager(aerospikeClientFactory ClientFactory, closeDelay time.Duration) *ClientManagerImpl { return &ClientManagerImpl{ clients: make(map[*model.AerospikeCluster]*clientInfo), clientFactory: aerospikeClientFactory, diff --git a/pkg/service/client_manager_test.go b/pkg/service/aerospike/client_manager_test.go similarity index 97% rename from pkg/service/client_manager_test.go rename to pkg/service/aerospike/client_manager_test.go index 7439e66d..34459f34 100644 --- a/pkg/service/client_manager_test.go +++ b/pkg/service/aerospike/client_manager_test.go @@ -1,4 +1,4 @@ -package service +package aerospike import ( "errors" @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/require" ) -// MockClientFactory is a mock implementation of the AerospikeClientFactory interface. +// MockClientFactory is a mock implementation of the ClientFactory interface. type MockClientFactory struct { ShouldFail bool IsClusterDisconnected bool diff --git a/pkg/service/aerospike_service.go b/pkg/service/aerospike/namespace_validator.go similarity index 72% rename from pkg/service/aerospike_service.go rename to pkg/service/aerospike/namespace_validator.go index 1ffbe993..1c0ab753 100644 --- a/pkg/service/aerospike_service.go +++ b/pkg/service/aerospike/namespace_validator.go @@ -1,4 +1,4 @@ -package service +package aerospike import ( "errors" @@ -6,14 +6,10 @@ import ( "log/slog" "strings" - _ "github.com/aerospike/aerospike-backup-service/v2/modules/schema" // it's required to load configuration schemas in init method "github.com/aerospike/aerospike-backup-service/v2/pkg/model" "github.com/aerospike/aerospike-backup-service/v2/pkg/util" as "github.com/aerospike/aerospike-client-go/v7" - "github.com/aerospike/aerospike-management-lib/asconfig" - "github.com/aerospike/aerospike-management-lib/info" "github.com/aerospike/backup-go" - "github.com/go-logr/logr" ) const namespaceInfo = "namespaces" @@ -103,48 +99,9 @@ func getAllNamespacesOfCluster(client backup.AerospikeClient) ([]string, error) return strings.Split(namespaces, ";"), nil } -func getClusterConfiguration(client backup.AerospikeClient) []asconfig.DotConf { - activeHosts := getActiveHosts(client) - - var outputs = make([]asconfig.DotConf, 0, len(activeHosts)) - policy := client.Cluster().ClientPolicy() - for _, host := range activeHosts { - asInfo := info.NewAsInfo(logr.Logger{}, host, &policy) - - conf, err := asconfig.GenerateConf(logr.Discard(), asInfo, true) - if err != nil { - slog.Error("Error reading configuration", - slog.Any("host", host), slog.Any("err", err)) - continue - } - asconf, _ := asconfig.NewMapAsConfig(logr.Discard(), conf.Conf) - configAsString, err := util.TryAndRecover(asconf.ToConfFile) - if err != nil { - slog.Error("Error serialising configuration", - slog.Any("host", host), slog.Any("err", err)) - continue - } - - outputs = append(outputs, configAsString) - } - - return outputs -} - -func getActiveHosts(client backup.AerospikeClient) []*as.Host { - var activeHosts []*as.Host - for _, node := range client.GetNodes() { - if node.IsActive() { - activeHosts = append(activeHosts, node.GetHost()) - } - } - - return activeHosts -} - -// resolveBackupNamespaces returns the list of namespaces to back up. +// ResolveNamespaces returns the list of namespaces to back up. // If `namespaces` is empty, it fetches all namespaces from the cluster via the provided client. -func resolveNamespaces(namespaces []string, client backup.AerospikeClient) ([]string, error) { +func ResolveNamespaces(namespaces []string, client backup.AerospikeClient) ([]string, error) { if len(namespaces) == 0 { return getAllNamespacesOfCluster(client) } diff --git a/pkg/service/aerospike_service_test.go b/pkg/service/aerospike/namespace_validator_test.go similarity index 96% rename from pkg/service/aerospike_service_test.go rename to pkg/service/aerospike/namespace_validator_test.go index f5e727fa..a00e432d 100644 --- a/pkg/service/aerospike_service_test.go +++ b/pkg/service/aerospike/namespace_validator_test.go @@ -1,6 +1,6 @@ //go:build !ci -package service +package aerospike import ( "testing" diff --git a/pkg/service/backup_routine_handler.go b/pkg/service/backup_routine_handler.go index 6d36967f..d9d1ceb5 100644 --- a/pkg/service/backup_routine_handler.go +++ b/pkg/service/backup_routine_handler.go @@ -8,6 +8,7 @@ import ( "time" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "github.com/aerospike/aerospike-backup-service/v2/pkg/service/storage" "github.com/aerospike/aerospike-backup-service/v2/pkg/util" "github.com/aerospike/backup-go" @@ -27,7 +28,7 @@ type BackupRoutineHandler struct { secretAgent *model.SecretAgent lastRun lastBackupRun retry executor - clientManager ClientManager + clientManager aerospike.ClientManager logger *slog.Logger clusterConfigWriter ClusterConfigWriter @@ -79,7 +80,7 @@ type BackupHandlerHolder map[string]*BackupRoutineHandler // newBackupRoutineHandler returns a new BackupRoutineHandler instance. func newBackupRoutineHandler( config *model.Config, - clientManager ClientManager, + clientManager aerospike.ClientManager, backupService Backup, routineName string, backupBackend backupMetadataManager, @@ -174,7 +175,7 @@ func (h *BackupRoutineHandler) prepareCluster(retry executor) (*backup.Client, [ if err != nil { return fmt.Errorf("cannot get backup client: %w", err) } - namespaces, err = resolveNamespaces(h.namespaces, client.AerospikeClient()) + namespaces, err = aerospike.ResolveNamespaces(h.namespaces, client.AerospikeClient()) if err != nil { return fmt.Errorf("cannot retrieve namespaces from source cluster: %w", err) } diff --git a/pkg/service/cluster_config_writer.go b/pkg/service/cluster_config_writer.go index bb21fb6d..3bad9ff9 100644 --- a/pkg/service/cluster_config_writer.go +++ b/pkg/service/cluster_config_writer.go @@ -38,7 +38,7 @@ func (w *DefaultClusterConfigWriter) Write( client backup.AerospikeClient, timestamp time.Time, ) { - infos := getClusterConfiguration(client) + infos := scanClusterConfiguration(client, w.logger) if len(infos) == 0 { w.logger.Warn("Could not read aerospike configuration") return diff --git a/pkg/service/cluster_configuration.go b/pkg/service/cluster_configuration.go new file mode 100644 index 00000000..5dfd8505 --- /dev/null +++ b/pkg/service/cluster_configuration.go @@ -0,0 +1,52 @@ +package service + +import ( + "log/slog" + + _ "github.com/aerospike/aerospike-backup-service/v2/modules/schema" // it's required to load configuration schemas in init method + "github.com/aerospike/aerospike-backup-service/v2/pkg/util" + as "github.com/aerospike/aerospike-client-go/v7" + "github.com/aerospike/aerospike-management-lib/asconfig" + "github.com/aerospike/aerospike-management-lib/info" + "github.com/aerospike/backup-go" + "github.com/go-logr/logr" +) + +func scanClusterConfiguration(client backup.AerospikeClient, logger *slog.Logger) []asconfig.DotConf { + activeHosts := getActiveHosts(client) + + var outputs = make([]asconfig.DotConf, 0, len(activeHosts)) + policy := client.Cluster().ClientPolicy() + for _, host := range activeHosts { + asInfo := info.NewAsInfo(logr.Logger{}, host, &policy) + + conf, err := asconfig.GenerateConf(logr.Discard(), asInfo, true) + if err != nil { + logger.Error("Error reading configuration", + slog.Any("host", host), slog.Any("err", err)) + continue + } + asconf, _ := asconfig.NewMapAsConfig(logr.Discard(), conf.Conf) + configAsString, err := util.TryAndRecover(asconf.ToConfFile) + if err != nil { + logger.Error("Error serialising configuration", + slog.Any("host", host), slog.Any("err", err)) + continue + } + + outputs = append(outputs, configAsString) + } + + return outputs +} + +func getActiveHosts(client backup.AerospikeClient) []*as.Host { + var activeHosts []*as.Host + for _, node := range client.GetNodes() { + if node.IsActive() { + activeHosts = append(activeHosts, node.GetHost()) + } + } + + return activeHosts +} diff --git a/pkg/service/config_applier.go b/pkg/service/config_applier.go index e72d3636..521fad39 100644 --- a/pkg/service/config_applier.go +++ b/pkg/service/config_applier.go @@ -7,6 +7,7 @@ import ( "sync" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "github.com/reugn/go-quartz/matcher" "github.com/reugn/go-quartz/quartz" ) @@ -21,7 +22,7 @@ type DefaultConfigApplier struct { scheduler quartz.Scheduler config *model.Config backends BackendsHolder - clientManager ClientManager + clientManager aerospike.ClientManager handlerHolder BackupHandlerHolder } @@ -29,7 +30,7 @@ func NewDefaultConfigApplier( scheduler quartz.Scheduler, config *model.Config, backends BackendsHolder, - manager ClientManager, + manager aerospike.ClientManager, handlerHolder BackupHandlerHolder, ) ConfigApplier { return &DefaultConfigApplier{ @@ -86,7 +87,7 @@ func (a *DefaultConfigApplier) clearPeriodicSchedulerJobs() error { // makeHandlers creates and returns a map of backup handlers per the configured routines. func makeHandlers( ctx context.Context, - clientManager ClientManager, + clientManager aerospike.ClientManager, config *model.Config, backends BackendsHolder, oldHandlers BackupHandlerHolder, @@ -112,7 +113,7 @@ func makeHandlers( func makeHandler( ctx context.Context, - clientManager ClientManager, + clientManager aerospike.ClientManager, config *model.Config, backends BackendsHolder, oldHandlers BackupHandlerHolder, diff --git a/pkg/service/restore_data.go b/pkg/service/restore_data.go index 58ba19a4..bd0efa69 100644 --- a/pkg/service/restore_data.go +++ b/pkg/service/restore_data.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/aerospike/aerospike-backup-service/v2/pkg/model" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" "github.com/aerospike/aerospike-backup-service/v2/pkg/service/storage" "github.com/aerospike/backup-go" "github.com/prometheus/client_golang/prometheus" @@ -25,8 +26,8 @@ type dataRestorer struct { restoreJobs *RestoreJobsHolder restoreService Restore backends BackendsHolder - clientManager ClientManager - nsValidator NamespaceValidator + clientManager aerospike.ClientManager + nsValidator aerospike.NamespaceValidator } var _ RestoreManager = (*dataRestorer)(nil) @@ -35,9 +36,9 @@ var _ RestoreManager = (*dataRestorer)(nil) func NewRestoreManager(backends BackendsHolder, config *model.Config, restoreService Restore, - clientManager ClientManager, + clientManager aerospike.ClientManager, restoreJobs *RestoreJobsHolder, - nsValidator NamespaceValidator, + nsValidator aerospike.NamespaceValidator, ) RestoreManager { return &dataRestorer{ configRetriever: configRetriever{ diff --git a/pkg/validation/config_validation.go b/pkg/validation/config_validation.go index 184a2a43..06643ae6 100644 --- a/pkg/validation/config_validation.go +++ b/pkg/validation/config_validation.go @@ -4,10 +4,10 @@ import ( "fmt" "github.com/aerospike/aerospike-backup-service/v2/pkg/dto" - "github.com/aerospike/aerospike-backup-service/v2/pkg/service" + "github.com/aerospike/aerospike-backup-service/v2/pkg/service/aerospike" ) -var nsValidator = &service.NoopNamespaceValidator{} +var nsValidator = &aerospike.NoopNamespaceValidator{} // ValidateStaticFieldChanges checks if new config changes are allowed as per dynamic consideration. func ValidateStaticFieldChanges(oldConf, newConf *dto.Config) error { @@ -16,11 +16,22 @@ func ValidateStaticFieldChanges(oldConf, newConf *dto.Config) error { } func ValidateConfiguration(conf *dto.Config) error { + if conf == nil { + return fmt.Errorf("config is nil") + } + _, err := conf.ToModel(nsValidator) return err } -func ValidateRestoreRequest(request dto.RestoreRequest, conf *dto.Config) error { +func ValidateRestoreRequest(request *dto.RestoreRequest, conf *dto.Config) error { + if conf == nil { + return fmt.Errorf("config is nil") + } + if request == nil { + return fmt.Errorf("restore request is nil") + } + model, err := conf.ToModel(nsValidator) if err != nil { return fmt.Errorf("config invalid: %w", err) @@ -35,7 +46,14 @@ func ValidateRestoreRequest(request dto.RestoreRequest, conf *dto.Config) error return err } -func ValidateRestoreTimestampRequest(request dto.RestoreTimestampRequest, conf *dto.Config) error { +func ValidateRestoreTimestampRequest(request *dto.RestoreTimestampRequest, conf *dto.Config) error { + if conf == nil { + return fmt.Errorf("config is nil") + } + if request == nil { + return fmt.Errorf("restore request is nil") + } + model, err := conf.ToModel(nsValidator) if err != nil { return fmt.Errorf("config invalid: %w", err)