Skip to content

Commit

Permalink
refactor profile creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-Ayres committed Dec 13, 2023
1 parent 2b7c801 commit 100a266
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions create-k8s-chained-sessions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# instance beforehand.

# global variables
declare PROFILE_ID
declare REGION='us-east-1'

###### FUNCTIONS ######
Expand Down Expand Up @@ -44,13 +43,13 @@ function createLeappSession {
leapp session stop --sessionId "$parent_session_id"
# create a named profile per account so they can be used simultaneously
echo "creating new profile"
createLeappProfile "$parent_session_name"
profile_id=$(createLeappProfile "$parent_session_name")
echo "creating new session"
# create new chained leapp session from parent
leapp session add --providerType aws --sessionType awsIamRoleChained \
--sessionName "$chained_session_name" --region "$REGION" \
--roleArn "$role_arn" --parentSessionId "$parent_session_id" \
--profileId "$PROFILE_ID"
--profileId "$profile_id"

else
echo "existing session found"
Expand All @@ -73,8 +72,13 @@ function createLeappProfile {
# match e.g. both `kubectl-access-role-panorama-k8s-playground` and
# `kubectl-access-role-panorama-k8s-playground-2`.
profile_name="kubectl-access-role-${1}"
profile_id=$(leapp profile list -x --output json --filter="Profile Name=^${profile_name}$" | jq -r '.[0].id')
if [[ -n "${profile_id}" ]]; then
echo "${profile_id}"
return
fi
leapp profile create --profileName "$profile_name"
PROFILE_ID=$(leapp profile list -x --output json --filter="Profile Name=^${profile_name}$" | jq -r '.[0].id')
leapp profile list -x --output json --filter="Profile Name=^${profile_name}$" | jq -r '.[0].id'
}
#
###### END FUNCTIONS ######
Expand Down

0 comments on commit 100a266

Please sign in to comment.