refactor(internal/cmd): move backend cmd functions to grafanabackuper package
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tom Neuber 2024-08-19 14:13:16 +02:00
parent 840008df2d
commit 83a15b5a87
Signed by: tom
GPG key ID: F17EFE4272D89FF6
7 changed files with 112 additions and 264 deletions

View file

@ -3,11 +3,14 @@ package config
import (
"errors"
"io"
"github.com/rs/zerolog"
)
type Config struct {
Debug bool
ForceCommits bool
JSONFormat bool
GrafanaURL string
GrafanaToken string
GitBranch string
@ -18,34 +21,35 @@ type Config struct {
GPGKey string
Output io.Writer
Logger zerolog.Logger
}
func (c *Config) Validate() error {
var err error
func (c *Config) Validate() []error {
var errs []error
if c.GrafanaURL == "" {
err = errors.Join(err, errors.New("invalid grafana URL, must not be blank"))
errs = append(errs, errors.New("invalid grafana URL, must not be blank"))
}
if c.GrafanaToken == "" {
err = errors.Join(err, errors.New("invalid auth token for grafana, must not be blank"))
errs = append(errs, errors.New("invalid auth token for grafana, must not be blank"))
}
if c.GitRepo == "" {
err = errors.Join(err, errors.New("invalid repo url for git, must not be blank"))
errs = append(errs, errors.New("invalid repo url for git, must not be blank"))
}
if c.GitUser == "" {
err = errors.Join(err, errors.New("invalid username for git, must not be blank"))
errs = append(errs, errors.New("invalid username for git, must not be blank"))
}
if c.GitPass == "" {
err = errors.Join(err, errors.New("invalid password for git, must not be blank"))
errs = append(errs, errors.New("invalid password for git, must not be blank"))
}
if c.GitBranch == "" {
err = errors.Join(err, errors.New("invalid branch name for git, must not be blank"))
errs = append(errs, errors.New("invalid branch name for git, must not be blank"))
}
return err
return errs
}