mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-08-26 02:46:28 +00:00
fix: prompt for user action to set an instance ID on upgrade
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/garethgeorge/backrest/internal/config/validationutil"
|
||||
"github.com/gitploy-io/cronexpr"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,11 @@ func ValidateConfig(c *v1.Config) error {
|
||||
var err error
|
||||
|
||||
if e := validationutil.ValidateID(c.Instance, validationutil.IDMaxLen); e != nil {
|
||||
err = multierror.Append(err, fmt.Errorf("instance ID %q invalid: %w", c.Instance, e))
|
||||
if errors.Is(e, validationutil.ErrEmpty) {
|
||||
zap.L().Warn("ACTION REQUIRED: instance ID is empty, will be required in a future update. Please open the backrest UI to set a unique instance ID. Until fixed this warning (and related errors) will print periodically.")
|
||||
} else {
|
||||
err = multierror.Append(err, fmt.Errorf("instance ID %q invalid: %w", c.Instance, e))
|
||||
}
|
||||
}
|
||||
|
||||
repos := make(map[string]*v1.Repo)
|
||||
|
||||
@@ -12,6 +12,12 @@ var (
|
||||
idRegex = regexp.MustCompile(`[a-zA-Z0-9_\-\.]*`) // matches a valid ID (including empty string)
|
||||
)
|
||||
|
||||
var (
|
||||
ErrEmpty = errors.New("empty")
|
||||
ErrTooLong = errors.New("too long")
|
||||
ErrInvalidChars = errors.New("contains invalid characters")
|
||||
)
|
||||
|
||||
func SanitizeID(id string) string {
|
||||
return sanitizeIDRegex.ReplaceAllString(id, "_")
|
||||
}
|
||||
@@ -21,13 +27,13 @@ func SanitizeID(id string) string {
|
||||
// The maxLen parameter is the maximum length of the ID. If maxLen is 0, the ID length is not checked.
|
||||
func ValidateID(id string, maxLen int) error {
|
||||
if !idRegex.MatchString(id) {
|
||||
return errors.New("contains invalid characters")
|
||||
return ErrInvalidChars
|
||||
}
|
||||
if len(id) == 0 {
|
||||
return errors.New("empty")
|
||||
return ErrEmpty
|
||||
}
|
||||
if maxLen > 0 && len(id) > maxLen {
|
||||
return fmt.Errorf("too long (> %d chars)", maxLen)
|
||||
return fmt.Errorf("(> %d chars): %w", maxLen, ErrTooLong)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user