fix: fix settings handling

This commit is contained in:
Jonas Juselius
2024-11-20 15:15:29 +01:00
parent 4e228d441c
commit 19303875b4
2 changed files with 37 additions and 24 deletions

10
scripts/run_lgtm.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
docker ps 2>&1 | grep -q zipkin
if [ $? = 0 ]; then
echo "Please stop the running Zipkin Docker instance and try again"
exit 1
fi
exec docker run -p 3000:3000 -p 4317:4317 -p 4318:4318 -p 9411:9411 --rm --name otel-lgtm -ti otel-lgtm:local

View File

@@ -18,7 +18,6 @@ let tryGetEnv =
let private secretStore = tryGetEnv "SECRETSTORE" |> Option.defaultValue "secretstore"
let private keyVault = tryGetEnv "KEYVAULT" |> Option.defaultValue "azure-keyvault"
let private configStore = tryGetEnv "CONFIGSTORE" |> Option.defaultValue "configstore"
let private appSecrets = $"{settings.sso.authDomain}-{settings.appName}-env"
let private settings =
let settings =
@@ -37,6 +36,29 @@ let private settings =
|> Option.defaultValue settings.plainAuthUsers
{ settings with plainAuthUsers = users }
let private isInt n =
try
int n |> ignore
true
with _ -> false
let appEnv, appName =
tryGetEnv "APP_NAME"
|> Option.defaultValue settings.appName
|> fun s -> s.Split '-'
|> fun y ->
match y.Length with
| 1 -> "devel", y[0]
| 2 when isInt y[1] -> "devel", y[0]
| 2 -> y[0], y[1]
| 3 when isInt y[2] -> y[0], y[1]
| 3 -> "devel", y[0]
| _ ->
let x = y[.. (y.Length - 3)]
String.concat "-" x[.. (x.Length - 2)], Array.last x
let private appSecrets = $"{settings.sso.authDomain}-{appName}-env"
let private appNamespace =
tryGetEnv "APP_NAMESPACE"
|> Option.defaultValue settings.appNamespace
@@ -80,9 +102,6 @@ let private configureEnv () =
let! oidc = Dictionary.tryGetValue "OIDC_CLIENT_SECRET" secret
System.Environment.SetEnvironmentVariable("OIDC_CLIENT_SECRET", oidc)
let! archmaester = Dictionary.tryGetValue "ARCHMAESTER_AUTH" secret
System.Environment.SetEnvironmentVariable("ARCHMAESTER_AUTH", archmaester)
let! archmaester = Dictionary.tryGetValue "DATA_PROTECTION_TOKEN" secret
System.Environment.SetEnvironmentVariable("DATA_PROTECTION_TOKEN", archmaester)
} |> ignore
@@ -111,8 +130,12 @@ let private configureEnv () =
| None ->
printfn "<<< Configuring runtime environment >>>"
setAzureEnv ()
printfn " * Azure env"
setRedisEnv ()
printfn " * Redis env"
setAppEnv ()
printfn " * App env"
printfn "<<< Done configuring runtime environment >>>"
let loglevel =
match tryGetEnv "LOG_LEVEL" with
@@ -155,31 +178,11 @@ let private redisConnString =
| Some redis -> redis
| None -> settings.redis)
let private isInt n =
try
int n |> ignore
true
with _ -> false
let appsettings =
configureEnv ()
let oidcClientSecret =
tryGetEnv "OIDC_CLIENT_SECRET"
|> Option.defaultValue settings.oidc.clientSecret
let appEnv, appName =
tryGetEnv "APP_NAME"
|> Option.defaultValue "atlantis"
|> fun s -> s.Split '-'
|> fun y ->
match y.Length with
| 1 -> "devel", y[0]
| 2 when isInt y[1] -> "devel", y[0]
| 2 -> y[0], y[1]
| 3 when isInt y[2] -> y[0], y[1]
| 3 -> "devel", y[0]
| _ ->
let x = y[.. (y.Length - 3)]
String.concat "-" x[.. (x.Length - 2)], Array.last x
let appVersion =
tryGetEnv "APP_VERSION"
|> Option.defaultValue (