Skip to content

Commit

Permalink
Allow whitespaces before/after equal sign
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Oct 11, 2022
1 parent fbd8786 commit 112e1f1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions aws-export-assume-profile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ set -o pipefail
###
###
###
APP_VERSION="v0.2"
APP_DATE="2020-10-08"
APP_VERSION="v0.3"
APP_DATE="2022-10-11"
APP_NAME="aws-export-assume-profile"


Expand Down Expand Up @@ -71,6 +71,22 @@ function json_get_key {
}


###
### Remove leading and trailing whitespace
###
### @param str String to trim
### @outputs Trimmed string
###
function trim {
local var="${1}"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "${var}"
}


###
### Extract AWS profile information
###
Expand Down Expand Up @@ -109,18 +125,22 @@ function extract_aws_profile {
# Get RoleArn
if [[ "${line}" =~ ^[[:space:]]*role_arn[[:space:]]*= ]]; then
ROLE_ARN="${line#*=}"
ROLE_ARN="$( trim "${ROLE_ARN}" )"
fi
# Get Source Profile
if [[ "${line}" =~ ^[[:space:]]*source_profile[[:space:]]*= ]]; then
SOURCE_PROFILE="${line#*=}"
SOURCE_PROFILE="$( trim "${SOURCE_PROFILE}" )"
fi
# Get Region
if [[ "${line}" =~ ^[[:space:]]*region[[:space:]]*= ]]; then
REGION="${line#*=}"
REGION="$( trim "${REGION}" )"
fi
# Get Login duration
if [[ "${line}" =~ ^[[:space:]]*duration_seconds[[:space:]]*= ]]; then
DURATION_SECONDS="${line#*=}"
DURATION_SECONDS="$( trim "${DURATION_SECONDS}" )"
fi
fi
done < "${config}"
Expand Down

0 comments on commit 112e1f1

Please sign in to comment.