Skip to content

Commit 6d14aa6

Browse files
chore: add jira configuration section
Signed-off-by: Pablo Aguilar <[email protected]>
1 parent 448dc5e commit 6d14aa6

10 files changed

+356
-30
lines changed

config/flipt.schema.cue

+10
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ import "strings"
435435
cloud?: {
436436
enabled?: bool | *false
437437
}
438+
jira?: {
439+
enabled?: bool | *false
440+
instance_name: string
441+
authentication: {
442+
oauth: {
443+
client_id: string
444+
client_secret: string
445+
}
446+
}
447+
}
438448
}
439449

440450
#duration: "^([0-9]+(ns|us|µs|ms|s|m|h))+$"

config/flipt.schema.json

+30
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,36 @@
14751475
"default": false
14761476
}
14771477
}
1478+
},
1479+
"jira": {
1480+
"type": "object",
1481+
"additionalProperties": false,
1482+
"properties": {
1483+
"enabled": {
1484+
"type": "boolean",
1485+
"default": false
1486+
},
1487+
"instance_name": {
1488+
"type": "string"
1489+
},
1490+
"authentication": {
1491+
"type": "object",
1492+
"additionalProperties": false,
1493+
"properties": {
1494+
"oauth": {
1495+
"type": "object",
1496+
"properties": {
1497+
"client_id": {
1498+
"type": "string"
1499+
},
1500+
"client_secret": {
1501+
"type": "string"
1502+
}
1503+
}
1504+
}
1505+
}
1506+
}
1507+
}
14781508
}
14791509
},
14801510
"title": "Experimental"

internal/config/config_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,21 @@ func TestLoad(t *testing.T) {
605605
return cfg
606606
},
607607
},
608+
{
609+
name: "empty instance name when jira integration is enabled",
610+
path: "./testdata/experimental/jira_empty_instance_name.yml",
611+
wantErr: errors.New("instance name cannot be empty when jira integration is enabled"),
612+
},
613+
{
614+
name: "empty oauth client id when jira integration is enabled",
615+
path: "./testdata/experimental/jira_empty_oauth_client_id.yml",
616+
wantErr: errors.New("invalid oauth parameters for jira integration"),
617+
},
618+
{
619+
name: "empty oauth client secret when jira integration is enabled",
620+
path: "./testdata/experimental/jira_empty_oauth_client_secret.yml",
621+
wantErr: errors.New("invalid oauth parameters for jira integration"),
622+
},
608623
{
609624
name: "authentication github requires read:org scope when allowing orgs",
610625
path: "./testdata/authentication/github_missing_org_scope.yml",
@@ -939,6 +954,17 @@ func TestLoad(t *testing.T) {
939954
},
940955
}
941956

957+
cfg.Experimental.Jira = Jira{
958+
Enabled: true,
959+
InstanceName: "INSTANCE_NAME",
960+
Authentication: JiraAuthentication{
961+
OAuth: JiraOauth{
962+
ClientID: "CLIENT_ID",
963+
ClientSecret: "CLIENT_SECRET",
964+
},
965+
},
966+
}
967+
942968
return cfg
943969
},
944970
},

internal/config/experimental.go

+37
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,57 @@
11
package config
22

33
import (
4+
"errors"
5+
"strings"
6+
47
"github.com/spf13/viper"
58
)
69

710
// ExperimentalConfig allows for experimental features to be enabled
811
// and disabled.
912
type ExperimentalConfig struct {
13+
Jira Jira `json:"jira,omitempty" mapstructure:"jira" yaml:"jira,omitempty"`
1014
}
1115

1216
func (c *ExperimentalConfig) deprecations(v *viper.Viper) []deprecated {
1317
return nil
1418
}
1519

20+
func (c *ExperimentalConfig) validate() error {
21+
return c.Jira.validate()
22+
}
23+
1624
// ExperimentalFlag is a structure which has properties to configure
1725
// experimental feature enablement.
1826
type ExperimentalFlag struct {
1927
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"`
2028
}
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+
}

internal/config/testdata/advanced.yml

