-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,6 +414,14 @@ while [ "$#" != 0 ]; do | |
REQUEST_METHOD="$1" | ||
shift | ||
;; | ||
--json ) | ||
shift | ||
OUTPUT_FORMAT="application/json" | ||
;; | ||
--xml ) | ||
shift | ||
OUTPUT_FORMAT="application/xml" | ||
;; | ||
-H | --header ) | ||
shift | ||
REQUEST_HEADERS=$(printf "%s\n%s" "$REQUEST_HEADERS" "$1") | ||
|
@@ -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 commentThe 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 |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Suggest to move body of this condition into function |
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. Mac needs 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. |
||
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 commentThe 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. |
||
AWS_SECRET_ACCESS_KEY=$(get_cred_value "$block" aws_secret_access_key) | ||
AWS_SESSION_TOKEN=$(get_cred_value "$block" aws_session_token) | ||
AWS_DEFAULT_REGION=$(get_cred_value "$block" region) | ||
output=$(get_cred_value "$block" output) | ||
if [ -n "$output" ]; then | ||
OUTPUT_FORMAT=application/$output | ||
fi | ||
fi | ||
|
||
# check mandatory environment variables | ||
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then | ||
|
@@ -617,6 +641,6 @@ echo "$CURL_ARGS" \ | |
| xargs -0 curl --request "$REQUEST_METHOD" \ | ||
--header "$AUTHORIZATION_HEADER" \ | ||
--header "User-Agent:" \ | ||
--header "Accept:" \ | ||
--header "Accept: $OUTPUT_FORMAT" \ | ||
--header "Content-Type:" \ | ||
--data-binary "$REQUEST_PAYLOAD" |
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