fixed backwards compatibility with multiple auths

This commit is contained in:
jasquat 2023-11-09 11:09:11 -05:00
parent 155f07d723
commit b8cfa4fd3c
2 changed files with 37 additions and 21 deletions

View File

@ -35,18 +35,25 @@ elif [[ "$process_model_dir" == "localopenid" ]]; then
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_id="spiffworkflow-backend" export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_id="spiffworkflow-backend"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_secret="JXeQExm0JhQPLumgHtIIqf52bDalHz0q" export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_secret="JXeQExm0JhQPLumgHtIIqf52bDalHz0q"
export SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME="example.yml" export SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME="example.yml"
else
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__identifier="keycloak_internal"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__label="I am a Core Contributor"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__uri="http://localhost:7002/realms/spiffworkflow"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_id="spiffworkflow-backend"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_secret="JXeQExm0JhQPLumgHtIIqf52bDalHz0q"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__identifier="openid" # else # uncomment to test multiple auths
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__label="I am a vendor" # export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__identifier="keycloak_internal"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__uri="http://localhost:$port/openid" # export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__label="I am a Core Contributor"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__client_id="spiffworkflow-backend" # export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__uri="http://localhost:7002/realms/spiffworkflow"
export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__client_secret="JXeQExm0JhQPLumgHtIIqf52bDalHz0q" # export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_id="spiffworkflow-backend"
# export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__client_secret="JXeQExm0JhQPLumgHtIIqf52bDalHz0q"
#
# export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__identifier="openid"
# export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__label="I am a vendor"
# export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__uri="http://localhost:$port/openid"
# export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__client_id="spiffworkflow-backend"
# export SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__client_secret="JXeQExm0JhQPLumgHtIIqf52bDalHz0q"
# else # uncomment to test specfied
# export SPIFFWORKFLOW_BACKEND_OPEN_ID_SERVER_URL="http://localhost:7002/realms/spiffworkflow"
# export SPIFFWORKFLOW_BACKEND_OPEN_ID_CLIENT_ID="spiffworkflow-backend"
# export SPIFFWORKFLOW_BACKEND_OPEN_ID_CLIENT_SECRET_KEY="JXeQExm0JhQPLumgHtIIqf52bDalHz0q"
fi fi
if [[ -z "${SPIFFWORKFLOW_BACKEND_ENV:-}" ]]; then if [[ -z "${SPIFFWORKFLOW_BACKEND_ENV:-}" ]]; then

View File

@ -1,5 +1,6 @@
import re import re
from os import environ from os import environ
from typing import Any
from spiffworkflow_backend.config.normalized_environment import normalized_environment from spiffworkflow_backend.config.normalized_environment import normalized_environment
@ -8,7 +9,7 @@ from spiffworkflow_backend.config.normalized_environment import normalized_envir
# is a benefit of the status quo and having them all in this file explicitly. # is a benefit of the status quo and having them all in this file explicitly.
def config_from_env(variable_name: str, *, default: str | bool | int | None = None) -> None: def config_from_env(variable_name: str, *, default: str | bool | int | None = None) -> Any:
value_from_env: str | None = environ.get(variable_name) value_from_env: str | None = environ.get(variable_name)
if value_from_env == "": if value_from_env == "":
value_from_env = None value_from_env = None
@ -30,6 +31,7 @@ def config_from_env(variable_name: str, *, default: str | bool | int | None = No
# the value set in the variable here. It is better to set the variables like # the value set in the variable here. It is better to set the variables like
# normal in them so they can take effect. # normal in them so they can take effect.
globals()[variable_name] = value_to_return globals()[variable_name] = value_to_return
return value_to_return
configs_with_structures = normalized_environment(environ) configs_with_structures = normalized_environment(environ)
@ -90,6 +92,13 @@ config_from_env("SPIFFWORKFLOW_BACKEND_OPEN_ID_TENANT_SPECIFIC_FIELDS")
# server hosted by spiffworkflow-backend # server hosted by spiffworkflow-backend
if "SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS" in configs_with_structures: if "SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS" in configs_with_structures:
SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS = configs_with_structures["SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS"] SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS = configs_with_structures["SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS"]
else:
# do this for now for backwards compatibility
url_config = config_from_env("SPIFFWORKFLOW_BACKEND_OPEN_ID_SERVER_URL")
if url_config is not None:
SPIFFWORKFLOW_BACKEND_OPEN_ID_SERVER_URL = url_config
config_from_env("SPIFFWORKFLOW_BACKEND_OPEN_ID_CLIENT_ID")
config_from_env("SPIFFWORKFLOW_BACKEND_OPEN_ID_CLIENT_SECRET_KEY")
else: else:
SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS = [ SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS = [
{ {