|
1 | 1 | package config
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "errors" |
| 5 | + "strings" |
| 6 | + |
4 | 7 | "github.com/spf13/viper"
|
5 | 8 | )
|
6 | 9 |
|
7 | 10 | // ExperimentalConfig allows for experimental features to be enabled
|
8 | 11 | // and disabled.
|
9 | 12 | type ExperimentalConfig struct {
|
| 13 | + Jira Jira `json:"jira,omitempty" mapstructure:"jira" yaml:"jira,omitempty"` |
10 | 14 | }
|
11 | 15 |
|
12 | 16 | func (c *ExperimentalConfig) deprecations(v *viper.Viper) []deprecated {
|
13 | 17 | return nil
|
14 | 18 | }
|
15 | 19 |
|
| 20 | +func (c *ExperimentalConfig) validate() error { |
| 21 | + return c.Jira.validate() |
| 22 | +} |
| 23 | + |
16 | 24 | // ExperimentalFlag is a structure which has properties to configure
|
17 | 25 | // experimental feature enablement.
|
18 | 26 | type ExperimentalFlag struct {
|
19 | 27 | Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"`
|
20 | 28 | }
|
| 29 | + |
| 30 | +type Jira struct { |
| 31 | + Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"` |
| 32 | + InstanceName string `json:"instanceName,omitempty" mapstructure:"instance_name" yaml:"instance_name,omitempty"` |
| 33 | + Authentication JiraAuthentication `json:"authentication,omitempty" mapstructure:"authentication" yaml:"authentication,omitempty"` |
| 34 | +} |
| 35 | + |
| 36 | +func (j *Jira) validate() error { |
| 37 | + if j.Enabled { |
| 38 | + if strings.TrimSpace(j.InstanceName) == "" { |
| 39 | + return errors.New("instance name cannot be empty when jira integration is enabled") |
| 40 | + } |
| 41 | + |
| 42 | + if strings.TrimSpace(j.Authentication.OAuth.ClientID) == "" || strings.TrimSpace(j.Authentication.OAuth.ClientSecret) == "" { |
| 43 | + return errors.New("invalid oauth parameters for jira integration") |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + return nil |
| 48 | +} |
| 49 | + |
| 50 | +type JiraAuthentication struct { |
| 51 | + OAuth JiraOauth `json:"oauth,omitempty" mapstructure:"oauth" yaml:"oauth,omitempty"` |
| 52 | +} |
| 53 | + |
| 54 | +type JiraOauth struct { |
| 55 | + ClientID string `json:"-" mapstructure:"client_id" yaml:"-"` |
| 56 | + ClientSecret string `json:"-" mapstructure:"client_secret" yaml:"-"` |
| 57 | +} |
0 commit comments