From 100a266a9e11673931c2f04186caef74c41039af Mon Sep 17 00:00:00 2001 From: Patrick Ayres Date: Wed, 13 Dec 2023 11:57:15 -0500 Subject: [PATCH] refactor profile creation --- create-k8s-chained-sessions.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/create-k8s-chained-sessions.sh b/create-k8s-chained-sessions.sh index cb5ecaa..da02fcd 100755 --- a/create-k8s-chained-sessions.sh +++ b/create-k8s-chained-sessions.sh @@ -7,7 +7,6 @@ # instance beforehand. # global variables -declare PROFILE_ID declare REGION='us-east-1' ###### FUNCTIONS ###### @@ -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" @@ -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 ######