From 28f9a49c94bdd2fe8677dcdbc804f864177bcb26 Mon Sep 17 00:00:00 2001 From: akorotkov <akorotkov@aerospike.com> Date: Sun, 24 Nov 2024 10:48:07 +0200 Subject: [PATCH 1/3] allow empty auth for GCP and Azure --- pkg/dto/storage.go | 57 +++++++++++++++++++++++--------------------- pkg/model/storage.go | 2 +- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/pkg/dto/storage.go b/pkg/dto/storage.go index d31fef30..a12c9fa9 100644 --- a/pkg/dto/storage.go +++ b/pkg/dto/storage.go @@ -113,7 +113,7 @@ func (s *S3Storage) Validate() error { // GcpStorage represents the configuration for GCP storage. type GcpStorage struct { // Path to file containing Service Account JSON Key. - KeyFile string `yaml:"key-file" json:"key-file" validate:"required"` + KeyFile string `yaml:"key-file" json:"key-file"` // GCP storage bucket name. BucketName string `yaml:"bucket-name" json:"bucket-name" validate:"required"` // The root path for the backup repository. If not specified, backups will be saved in the bucket's root. @@ -125,9 +125,6 @@ type GcpStorage struct { // Validate checks if the GcpStorage is valid. func (g *GcpStorage) Validate() error { - if g.KeyFile == "" { - return errors.New("GCP key file is not specified") - } if g.BucketName == "" { return errors.New("GCP bucket name is not specified") } @@ -204,29 +201,33 @@ func (s *Storage) ToModel() model.Storage { } } if s.AzureStorage != nil { - azureStorage := &model.AzureStorage{ + return &model.AzureStorage{ Endpoint: s.AzureStorage.Endpoint, ContainerName: s.AzureStorage.ContainerName, Path: s.AzureStorage.Path, + Auth: getAzureAuth(s), } + } + slog.Info("error converting storage dto to model: no storage configuration provided") + return nil +} - switch { - case s.AzureStorage.AccountName != "" && s.AzureStorage.AccountKey != "": - azureStorage.Auth = model.AzureSharedKeyAuth{ - AccountName: s.AzureStorage.AccountName, - AccountKey: s.AzureStorage.AccountKey, - } - case s.AzureStorage.TenantID != "" && s.AzureStorage.ClientID != "" && s.AzureStorage.ClientSecret != "": - azureStorage.Auth = model.AzureADAuth{ - TenantID: s.AzureStorage.TenantID, - ClientID: s.AzureStorage.ClientID, - ClientSecret: s.AzureStorage.ClientSecret, - } +func getAzureAuth(s *Storage) model.AzureAuth { + if s.AzureStorage.AccountName != "" && s.AzureStorage.AccountKey != "" { + return model.AzureSharedKeyAuth{ + AccountName: s.AzureStorage.AccountName, + AccountKey: s.AzureStorage.AccountKey, } + } - return azureStorage + if s.AzureStorage.TenantID != "" && s.AzureStorage.ClientID != "" && s.AzureStorage.ClientSecret != "" { + return model.AzureADAuth{ + TenantID: s.AzureStorage.TenantID, + ClientID: s.AzureStorage.ClientID, + ClientSecret: s.AzureStorage.ClientSecret, + } } - slog.Info("error converting storage dto to model: no storage configuration provided") + return nil } @@ -268,14 +269,16 @@ func NewStorageFromModel(m model.Storage) *Storage { Path: s.Path, } - switch auth := s.Auth.(type) { - case model.AzureSharedKeyAuth: - azureStorage.AccountName = auth.AccountName - azureStorage.AccountKey = auth.AccountKey - case model.AzureADAuth: - azureStorage.TenantID = auth.TenantID - azureStorage.ClientID = auth.ClientID - azureStorage.ClientSecret = auth.ClientSecret + if s.Auth != nil { + switch auth := s.Auth.(type) { + case model.AzureSharedKeyAuth: + azureStorage.AccountName = auth.AccountName + azureStorage.AccountKey = auth.AccountKey + case model.AzureADAuth: + azureStorage.TenantID = auth.TenantID + azureStorage.ClientID = auth.ClientID + azureStorage.ClientSecret = auth.ClientSecret + } } return &Storage{ diff --git a/pkg/model/storage.go b/pkg/model/storage.go index 2c7dc139..9eb8308a 100644 --- a/pkg/model/storage.go +++ b/pkg/model/storage.go @@ -71,7 +71,7 @@ type AzureStorage struct { // ContainerName is the name of the Azure Blob container where backups will be stored. ContainerName string // Auth holds the authentication details for Azure Blob storage. - // It can be either AzureSharedKeyAuth or AzureADAuth. + // It can be nil or AzureSharedKeyAuth or AzureADAuth. Auth AzureAuth } From 46495446694d590e0cc988cffd87ecd64d4db9b6 Mon Sep 17 00:00:00 2001 From: akorotkov <akorotkov@aerospike.com> Date: Sun, 24 Nov 2024 10:49:14 +0200 Subject: [PATCH 2/3] regenerate openapi --- docs/docs.go | 3 +-- docs/openapi.json | 2 +- docs/openapi.yaml | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index eee8240a..f5524a33 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1997,8 +1997,7 @@ const docTemplate = `{ "dto.GcpStorage": { "type": "object", "required": [ - "bucket-name", - "key-file" + "bucket-name" ], "properties": { "bucket-name": { diff --git a/docs/openapi.json b/docs/openapi.json index bb2a8cb6..fce056b9 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -2152,7 +2152,7 @@ "type" : "string" } }, - "required" : [ "bucket-name", "key-file" ], + "required" : [ "bucket-name" ], "type" : "object" }, "dto.HTTPServerConfig" : { diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 4ada32d5..a52f87f4 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1730,7 +1730,6 @@ components: type: string required: - bucket-name - - key-file type: object dto.HTTPServerConfig: description: HTTPServerConfig represents the service's HTTP server configuration. From ac452dcfc1dd8b61b4967dcd5d3648151805968f Mon Sep 17 00:00:00 2001 From: akorotkov <akorotkov@aerospike.com> Date: Sun, 24 Nov 2024 10:55:30 +0200 Subject: [PATCH 3/3] rollback nil check --- pkg/dto/storage.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/dto/storage.go b/pkg/dto/storage.go index a12c9fa9..0bf57f3b 100644 --- a/pkg/dto/storage.go +++ b/pkg/dto/storage.go @@ -269,16 +269,14 @@ func NewStorageFromModel(m model.Storage) *Storage { Path: s.Path, } - if s.Auth != nil { - switch auth := s.Auth.(type) { - case model.AzureSharedKeyAuth: - azureStorage.AccountName = auth.AccountName - azureStorage.AccountKey = auth.AccountKey - case model.AzureADAuth: - azureStorage.TenantID = auth.TenantID - azureStorage.ClientID = auth.ClientID - azureStorage.ClientSecret = auth.ClientSecret - } + switch auth := s.Auth.(type) { + case model.AzureSharedKeyAuth: + azureStorage.AccountName = auth.AccountName + azureStorage.AccountKey = auth.AccountKey + case model.AzureADAuth: + azureStorage.TenantID = auth.TenantID + azureStorage.ClientID = auth.ClientID + azureStorage.ClientSecret = auth.ClientSecret } return &Storage{