Skip to content

Commit c03cb12

Browse files
committed
Updated with option to manually provide user OCID
1 parent 899f5a0 commit c03cb12

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

cloudbank/scripts/tasks/init-state-part1.sh

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,41 @@ while : ; do
6060
OCIR="${PROCESSED_RKEY}.ocir.io/${NS}/cloudbank/${TOK}"
6161
state_set '.lab.docker_registry |= $VAL' $OCIR
6262

63-
# requires user OCID
64-
state_set '.lab.ocid.user |= $VAL' $OCI_CS_USER_OCID
65-
66-
# requires username
67-
uNAME=$(cd $CB_STATE_DIR/tasks ; ./get-user-name.sh $OCI_CS_USER_OCID )
68-
state_set '.lab.username |= $VAL' $uNAME
69-
7063
# requires Fingerprint
7164
read -p "Enter user fingerprint to authenticate provisioning with: " fPRINTVAL
7265
state_set '.lab.apikey.fingerprint |= $VAL' $fPRINTVAL
7366

67+
# requires user OCID
68+
USE_ENV_VARIABLE=0
69+
echo "Retrieving user..."
70+
while : ; do
71+
72+
if [ $USE_ENV_VARIABLE -eq 0 ]; then
73+
UOCID=$OCI_CS_USER_OCID
74+
else
75+
read -p "Please enter your User OCID: " UOCID
76+
fi
77+
78+
# Check
79+
OUTPUT=$(oci iam user get --user-id $UOCID 2> /dev/null)
80+
# User found
81+
if [ $? -eq 0 ]; then
82+
echo "User found."
83+
break
84+
fi
85+
86+
echo ""
87+
echo "Error: User with OCID: $UOCID: NOT FOUND"
88+
echo "Error: This error is most likely caused by using a federated user and the OCID cannot be retrieved automatically"
89+
USE_ENV_VARIABLE=1
90+
91+
done
92+
93+
uNAME=$(cd $CB_STATE_DIR/tasks ; ./get-user-name.sh $UOCID )
94+
state_set '.lab.ocid.user |= $VAL' $UOCID
95+
state_set '.lab.username |= $VAL' $uNAME
96+
97+
7498
(cd $CB_STATE_DIR/tasks ; ./utils-confirm.sh) || break
7599
done
76100

0 commit comments

Comments
 (0)