Skip to content

Commit

Permalink
Re-instate setup mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Feb 15, 2019
1 parent 1955230 commit 4ccfb34
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/jetstream/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ func (n notFoundErr) Error() string {

// NewConfigFileLookup - Load the configuration values in the specified config file if it exists
func NewConfigFileLookup(path string) env.Lookup {

// Check if the config file exists
if _, err := os.Stat(path); err != nil {
return env.NoopLookup
}

file, err := os.Open(path)
if err != nil {
log.Warn("Error reading configuration file, ignoring this file: ", err)
Expand Down
44 changes: 36 additions & 8 deletions src/jetstream/setup_console.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -149,20 +150,47 @@ func (p *portalProxy) setupConsoleUpdate(c echo.Context) error {
func (p *portalProxy) initialiseConsoleConfig(consoleRepo console_config.Repository) (*interfaces.ConsoleConfig, error) {
log.Debug("initialiseConsoleConfig")

var err error

consoleConfig := new(interfaces.ConsoleConfig)
uaaEndpoint, found := p.Env().Lookup("UAA_ENDPOINT")
if !found {
return consoleConfig, errors.New("UAA_Endpoint not found")
}

consoleClient, found := p.Env().Lookup("CONSOLE_CLIENT")
if !found {
return consoleConfig, errors.New("CONSOLE_CLIENT not found")
}

consoleConfig.ConsoleClient = p.Env().MustString("CONSOLE_CLIENT")
// Special case, mostly this is blank, so assume its blank
// CHECK: Can we handle this better?
consoleConfig.ConsoleClientSecret = p.Env().String("CONSOLE_CLIENT_SECRET", "")
consoleConfig.ConsoleAdminScope = p.Env().MustString("CONSOLE_ADMIN_SCOPE")
consoleConfig.SkipSSLValidation = p.Env().MustBool("SKIP_SSL_VALIDATION")
consoleClientSecret, found := p.Env().Lookup("CONSOLE_CLIENT_SECRET")
if err != nil {
// Special case, mostly this is blank, so assume its blank
consoleClientSecret = ""
}

var err error
if consoleConfig.UAAEndpoint, err = url.Parse(p.Env().MustString("UAA_ENDPOINT")); err != nil {
consoleAdminScope, found := p.Env().Lookup("CONSOLE_ADMIN_SCOPE")
if !found {
return consoleConfig, errors.New("CONSOLE_ADMIN_SCOPE not found")
}

skipSslValidation, found := p.Env().Lookup("SKIP_SSL_VALIDATION")
if !found {
return consoleConfig, errors.New("SKIP_SSL_VALIDATION not found")
}

if consoleConfig.UAAEndpoint, err = url.Parse(uaaEndpoint); err != nil {
return consoleConfig, fmt.Errorf("Unable to parse UAA Endpoint: %v", err)
}

consoleConfig.ConsoleAdminScope = consoleAdminScope
consoleConfig.ConsoleClient = consoleClient
consoleConfig.ConsoleClientSecret = consoleClientSecret
consoleConfig.SkipSSLValidation, err = strconv.ParseBool(skipSslValidation)
if err != nil {
return consoleConfig, fmt.Errorf("Invalid value for Skip SSL Validation property %v", err)
}

err = p.SaveConsoleConfig(consoleConfig, consoleRepo)
if err != nil {
return consoleConfig, fmt.Errorf("Failed to save config due to: %v", err)
Expand Down

0 comments on commit 4ccfb34

Please sign in to comment.