2024-07-01 00:54:05 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2024-07-27 18:56:09 +02:00
|
|
|
"errors"
|
|
|
|
"io"
|
2024-08-19 14:13:16 +02:00
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
2024-07-01 00:54:05 +02:00
|
|
|
)
|
|
|
|
|
2024-12-06 23:56:18 +01:00
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
2024-07-01 00:54:05 +02:00
|
|
|
type Config struct {
|
2024-07-27 18:56:09 +02:00
|
|
|
Debug bool
|
2024-07-01 00:54:05 +02:00
|
|
|
ForceCommits bool
|
2024-08-19 14:13:16 +02:00
|
|
|
JSONFormat bool
|
2024-07-01 00:54:05 +02:00
|
|
|
GrafanaURL string
|
|
|
|
GrafanaToken string
|
|
|
|
GitBranch string
|
2024-07-27 18:56:09 +02:00
|
|
|
GitEmail string
|
2024-07-01 00:54:05 +02:00
|
|
|
GitRepo string
|
|
|
|
GitUser string
|
|
|
|
GitPass string
|
|
|
|
GPGKey string
|
2024-08-19 20:22:41 +02:00
|
|
|
Quiet bool
|
2024-12-07 00:52:25 +01:00
|
|
|
Sequence []string
|
2024-07-27 18:56:09 +02:00
|
|
|
|
|
|
|
Output io.Writer
|
2024-08-19 14:13:16 +02:00
|
|
|
Logger zerolog.Logger
|
2024-07-01 00:54:05 +02:00
|
|
|
}
|
|
|
|
|
2024-08-19 14:13:16 +02:00
|
|
|
func (c *Config) Validate() []error {
|
|
|
|
var errs []error
|
2024-07-27 18:56:09 +02:00
|
|
|
|
|
|
|
if c.GrafanaURL == "" {
|
2024-12-06 23:56:18 +01:00
|
|
|
errs = append(errs, ErrInvalidGrafanaURL)
|
2024-07-27 18:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.GrafanaToken == "" {
|
2024-12-06 23:56:18 +01:00
|
|
|
errs = append(errs, ErrInvalidAuthToken)
|
2024-07-27 18:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.GitRepo == "" {
|
2024-12-06 23:56:18 +01:00
|
|
|
errs = append(errs, ErrInvalidRepoURL)
|
2024-07-27 18:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.GitUser == "" {
|
2024-12-06 23:56:18 +01:00
|
|
|
errs = append(errs, ErrInvalidGitUser)
|
2024-07-27 18:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.GitPass == "" {
|
2024-12-06 23:56:18 +01:00
|
|
|
errs = append(errs, ErrInvalidGitPass)
|
2024-07-27 18:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.GitBranch == "" {
|
2024-12-06 23:56:18 +01:00
|
|
|
errs = append(errs, ErrInvalidBranchName)
|
2024-07-27 18:56:09 +02:00
|
|
|
}
|
|
|
|
|
2024-08-19 14:13:16 +02:00
|
|
|
return errs
|
2024-07-01 00:54:05 +02:00
|
|
|
}
|