Skip to content

Commit

Permalink
Config and Test Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Victor Goklas authored and Jonathan Victor Goklas committed May 3, 2024
1 parent aa2fdfc commit a58ba60
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
14 changes: 6 additions & 8 deletions api/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ func startServer(cfg *config.Config) {
mount(router, "/v2", api.NewRouter(appCtx, v2Controllers))

uiEnv := uiEnvHandler{
APIURL: cfg.APIHost,
OauthClientID: cfg.OauthClientID,
Environment: cfg.Environment,
SentryDSN: cfg.SentryDSN,
Streams: cfg.Streams,
Docs: cfg.Docs,
MetadataUpdateEnabled: cfg.MetadataUpdateEnabled,
APIURL: cfg.APIHost,
OauthClientID: cfg.OauthClientID,
Environment: cfg.Environment,
SentryDSN: cfg.SentryDSN,
Streams: cfg.Streams,
Docs: cfg.Docs,
MaxAuthzCacheExpiryMinutes: fmt.Sprintf("%.0f",
math.Ceil((time.Duration(enforcer.MaxKeyExpirySeconds) * time.Second).Minutes())),
UIConfig: cfg.UI,
Expand Down Expand Up @@ -115,7 +114,6 @@ type uiEnvHandler struct {
Streams config.Streams `json:"REACT_APP_STREAMS"`
Docs config.Documentations `json:"REACT_APP_DOC_LINKS"`
MaxAuthzCacheExpiryMinutes string `json:"REACT_APP_MAX_AUTHZ_CACHE_EXPIRY_MINUTES"`
MetadataUpdateEnabled bool `json:"REACT_APP_METADATA_UPDATE_ENABLED"`
}

func (h uiEnvHandler) handler(w http.ResponseWriter, r *http.Request) {
Expand Down
16 changes: 8 additions & 8 deletions api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import (
)

type Config struct {
APIHost string `validate:"required"`
Environment string `validate:"required"`
Port int `validate:"required"`
SentryDSN string
OauthClientID string
MetadataUpdateEnabled bool
APIHost string `validate:"required"`
Environment string `validate:"required"`
Port int `validate:"required"`
SentryDSN string
OauthClientID string

Streams Streams `validate:"dive,required"`
Docs Documentations
Expand Down Expand Up @@ -117,8 +116,9 @@ type UIConfig struct {
StaticPath string `validated:"required"`
IndexPath string `validated:"required"`

ClockworkUIHomepage string `json:"REACT_APP_CLOCKWORK_UI_HOMEPAGE"`
KubeflowUIHomepage string `json:"REACT_APP_KUBEFLOW_UI_HOMEPAGE"`
ClockworkUIHomepage string `json:"REACT_APP_CLOCKWORK_UI_HOMEPAGE"`
KubeflowUIHomepage string `json:"REACT_APP_KUBEFLOW_UI_HOMEPAGE"`
MetadataUpdateEnabled bool `json:"REACT_APP_METADATA_UPDATE_ENABLED"`
}

// Transform env variables to the format consumed by koanf.
Expand Down
34 changes: 21 additions & 13 deletions api/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestLoad(t *testing.T) {
CacheCleanUpIntervalSeconds: 900,
},
},
MetadataUpdateEnabled: false,
Database: &config.DatabaseConfig{
Host: "localhost",
Port: 5432,
Expand All @@ -86,8 +85,9 @@ func TestLoad(t *testing.T) {
"EmptyStream": {},
},
UI: &config.UIConfig{
StaticPath: "ui/build",
IndexPath: "index.html",
StaticPath: "ui/build",
IndexPath: "index.html",
MetadataUpdateEnabled: false,
},
DefaultSecretStorage: &config.SecretStorage{
Name: "default-secret-storage",
Expand Down Expand Up @@ -122,7 +122,6 @@ func TestLoad(t *testing.T) {
CacheCleanUpIntervalSeconds: 900,
},
},
MetadataUpdateEnabled: false,
Database: &config.DatabaseConfig{
Host: "localhost",
Port: 5432,
Expand All @@ -144,8 +143,9 @@ func TestLoad(t *testing.T) {
"EmptyStream": {},
},
UI: &config.UIConfig{
StaticPath: "ui/build",
IndexPath: "index.html",
StaticPath: "ui/build",
IndexPath: "index.html",
MetadataUpdateEnabled: false,
},
DefaultSecretStorage: &config.SecretStorage{
Name: "default-secret-storage",
Expand Down Expand Up @@ -199,7 +199,6 @@ func TestLoad(t *testing.T) {
},
},
},
MetadataUpdateEnabled: false,
Authorization: &config.AuthorizationConfig{
Enabled: true,
KetoRemoteRead: "http://localhost:4466",
Expand Down Expand Up @@ -241,8 +240,9 @@ func TestLoad(t *testing.T) {
StaticPath: "ui/build",
IndexPath: "index.html",

ClockworkUIHomepage: "http://clockwork.dev",
KubeflowUIHomepage: "http://kubeflow.org",
ClockworkUIHomepage: "http://clockwork.dev",
KubeflowUIHomepage: "http://kubeflow.org",
MetadataUpdateEnabled: false,
},
DefaultSecretStorage: &config.SecretStorage{
Name: "default-secret-storage",
Expand Down Expand Up @@ -300,7 +300,6 @@ func TestValidate(t *testing.T) {
CacheCleanUpIntervalSeconds: 900,
},
},
MetadataUpdateEnabled: false,
Database: &config.DatabaseConfig{
Host: "localhost",
Port: 5432,
Expand All @@ -326,6 +325,9 @@ func TestValidate(t *testing.T) {
},
},
},
UI: &config.UIConfig{
MetadataUpdateEnabled: false,
},
},
},
"extended | success": {
Expand All @@ -342,7 +344,6 @@ func TestValidate(t *testing.T) {
CacheCleanUpIntervalSeconds: 900,
},
},
MetadataUpdateEnabled: false,
Database: &config.DatabaseConfig{
Host: "localhost",
Port: 5432,
Expand Down Expand Up @@ -371,6 +372,9 @@ func TestValidate(t *testing.T) {
},
},
},
UI: &config.UIConfig{
MetadataUpdateEnabled: false,
},
},
},
"default config | failure": {
Expand All @@ -394,7 +398,6 @@ func TestValidate(t *testing.T) {
CacheCleanUpIntervalSeconds: 900,
},
},
MetadataUpdateEnabled: false,
Database: &config.DatabaseConfig{
Host: "localhost",
Port: 5432,
Expand All @@ -420,6 +423,9 @@ func TestValidate(t *testing.T) {
},
},
},
UI: &config.UIConfig{
MetadataUpdateEnabled: false,
},
},
error: errors.New(
"failed to validate configuration: " +
Expand All @@ -440,7 +446,6 @@ func TestValidate(t *testing.T) {
Enabled: true,
},
},
MetadataUpdateEnabled: false,
Database: &config.DatabaseConfig{
Host: "localhost",
Port: 5432,
Expand All @@ -466,6 +471,9 @@ func TestValidate(t *testing.T) {
},
},
},
UI: &config.UIConfig{
MetadataUpdateEnabled: false,
},
},
error: errors.New(
"failed to validate configuration: " +
Expand Down
5 changes: 4 additions & 1 deletion api/config/testdata/config-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ defaultSecretStorage:
mountPath: secret
pathPrefix: caraml-secret/{{ .project }}/
authMethod: gcp
gcpAuthType: gce
gcpAuthType: gce

ui:
metadataUpdateEnabled: false
1 change: 1 addition & 0 deletions api/config/testdata/config-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ authorization:
ui:
clockworkUIHomepage: http://clockwork.dev
kubeflowUIHomepage: http://kubeflow.org
metadataUpdateEnabled: false

defaultSecretStorage:
name: default-secret-storage
Expand Down

0 comments on commit a58ba60

Please sign in to comment.