Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APPS-1354 Relax storage configuration validation for GCP and Azure #267

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1997,8 +1997,7 @@ const docTemplate = `{
"dto.GcpStorage": {
"type": "object",
"required": [
"bucket-name",
"key-file"
"bucket-name"
],
"properties": {
"bucket-name": {
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@
"type" : "string"
}
},
"required" : [ "bucket-name", "key-file" ],
"required" : [ "bucket-name" ],
"type" : "object"
},
"dto.HTTPServerConfig" : {
Expand Down
1 change: 0 additions & 1 deletion docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 20 additions & 19 deletions pkg/dto/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/model/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading