-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for AWS_PROFILE and --json and --xml options #5
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contribution. Unfortunately, this PR needs some adjustments to be merged. The main concern is that credentials parser implemented here is picky to syntax, it should not be relying on empty lines, specific number of spaces around parameters etc.
|
||
if [ -n "$AWS_PROFILE" ] && [ -z "$AWS_ACCESS_KEY_ID" ]; then | ||
# this can work with AWS SSO based connections | ||
block=$(sed -n '/\['$AWS_PROFILE'/,/^$/p' ~/.aws/credentials) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mac needs gsed
, there is SED_CMD env variable that is populated on mac with gsed that you can use instead of referencing to sed
.
There is missing closing \]
.
Selecting lines from section start to first empty line likely is not like aws cli parses this file. Likely section end condition is one of 1) start of new section 2) end of file. This regexp need a fix.
@@ -499,6 +507,22 @@ fi | |||
if [ "$EC2_CREDS" = 1 ]; then | |||
ec2_import_creds | |||
fi | |||
get_cred_value() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to name it as ini_get_value, please assign named local variables for $1 and $2, format it similar to other functions in this file and move up to function.
I guess credentials file can have zero or more spaces around =
sign and this code works just for one specific scenario. Suggest to adjust syntax to tolerate extraneous spaces around equal sign, also, tolerate if there are no any spaces.
if [ -n "$AWS_PROFILE" ] && [ -z "$AWS_ACCESS_KEY_ID" ]; then | ||
# this can work with AWS SSO based connections | ||
block=$(sed -n '/\['$AWS_PROFILE'/,/^$/p' ~/.aws/credentials) | ||
AWS_ACCESS_KEY_ID=$(get_cred_value "$block" aws_access_key_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code doesn't handle situation when profile doesn't have values for parameters. It blindly overwrites context with what it is profile, but if profile has no values and values were passed in script in alternative way, then these values will be zeroed.
echo "$1" | grep "$2 =" | cut -d ' ' -f 3- | ||
} | ||
|
||
if [ -n "$AWS_PROFILE" ] && [ -z "$AWS_ACCESS_KEY_ID" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to move body of this condition into function profile_import_creds
that will have profile name as parameter
@@ -43,7 +43,7 @@ Set AWS credentials and region using standard AWS CLI environment variables: | |||
- `AWS_SESSION_TOKEN` - temporary token received from STS or from EC2 metadata | |||
- `AWS_DEFAULT_REGION` - AWS default region, in case if region is not provided | |||
in URL or as command line argument `--region`. | |||
|
|||
- `AWS_PROFILE` - AWS_PROFILE, will read the above and default format from ~/.aws/credentials |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wrap ~/.aws/credentials as ~/.aws/credentials
nit: extraneous AWS_PROFILE
No description provided.