Skip to content

Commit

Permalink
cse idp script split
Browse files Browse the repository at this point in the history
Moved the generation of the cognito config to a separate
script file that can be called during the site creation.

Change-Id: I33e2ecd2bf40ce2cb3682b63a45f49c501b3f7d1
  • Loading branch information
rene-slowenski-checkmk committed Nov 22, 2023
1 parent 2d1ae03 commit b6dd983
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
16 changes: 16 additions & 0 deletions scripts/create_cognito_config_cse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Generate and print the cognito idp config for the SaaS edition

IDP_URL="${1-http://localhost:5551}"
BASE_URL="${2:-http://localhost:5000}"
CLIENT_ID="${3:-notused}"
TENANT_ID="${4:-123tenant567}"

# Create JSON object
printf '{\n "%s":"%s",\n "%s":"%s",\n "%s":"%s",\n "%s":"%s",\n "%s":"%s",\n "%s":"%s"\n}' \
"client_id" "$CLIENT_ID" \
"base_url" "$BASE_URL" \
"saas_api_url" "$IDP_URL" \
"tenant_id" "$TENANT_ID" \
"logout_url" "$IDP_URL/logout" \
"well_known" "$IDP_URL/.well-known/openid-configuration"
42 changes: 12 additions & 30 deletions scripts/create_test_idp_cse.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
#!/bin/bash
#
#!/usr/bin/env bash
# Launch a cognito idp for the SaaS edition
set -e

REPO_PATH="$(dirname "$(dirname "$(realpath "$0")")")"

# acquire sudo to run to change the configuration
sudo true

configure_cognito() {
idp_url="$1"
checkmk_port="$2"

client_id="notused"
base_url="http://localhost:$checkmk_port"
well_known="$idp_url/.well-known/openid-configuration"

# Create JSON object
JSON=$(printf '{\n "%s":"%s",\n "%s":"%s",\n "%s":"%s",\n "%s":"%s",\n "%s":"%s",\n "%s":"%s"\n}' \
"client_id" "$client_id" \
"base_url" "$base_url" \
"saas_api_url" "$idp_url" \
"tenant_id" "123tenant567" \
"logout_url" "$idp_url/logout" \
"well_known" "$well_known")

# Write JSON object to file
sudo mkdir -p /etc/cse
echo "$JSON" | sudo tee /etc/cse/cognito-cmk.json >/dev/null
}

PORT=5551
# URL under which we can reach the openid provider
# PORT and URL under which we can reach the openid provider
PORT=${1:-5551}
export URL="http://localhost:${PORT}"

# checkmk uses port 5000 by default
configure_cognito $URL 5000
# URL of the checkmk instance; checkmk uses port 5000 by default
CMK_URL="http://localhost:${2:-5000}"

# Write cognito configuration file
sudo mkdir -p /etc/cse
"$(dirname "$0")/create_cognito_config_cse.sh" "${URL}" "${CMK_URL}" | sudo tee /etc/cse/cognito-cmk.json >/dev/null

export PYTHONPATH="${REPO_PATH}/tests/testlib"
"$REPO_PATH"/scripts/run-pipenv run uvicorn cse.openid_oauth_provider:application --port "$PORT"
export PYTHONPATH="${REPO_PATH}:${REPO_PATH}/tests/testlib"
"${REPO_PATH}/scripts/run-pipenv" run uvicorn cse.openid_oauth_provider:application --port "${PORT}"

0 comments on commit b6dd983

Please sign in to comment.