+7
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,10 @@ authorization:
121121
experimental:
122122
authorization:
123123
enabled: true
124+
jira:
125+
enabled: true
126+
instance_name: "INSTANCE_NAME"
127+
authentication:
128+
oauth:
129+
client_id: "CLIENT_ID"
130+
client_secret: "CLIENT_SECRET"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
log:
2+
level: INFO
3+
encoding: console
4+
grpc_level: ERROR
5+
6+
ui:
7+
default_theme: system
8+
9+
analytics:
10+
buffer:
11+
flush_period: "10s"
12+
13+
cors:
14+
enabled: false
15+
allowed_origins:
16+
- "*"
17+
allowed_headers:
18+
- "Accept"
19+
- "Authorization"
20+
- "Content-Type"
21+
- "X-CSRF-Token"
22+
- "X-Fern-Language"
23+
- "X-Fern-SDK-Name"
24+
- "X-Fern-SDK-Version"
25+
- "X-Flipt-Namespace"
26+
- "X-Flipt-Accept-Server-Version"
27+
28+
server:
29+
host: 0.0.0.0
30+
http_port: 8080
31+
https_port: 443
32+
grpc_port: 9000
33+
34+
metrics:
35+
enabled: true
36+
exporter: prometheus
37+
38+
storage:
39+
type: database
40+
41+
diagnostics:
42+
profiling:
43+
enabled: true
44+
45+
db:
46+
url: file:/var/opt/flipt/flipt.db
47+
max_idle_conn: 2
48+
prepared_statements_enabled: true
49+
50+
experimental:
51+
jira:
52+
enabled: true
53+
instance_name: ""
54+
authentication:
55+
oauth:
56+
client_id: "CLIENT_ID"
57+
client_secret: "CLIENT_SECRET"
58+
59+
meta:
60+
check_for_updates: true
61+
telemetry_enabled: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
log:
2+
level: INFO
3+
encoding: console
4+
grpc_level: ERROR
5+
6+
ui:
7+
default_theme: system
8+
9+
analytics:
10+
buffer:
11+
flush_period: "10s"
12+
13+
cors:
14+
enabled: false
15+
allowed_origins:
16+
- "*"
17+
allowed_headers:
18+
- "Accept"
19+
- "Authorization"
20+
- "Content-Type"
21+
- "X-CSRF-Token"
22+
- "X-Fern-Language"
23+
- "X-Fern-SDK-Name"
24+
- "X-Fern-SDK-Version"
25+
- "X-Flipt-Namespace"
26+
- "X-Flipt-Accept-Server-Version"
27+
28+
server:
29+
host: 0.0.0.0
30+
http_port: 8080
31+
https_port: 443
32+
grpc_port: 9000
33+
34+
metrics:
35+
enabled: true
36+
exporter: prometheus
37+
38+
storage:
39+
type: database
40+
41+
diagnostics:
42+
profiling:
43+
enabled: true
44+
45+
db:
46+
url: file:/var/opt/flipt/flipt.db
47+
max_idle_conn: 2
48+
prepared_statements_enabled: true
49+
50+
experimental:
51+
jira:
52+
enabled: true
53+
instance_name: "INSTANCE_NAME"
54+
authentication:
55+
oauth:
56+
client_id: ""
57+
client_secret: "CLIENT_SECRET"
58+
59+
meta:
60+
check_for_updates: true
61+
telemetry_enabled: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
log:
2+
level: INFO
3+
encoding: console
4+
grpc_level: ERROR
5+
6+
ui:
7+
default_theme: system
8+
9+
analytics:
10+
buffer:
11+
flush_period: "10s"
12+
13+
cors:
14+
enabled: false
15+
allowed_origins:
16+
- "*"
17+
allowed_headers:
18+
- "Accept"
19+
- "Authorization"
20+
- "Content-Type"
21+
- "X-CSRF-Token"
22+
- "X-Fern-Language"
23+
- "X-Fern-SDK-Name"
24+
- "X-Fern-SDK-Version"
25+
- "X-Flipt-Namespace"
26+
- "X-Flipt-Accept-Server-Version"
27+
28+
server:
29+
host: 0.0.0.0
30+
http_port: 8080
31+
https_port: 443
32+
grpc_port: 9000
33+
34+
metrics:
35+
enabled: true
36+
exporter: prometheus
37+
38+
storage:
39+
type: database
40+
41+
diagnostics:
42+
profiling:
43+
enabled: true
44+
45+
db:
46+
url: file:/var/opt/flipt/flipt.db
47+
max_idle_conn: 2
48+
prepared_statements_enabled: true
49+
50+
experimental:
51+
jira:
52+
enabled: true
53+
instance_name: "INSTANCE_NAME"
54+
authentication:
55+
oauth:
56+
client_id: "CLIENT_ID"
57+
client_secret: ""
58+
59+
meta:
60+
check_for_updates: true
61+
telemetry_enabled: true

0 commit comments

Comments
 (0)