feat(ops/besadii): Add other missing configuration keys

Adds configuration keys and rudimentary validation for all other
besadii settings that are currently hardcoded.

This adds the config options:

* repository: Name of the repository in Gerrit.
* branch: Name of the HEAD branch in the repository.
* gerritUrl: Base URL of the Gerrit instance
* gerritUser: Username of the Gerrit user
* gerritPassword: Password of the Gerrit user
* buildkiteOrg: Name of the Buildkite organisation
* buildkiteProject: Name of the pipeline inside the Buildkite
  organisation
* buildkiteToken: Auth token for Buildkite access

All of these configuration options are required.

Change-Id: Ie6b109de9cd8484a3773c6351d7fd140f39a49ed
This commit is contained in:
Vincent Ambo 2021-11-29 19:06:09 +03:00
parent ee635d4645
commit e48ae26e8e

View file

@ -34,6 +34,18 @@ var changeIdRegexp = regexp.MustCompile(`^.*/(\d+)$`)
// besadii configuration file structure
type config struct {
// Required configuration for Buildkite<>Gerrit monorepo
// integration.
Repository string `json:"repository"`
Branch string `json:"branch"`
GerritUrl string `json:"gerritUrl"`
GerritUser string `json:"gerritUser"`
GerritPassword string `json:"gerritPassword"`
BuildkiteOrg string `json:"buildkiteOrg"`
BuildkiteProject string `json:"buildkiteProject"`
BuildkiteToken string `json:"buildkiteToken"`
// Optional configuration for Sourcegraph trigger updates.
SourcegraphUrl string `json:"sourcegraphUrl"`
SourcegraphToken string `json:"sourcegraphToken"`
}
@ -107,6 +119,18 @@ func loadConfig() (*config, error) {
return nil, fmt.Errorf("'SourcegraphToken' must be set if 'SourcegraphUrl' is set")
}
if cfg.Repository == "" || cfg.Branch == "" {
return nil, fmt.Errorf("missing repository configuration (required: repository, branch)")
}
if cfg.GerritUrl == "" || cfg.GerritUser == "" || cfg.GerritPassword == "" {
return nil, fmt.Errorf("missing Gerrit configuration (required: gerritUrl, gerritUser, gerritPassword)")
}
if cfg.BuildkiteOrg == "" || cfg.BuildkiteProject == "" || cfg.BuildkiteToken == "" {
return nil, fmt.Errorf("mising Buildkite configuration (required: buildkiteOrg, buildkiteProject, buildkiteToken)")
}
return &cfg, nil
}