Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add jira configuration section #3574

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
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
Loading