Skip to content

Commit

Permalink
apiserver credential env support
Browse files Browse the repository at this point in the history
Signed-off-by: greg pereira <[email protected]>
  • Loading branch information
Gregory-Pereira committed May 19, 2024
1 parent 20796bb commit c065a22
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ui/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ PRECHECK_ENDPOINT=
TLS_CLIENT_CERT_PATH=
TLS_CLIENT_KEY_PATH=
TLS_SERVER_CA_CERT_PATH=
# Note, you cannot set TLS_INSECURE in this .env file, you have to pass it to the apiserver as a CLI arg
# Note, you cannot set TLS_INSECURE in this .env file, you have to pass it to the apiserver as a CLI arg

# API creds variables
API_USER=
API_PASS=
27 changes: 25 additions & 2 deletions ui/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,15 @@ func main() {
tlsServerCaCertPath := pflag.String("tls-server-ca-cert", "$HOME/server-ca-crt.pem2", "Path to the TLS server CA certificate. Defaults to 'server-ca-crt.pem2'")
pflag.Parse()

/* Support env population with priority being:
/* ENV support, most variabls take 3 options, with the following priority:
1) flag
2) env
3) acceptable defaults
*/

// NOTE: not all variables support all 3 methods, in which case they will be documented via comments.
// With no comment, assume they support all 3.

// Precheck endpoint
HOME := os.Getenv("HOME")
if *preCheckEndpointURL == "" {
Expand All @@ -542,7 +545,8 @@ func main() {
*preCheckEndpointURL = localEndpoint
}
}
// TLS certPath

// TLS configurations
if *tlsClientCertPath == "" {
tlsClientCertPathEnvValue := os.Getenv("TLS_CLIENT_CERT_PATH")
if tlsClientCertPathEnvValue != "" {
Expand All @@ -560,8 +564,27 @@ func main() {
*tlsClientKeyPath = fmt.Sprintf("%s/client-tls-key.pem2", HOME)
}
}

// NOTE: TLSInsecure not settable by env, just apiserver cli flag or defaults to false

/* API credentials
API creds support only apiserver cli flag or env, no default values.
*/
// API user
if *apiUser == "" {
apiUserEnvValue := os.Getenv("API_USER")
if apiUserEnvValue != "" {
*apiUser = apiUserEnvValue
}
}
// API pass
if *apiPass == "" {
apiPassEnvValue := os.Getenv("API_PASS")
if apiPassEnvValue != "" {
*apiPass = apiPassEnvValue
}
}

logger := setupLogger(*debugFlag)
defer logger.Sync()

Expand Down

0 comments on commit c065a22

Please sign in to comment.