@@ -4,6 +4,9 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
44# shellcheck disable=SC1090,SC1091
55source " $( python3 -c ' import os, sys; print(os.path.realpath(sys.argv[1]))' " $SCRIPT_DIR " /../../test.env) "
66
7+ # shellcheck disable=SC1091
8+ source " ${SCRIPT_DIR} /common.sh"
9+
710export TMP_DIR WORKDIR
811
912POPULATION_CONCURRENCY=${POPULATION_CONCURRENCY:- 10}
@@ -19,7 +22,7 @@ COOKIE="$TMP_DIR/cookie.jar"
1922
2023keycloak_url () {
2124 f=" $TMP_DIR /keycloak.url"
22- if command -v flock > /dev/null 2>&1 ; then
25+ if command -v flock > /dev/null 2>&1 ; then
2326 exec 4> " $kc_lockfile "
2427 flock 4 || {
2528 echo " Failed to acquire lock"
@@ -30,7 +33,7 @@ keycloak_url() {
3033 echo -n " https://$( oc get routes keycloak -n " ${RHDH_NAMESPACE} " -o jsonpath=' {.spec.host}' ) " > " $f "
3134 fi
3235 flock -u 4
33- elif command -v shlock > /dev/null 2>&1 ; then
36+ elif command -v shlock > /dev/null 2>&1 ; then
3437 LOCKFILE=" $TMP_DIR /kc_lockfile"
3538 trap ' rm -f "$LOCKFILE"' EXIT
3639
@@ -148,8 +151,8 @@ clone_and_upload() {
148151
149152 files=()
150153 while IFS= read -r line; do
151- files+=(" $line " )
152- done <<< " $out"
154+ files+=(" $line " )
155+ done <<< " $out"
153156
154157 for filename in " ${files[@]} " ; do
155158 cp -vf " $filename " " $( basename " $filename " ) "
@@ -224,7 +227,7 @@ get_group_id_by_name() {
224227 response=$( curl -s -k --location --request GET " $( keycloak_url) /auth/admin/realms/backstage/groups?search=${group_name} " \
225228 -H ' Content-Type: application/json' \
226229 -H " Authorization: Bearer $token " 2>&1 )
227-
230+
228231 if [[ " $response " == " [" * ]] && [[ " $response " == * " ]" ]] && [[ " $response " != " []" ]]; then
229232 group_id=$( echo " $response " | jq -r --stream --arg name " $group_name " '
230233 [., inputs] |
@@ -255,19 +258,19 @@ assign_parent_group() {
255258 max_attempts=5
256259 attempt=1
257260 parent_id=" "
258- while (( attempt <= max_attempts )) ; do
261+ while (( attempt <= max_attempts)) ; do
259262 parent_id=" $( get_group_id_by_name " $parent_group_name " ) "
260263 [ -n " $parent_id " ] && [ " $parent_id " != " null" ] && break
261264 log_warn " Parent $parent_group_name not found (attempt $attempt ). Waiting..." >> " $TMP_DIR /create_group.log"
262- (( attempt++ )) ;
265+ (( attempt++ ))
263266 done
264267 if [ -z " $parent_id " ] || [ " $parent_id " = " null" ]; then
265268 log_error " Parent $parent_group_name missing after $max_attempts attempts; cannot create $child_name " 2>&1 | tee -a " $TMP_DIR /create_group.log"
266269 return 1
267270 fi
268271
269272 attempt=1
270- while (( attempt <= max_attempts )) ; do
273+ while (( attempt <= max_attempts)) ; do
271274 token=$( get_token)
272275 response=" $( curl -s -k --location --request POST " $( keycloak_url) /auth/admin/realms/backstage/groups/${parent_id} /children" \
273276 -H ' Content-Type: application/json' -H " Authorization: Bearer $token " \
@@ -277,7 +280,7 @@ assign_parent_group() {
277280 return 0
278281 fi
279282 log_warn " Unable to create child $child_name under $parent_group_name at attempt $attempt . [$response ]" >> " $TMP_DIR /create_group.log"
280- (( attempt++ )) ;
283+ (( attempt++ ))
281284 done
282285 log_error " Unable to create child $child_name under $parent_group_name in $max_attempts attempts" 2>&1 | tee -a " $TMP_DIR /create_group.log"
283286 return 1
@@ -304,7 +307,7 @@ create_group() {
304307 return
305308 fi
306309 log_warn " Unable to create $groupname at attempt $attempt . [$response ]" >> " $TMP_DIR /create_group.log"
307- (( attempt++ )) ;
310+ (( attempt++ ))
308311 done
309312 log_error " Unable to create the $groupname group in $max_attempts attempts, giving up!" 2>&1 | tee -a " $TMP_DIR /create_group.log"
310313 return 1
@@ -327,7 +330,7 @@ create_group() {
327330 return
328331 fi
329332 log_warn " Unable to create $groupname at attempt $attempt . [$response ]" >> " $TMP_DIR /create_group.log"
330- (( attempt++ )) ;
333+ (( attempt++ ))
331334 done
332335 log_error " Unable to create the $groupname group in $max_attempts attempts, giving up!" 2>&1 | tee -a " $TMP_DIR /create_group.log"
333336 return 1
@@ -405,7 +408,7 @@ create_groups() {
405408 [ " $N " -gt " $GROUP_COUNT " ] && N=" $GROUP_COUNT "
406409 seq 1 " $N " | xargs -P1 -I{} bash -lc " create_group \"\$ 1\" " _ {}
407410 if [ " $GROUP_COUNT " -gt " $N " ]; then
408- seq $(( N+ 1 )) " $GROUP_COUNT " | xargs -P" ${POPULATION_CONCURRENCY} " -I{} bash -lc " create_group \"\$ 1\" " _ {}
411+ seq $(( N + 1 )) " $GROUP_COUNT " | xargs -P" ${POPULATION_CONCURRENCY} " -I{} bash -lc " create_group \"\$ 1\" " _ {}
409412 fi
410413 else
411414 seq 1 " $GROUP_COUNT " | xargs -P" ${POPULATION_CONCURRENCY} " -I{} bash -lc " create_group \"\$ 1\" " _ {}
@@ -466,7 +469,7 @@ create_user() {
466469 done
467470
468471 if [[ $attempt -gt $max_attempts ]]; then
469- log_error " Unable to create the $username user in $max_attempts attempts, giving up!" 2>&1 | tee -a " $TMP_DIR /create_user.log"
472+ log_error " Unable to create the $username user in $max_attempts attempts, giving up!" 2>&1 | tee -a " $TMP_DIR /create_user.log"
470473 fi
471474}
472475
@@ -478,33 +481,6 @@ create_users() {
478481}
479482
480483token_lockfile=" $TMP_DIR /token.lockfile"
481- log () {
482- echo " {\" level\" :\" ${2:- info} \" ,\" ts\" :\" $( date -u -Ins) \" ,\" message\" :\" $1 \" }"
483- }
484-
485- log_info () {
486- log " $1 " " info"
487- }
488-
489- log_warn () {
490- log " $1 " " warn"
491- }
492-
493- log_error () {
494- log " $1 " " error"
495- }
496-
497- log_token () {
498- log " $1 " " $2 " >> " $TMP_DIR /get_token.log"
499- }
500-
501- log_token_info () {
502- log_token " $1 " " info"
503- }
504-
505- log_token_err () {
506- log_token " $1 " " error"
507- }
508484
509485keycloak_token () {
510486 curl -s -k " $( keycloak_url) /auth/realms/master/protocol/openid-connect/token" -d username=admin -d " password=$1 " -d ' grant_type=password' -d ' client_id=admin-cli' | jq -r " .expires_in_timestamp = $( python3 -c ' from datetime import datetime, timedelta; t_add=int(30); print(int((datetime.now() + timedelta(seconds=t_add)).timestamp()))' ) "
@@ -534,7 +510,7 @@ rhdh_token() {
534510 --data-urlencode " redirect_uri=${REDIRECT_URL} " \
535511 --data-urlencode " scope=openid email profile" \
536512 --data-urlencode " response_type=code" \
537- " $( keycloak_url) /auth/realms/$REALM /protocol/openid-connect/auth" 2>&1 | tee " $TMP_DIR /auth_url.log" | grep -oE ' action="[^"]+"' | grep -oE ' "[^"]+"' | tr -d ' "' )
513+ " $( keycloak_url) /auth/realms/$REALM /protocol/openid-connect/auth" 2>&1 | tee " $TMP_DIR /auth_url.log" | grep -oE ' action="[^"]+"' | grep -oE ' "[^"]+"' | tr -d ' "' )
538514
539515 execution=$( echo " $AUTH_URL " | grep -oE ' execution=[^&]+' | grep -oE ' [^=]+$' )
540516 tab_id=$( echo " $AUTH_URL " | grep -oE ' tab_id=[^&]+' | grep -oE ' [^=]+$' )
@@ -547,7 +523,7 @@ rhdh_token() {
547523 --data-urlencode " tab_id=${tab_id} " \
548524 --data-urlencode " execution=${execution} " \
549525 --write-out " %{redirect_url}" \
550- " $AUTHENTICATE_URL " 2>&1 | tee " $TMP_DIR /code_url.log" )
526+ " $AUTHENTICATE_URL " 2>&1 | tee " $TMP_DIR /code_url.log" )
551527
552528 code=$( echo " $CODE_URL " | grep -oE ' code=[^&]+' | grep -oE ' [^=]+$' )
553529 session_state=$( echo " $CODE_URL " | grep -oE ' session_state=[^&]+' | grep -oE ' [^=]+$' )
0 commit comments