Skip to content

Commit

Permalink
chore: add jira configuration section
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Aguilar <[email protected]>
  • Loading branch information
thepabloaguilar committed Oct 31, 2024
1 parent 448dc5e commit 6d14aa6
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 30 deletions.
10 changes: 10 additions & 0 deletions config/flipt.schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ import "strings"
cloud?: {
enabled?: bool | *false
}
jira?: {
enabled?: bool | *false
instance_name: string
authentication: {
oauth: {
client_id: string
client_secret: string
}
}
}
}

#duration: "^([0-9]+(ns|us|µs|ms|s|m|h))+$"
Expand Down
30 changes: 30 additions & 0 deletions config/flipt.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,36 @@
"default": false
}
}
},
"jira": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"default": false
},
"instance_name": {
"type": "string"
},
"authentication": {
"type": "object",
"additionalProperties": false,
"properties": {
"oauth": {
"type": "object",
"properties": {
"client_id": {
"type": "string"
},
"client_secret": {
"type": "string"
}
}
}
}
}
}
}
},
"title": "Experimental"
Expand Down
26 changes: 26 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,21 @@ func TestLoad(t *testing.T) {
return cfg
},
},
{
name: "empty instance name when jira integration is enabled",
path: "./testdata/experimental/jira_empty_instance_name.yml",
wantErr: errors.New("instance name cannot be empty when jira integration is enabled"),
},
{
name: "empty oauth client id when jira integration is enabled",
path: "./testdata/experimental/jira_empty_oauth_client_id.yml",
wantErr: errors.New("invalid oauth parameters for jira integration"),
},
{
name: "empty oauth client secret when jira integration is enabled",
path: "./testdata/experimental/jira_empty_oauth_client_secret.yml",
wantErr: errors.New("invalid oauth parameters for jira integration"),
},
{
name: "authentication github requires read:org scope when allowing orgs",
path: "./testdata/authentication/github_missing_org_scope.yml",
Expand Down Expand Up @@ -939,6 +954,17 @@ func TestLoad(t *testing.T) {
},
}

cfg.Experimental.Jira = Jira{
Enabled: true,
InstanceName: "INSTANCE_NAME",
Authentication: JiraAuthentication{
OAuth: JiraOauth{
ClientID: "CLIENT_ID",
ClientSecret: "CLIENT_SECRET",
},
},
}

return cfg
},
},
Expand Down
37 changes: 37 additions & 0 deletions internal/config/experimental.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,57 @@
package config

import (
"errors"
"strings"

"github.com/spf13/viper"
)

// ExperimentalConfig allows for experimental features to be enabled
// and disabled.
type ExperimentalConfig struct {
Jira Jira `json:"jira,omitempty" mapstructure:"jira" yaml:"jira,omitempty"`
}

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

func (c *ExperimentalConfig) validate() error {
return c.Jira.validate()
}

// ExperimentalFlag is a structure which has properties to configure
// experimental feature enablement.
type ExperimentalFlag struct {
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"`
}

type Jira struct {
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"`
InstanceName string `json:"instanceName,omitempty" mapstructure:"instance_name" yaml:"instance_name,omitempty"`
Authentication JiraAuthentication `json:"authentication,omitempty" mapstructure:"authentication" yaml:"authentication,omitempty"`
}

func (j *Jira) validate() error {
if j.Enabled {
if strings.TrimSpace(j.InstanceName) == "" {
return errors.New("instance name cannot be empty when jira integration is enabled")
}

if strings.TrimSpace(j.Authentication.OAuth.ClientID) == "" || strings.TrimSpace(j.Authentication.OAuth.ClientSecret) == "" {
return errors.New("invalid oauth parameters for jira integration")
}
}

return nil
}

type JiraAuthentication struct {
OAuth JiraOauth `json:"oauth,omitempty" mapstructure:"oauth" yaml:"oauth,omitempty"`
}

