|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Test script to check IDP update functionality |
| 4 | +CSDB_NAMESPACE=$1 |
| 5 | + |
| 6 | +if [[ -z $CSDB_NAMESPACE ]]; then |
| 7 | + echo "No namespace provided. please provide the namespace as an argument." |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | + |
| 11 | +echo "Getting primary PostgreSQL pod..." |
| 12 | +CNPG_PRIMARY_POD=$(oc get cluster.postgresql.k8s.enterprisedb.io common-service-db -o jsonpath="{.status.currentPrimary}" -n $CSDB_NAMESPACE) |
| 13 | + |
| 14 | +if [[ -z $CNPG_PRIMARY_POD ]]; then |
| 15 | + echo "Error: Could not find primary PostgreSQL pod" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +echo "Primary pod: $CNPG_PRIMARY_POD" |
| 20 | + |
| 21 | +echo "Checking if account_iam database exists..." |
| 22 | +ACCOUNT_IAM_EXISTS=$(oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -c "\list" | grep "account_iam" || echo False) |
| 23 | + |
| 24 | +if [[ $ACCOUNT_IAM_EXISTS == "False" ]]; then |
| 25 | + echo "account_iam database not found. Creating test data..." |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +echo "Current IDP configuration BEFORE update:" |
| 30 | +oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c " |
| 31 | + SELECT uid, realm, idp, modified_ts |
| 32 | + FROM accountiam.idp_config |
| 33 | + ORDER BY modified_ts DESC; |
| 34 | +" |
| 35 | + |
| 36 | +echo "Getting cluster domain..." |
| 37 | +CLUSTER_DOMAIN=$(oc get route console -n openshift-console -o jsonpath='{.spec.host}' | sed 's/^console-openshift-console\.//') |
| 38 | + |
| 39 | +if [[ -z $CLUSTER_DOMAIN ]]; then |
| 40 | + echo "Warning: Could not determine cluster domain from console route, trying alternative method..." |
| 41 | + CLUSTER_DOMAIN=$(oc get ingress.config.openshift.io cluster -o jsonpath='{.spec.domain}') |
| 42 | +fi |
| 43 | + |
| 44 | +if [[ -z $CLUSTER_DOMAIN ]]; then |
| 45 | + echo "Error: Could not determine cluster domain. Using example.com for testing." |
| 46 | + CLUSTER_DOMAIN="example.com" |
| 47 | +fi |
| 48 | + |
| 49 | +echo "Detected cluster domain: $CLUSTER_DOMAIN" |
| 50 | + |
| 51 | +NEW_IDP_URL="https://cp-console.${CSDB_NAMESPACE}.${CLUSTER_DOMAIN}/idprovider/v1/auth" |
| 52 | +echo "New IDP URL will be: $NEW_IDP_URL" |
| 53 | + |
| 54 | +# Perform the update |
| 55 | +echo "Updating IDP configuration..." |
| 56 | +oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c " |
| 57 | + UPDATE accountiam.idp_config |
| 58 | + SET idp = '$NEW_IDP_URL', |
| 59 | + modified_ts = NOW() |
| 60 | + WHERE idp LIKE '%/idprovider/v1/%'; |
| 61 | +" |
| 62 | + |
| 63 | +echo "IDP configuration AFTER update:" |
| 64 | +oc -n $CSDB_NAMESPACE exec -t $CNPG_PRIMARY_POD -c postgres -- psql -U postgres -d account_iam -c " |
| 65 | + SELECT uid, realm, idp, modified_ts |
| 66 | + FROM accountiam.idp_config |
| 67 | + ORDER BY modified_ts DESC; |
| 68 | +" |
| 69 | + |
| 70 | +echo "Test completed!" |
0 commit comments