package config

import (
	"os"
	"strings"
)

var (
	BridgePort              = ":" + getEnvVar("BRIDGE_PORT", "3001")
	AssistedApiUrl          = getEnvUrlVar("AIUI_APP_API_URL", "http://localhost:8090")
	ApiInsecure             = getEnvVar("API_INSECURE_SKIP_VERIFY", "false")
	TlsKeyPath              = getEnvVar("TLS_KEY", "")
	TlsCertPath             = getEnvVar("TLS_CERT", "")
	UserAuthToken           = getEnvVar("USER_AUTH_TOKEN", "")
	PullSecretManifestPath  = getEnvVar("PULL_SECRET_MANIFEST_PATH", "/etc/assisted/manifests/pull-secret.yaml")
)

func getEnvUrlVar(key string, defaultValue string) string {
	urlValue := getEnvVar(key, defaultValue)
	return strings.TrimSuffix(urlValue, "/")
}

func getEnvVar(key string, defaultValue string) string {
	val, ok := os.LookupEnv(key)
	if !ok {
		return defaultValue
	}
	return val
}
