grafana-backuper/internal/config/config.go
Tom Neuber 579f2a5df7
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
feat(cmd): add sequence flag to execute multiple functions
2024-12-07 01:38:24 +01:00

66 lines
1.4 KiB
Go

package config
import (
"errors"
"io"
"github.com/rs/zerolog"
)
var (
ErrInvalidGrafanaURL = errors.New("invalid grafana URL, must not be blank")
ErrInvalidAuthToken = errors.New("invalid auth token for grafana, must not be blank")
ErrInvalidRepoURL = errors.New("invalid repo url for git, must not be blank")
ErrInvalidGitUser = errors.New("invalid username for git, must not be blank")
ErrInvalidGitPass = errors.New("invalid password for git, must not be blank")
ErrInvalidBranchName = errors.New("invalid branch name for git, must not be blank")
)
type Config struct {
Debug bool
ForceCommits bool
JSONFormat bool
GrafanaURL string
GrafanaToken string
GitBranch string
GitEmail string
GitRepo string
GitUser string
GitPass string
GPGKey string
Quiet bool
Sequence []string
Output io.Writer
Logger zerolog.Logger
}
func (c *Config) Validate() []error {
var errs []error
if c.GrafanaURL == "" {
errs = append(errs, ErrInvalidGrafanaURL)
}
if c.GrafanaToken == "" {
errs = append(errs, ErrInvalidAuthToken)
}
if c.GitRepo == "" {
errs = append(errs, ErrInvalidRepoURL)
}
if c.GitUser == "" {
errs = append(errs, ErrInvalidGitUser)
}
if c.GitPass == "" {
errs = append(errs, ErrInvalidGitPass)
}
if c.GitBranch == "" {
errs = append(errs, ErrInvalidBranchName)
}
return errs
}