From 5b51d3b21a213b42c7a9f5b7a8ac88950714e284 Mon Sep 17 00:00:00 2001 From: Brandon Wilson Date: Wed, 9 Dec 2020 15:58:50 -0600 Subject: [PATCH] Update dashboard config fields Signed-off-by: Brandon Wilson --- cmd/apply.go | 17 +++++++++-------- example.init.yaml | 1 + pkg/stack/stack.go | 25 ++++++++++++++++++++++--- pkg/types/types.go | 1 + scripts/export-sealed-secret-pubcert.sh | 1 - templates/dashboard_config.yml | 8 ++++++++ 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/cmd/apply.go b/cmd/apply.go index 4e99347..3ad8337 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -362,13 +362,7 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string } } - fmt.Println("Creating stack.yml") - - planErr := stack.Apply(plan) - if planErr != nil { - log.Println(planErr) - } - + var pubCert string if !prefs.SkipSealedSecrets { sealedSecretsErr := installSealedSecrets() if sealedSecretsErr != nil { @@ -376,7 +370,7 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string return sealedSecretsErr } - pubCert := exportSealedSecretPubCert() + pubCert = exportSealedSecretPubCert() writeErr := ioutil.WriteFile("tmp/pubcert.pem", []byte(pubCert), 0700) if writeErr != nil { log.Println(writeErr) @@ -384,6 +378,13 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string } } + fmt.Println("Creating stack.yml") + + planErr := stack.Apply(plan, pubCert) + if planErr != nil { + log.Println(planErr) + } + cloneErr := cloneCloudComponents(plan.OpenFaaSCloudVersion, additionalPaths) if cloneErr != nil { return cloneErr diff --git a/example.init.yaml b/example.init.yaml index 3eaa7e5..9773f4b 100644 --- a/example.init.yaml +++ b/example.init.yaml @@ -239,6 +239,7 @@ scm: github ## Populate from GitHub App github: app_id: "24304" + public_link: "https://github.com/apps/o6s-io" ## GitLab ### Public URL for your GitLab instance with a trailing slash diff --git a/pkg/stack/stack.go b/pkg/stack/stack.go index 898ec36..b537a39 100644 --- a/pkg/stack/stack.go +++ b/pkg/stack/stack.go @@ -5,6 +5,7 @@ import ( "html/template" "io/ioutil" "os" + "strings" "github.com/openfaas/ofc-bootstrap/pkg/types" ) @@ -50,8 +51,16 @@ type awsConfig struct { ECRRegion string } +type dashboardConfig struct { + RootDomain string + Scheme string + GitHubAppUrl string + GitLabInstance string + PublicKey string +} + // Apply creates `templates/gateway_config.yml` to be referenced by stack.yml -func Apply(plan types.Plan) error { +func Apply(plan types.Plan, pubCert string) error { scheme := "http" if plan.TLS { scheme += "s" @@ -98,8 +107,18 @@ func Apply(plan types.Plan) error { } } - dashboardConfigErr := generateTemplate("dashboard_config", plan, gatewayConfig{ - RootDomain: plan.RootDomain, Scheme: scheme, + var gitHubAppUrl, gitLabInstance string + if plan.SCM == types.GitHubSCM { + gitHubAppUrl = plan.Github.PublicLink + } else if plan.SCM == types.GitLabSCM { + gitLabInstance = plan.Gitlab.GitLabInstance + } + dashboardConfigErr := generateTemplate("dashboard_config", plan, dashboardConfig{ + RootDomain: plan.RootDomain, + Scheme: scheme, + GitHubAppUrl: gitHubAppUrl, + GitLabInstance: gitLabInstance, + PublicKey: strings.ReplaceAll(pubCert, "\n", "\n "), }) if dashboardConfigErr != nil { return dashboardConfigErr diff --git a/pkg/types/types.go b/pkg/types/types.go index cd59f34..cfa5885 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -122,6 +122,7 @@ type KeyValueNamespaceTuple struct { type Github struct { AppID string `yaml:"app_id,omitempty"` PrivateKeyFile string `yaml:"private_key_filename,omitempty"` + PublicLink string `yaml:"public_link,omitempty"` } type Gitlab struct { diff --git a/scripts/export-sealed-secret-pubcert.sh b/scripts/export-sealed-secret-pubcert.sh index 424ddec..09daf79 100755 --- a/scripts/export-sealed-secret-pubcert.sh +++ b/scripts/export-sealed-secret-pubcert.sh @@ -13,6 +13,5 @@ then chmod +x /tmp/kubeseal fi -/tmp/kubeseal --version /tmp/kubeseal --fetch-cert --controller-name=ofc-sealedsecrets-sealed-secrets > tmp/pub-cert.pem && \ cat tmp/pub-cert.pem diff --git a/templates/dashboard_config.yml b/templates/dashboard_config.yml index a4afe54..ab16086 100644 --- a/templates/dashboard_config.yml +++ b/templates/dashboard_config.yml @@ -12,3 +12,11 @@ environment: query_pretty_url: 'true' # Cookie root domain is needed to remove OAuth tokens when using OAuth, it doesnt matter if its set when not using OAuth cookie_root_domain: '.system.{{.RootDomain}}' + # Public URL for your GitHub app + # see https://github.com/settings/apps/ + github_app_url: {{.GitHubAppUrl}} + # Public URL for your GitLab instance + gitlab_url: {{.GitLabInstance}} + # SealedSecrets public key + public_key: | + {{.PublicKey}}