Skip to content

Commit

Permalink
better config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Sep 11, 2024
1 parent e03daa1 commit d654a94
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/utils/backups/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backups

import (
"errors"
"fmt"
"net/url"
"strings"
Expand All @@ -19,7 +20,7 @@ type Config struct {

// The path to a local disk directory to store compressed backups, e.g.
// file:///rel/path/ or a cloud location such as s3://bucket.
StorageDSN string `split_words:"true" required:"true"`
StorageDSN string `split_words:"true" required:"false"`

// Temporary directory to perform local backup to. If not set, then the OS tmpdir
// is used. Backups are generated in this folder and then moved to the storage
Expand All @@ -33,6 +34,16 @@ type Config struct {
Keep int `default:"1"`
}

// Validate the Config
func (c Config) Validate() error {
if c.Enabled {
if c.StorageDSN == "" {
return errors.New("invalid backup configuration: storage dsn is required")
}
}
return nil
}

// Storage returns the storage configuration specified by the storage DSN.
func (c Config) Storage() (_ Storage, err error) {
// Parse the DSN specified by the user
Expand Down

0 comments on commit d654a94

Please sign in to comment.