type JiraOauth struct {
ClientID string `json:"-" mapstructure:"client_id" yaml:"-"`
ClientSecret string `json:"-" mapstructure:"client_secret" yaml:"-"`
}
7 changes: 7 additions & 0 deletions internal/config/testdata/advanced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,10 @@ authorization:
experimental:
authorization:
enabled: true
jira:
enabled: true
instance_name: "INSTANCE_NAME"
authentication:
oauth:
client_id: "CLIENT_ID"
client_secret: "CLIENT_SECRET"
61 changes: 61 additions & 0 deletions internal/config/testdata/experimental/jira_empty_instance_name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
log:
level: INFO
encoding: console
grpc_level: ERROR

ui:
default_theme: system

analytics:
buffer:
flush_period: "10s"

cors:
enabled: false
allowed_origins:
- "*"
allowed_headers:
- "Accept"
- "Authorization"
- "Content-Type"
- "X-CSRF-Token"
- "X-Fern-Language"
- "X-Fern-SDK-Name"
- "X-Fern-SDK-Version"
- "X-Flipt-Namespace"
- "X-Flipt-Accept-Server-Version"

server:
host: 0.0.0.0
http_port: 8080
https_port: 443
grpc_port: 9000

metrics:
enabled: true
exporter: prometheus

storage:
type: database

diagnostics:
profiling:
enabled: true

db:
url: file:/var/opt/flipt/flipt.db
max_idle_conn: 2
prepared_statements_enabled: true

experimental:
jira:
enabled: true
instance_name: ""
authentication:
oauth:
client_id: "CLIENT_ID"
client_secret: "CLIENT_SECRET"

meta:
check_for_updates: true
telemetry_enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
log:
level: INFO
encoding: console
grpc_level: ERROR

ui:
default_theme: system

analytics:
buffer:
flush_period: "10s"

cors:
enabled: false
allowed_origins:
- "*"
allowed_headers:
- "Accept"
- "Authorization"
- "Content-Type"
- "X-CSRF-Token"
- "X-Fern-Language"
- "X-Fern-SDK-Name"
- "X-Fern-SDK-Version"
- "X-Flipt-Namespace"
- "X-Flipt-Accept-Server-Version"

server:
host: 0.0.0.0
http_port: 8080
https_port: 443
grpc_port: 9000

metrics:
enabled: true
exporter: prometheus

storage:
type: database

diagnostics:
profiling:
enabled: true

db:
url: file:/var/opt/flipt/flipt.db
max_idle_conn: 2
prepared_statements_enabled: true

experimental:
jira:
enabled: true
instance_name: "INSTANCE_NAME"
authentication:
oauth:
client_id: ""
client_secret: "CLIENT_SECRET"

meta:
check_for_updates: true
telemetry_enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
log:
level: INFO
encoding: console
grpc_level: ERROR

ui:
default_theme: system

analytics:
buffer:
flush_period: "10s"

cors:
enabled: false
allowed_origins:
- "*"
allowed_headers:
- "Accept"
- "Authorization"
- "Content-Type"
- "X-CSRF-Token"
- "X-Fern-Language"
- "X-Fern-SDK-Name"
- "X-Fern-SDK-Version"
- "X-Flipt-Namespace"
- "X-Flipt-Accept-Server-Version"

server:
host: 0.0.0.0
http_port: 8080
https_port: 443
grpc_port: 9000

metrics:
enabled: true
exporter: prometheus

storage:
type: database

diagnostics:
profiling:
enabled: true

db:
url: file:/var/opt/flipt/flipt.db
max_idle_conn: 2
prepared_statements_enabled: true

experimental:
jira:
enabled: true
instance_name: "INSTANCE_NAME"
authentication:
oauth:
client_id: "CLIENT_ID"
client_secret: ""

meta:
check_for_updates: true
telemetry_enabled: true
Loading

0 comments on commit 6d14aa6

Please sign in to comment.