awslabs / aws-shell

An integrated shell for working with the AWS CLI.
Apache License 2.0
7.15k stars 770 forks source link

Add profile support #92

Closed jamesls closed 8 years ago

jamesls commented 8 years ago

This PR adds profile support:

Using the new argument:

$ aws-shell --profile prod

Using the dot command:

$ aws-shell
aws> .profile
Current shell profile: no profile configured
You can change profiles using: .profile profile-name
aws> .profile demo
Current shell profile changed to: demo
aws> .profile
Current shell profile: demo
aws> s3api list-buckets       # <---- will use the "demo" profile.  Also server side completion will use the "demo" profile

Because this is using the updated internal APIs from the server side completion fix, this PR is using server-side-fix as the base branch to make it easier to review.

donnemartin commented 8 years ago

Awesome, this will be a great addition. Couple questions:

$ aws-shell aws> .profile Current shell profile: no profile configured You can change profiles using: .profile profile-name

If the user doesn't specify a profile, should the default profile automatically be chosen? Or is that what is meant by "no profile configured"?

Curious what the user sees if an invalid profile is specified. Let's say 'default' and 'prod' are available but 'beta' is chosen.

I'm a little short on time this morning, lots of PRs to review :) usually I'd do more testing myself.

:shipit:

jamesls commented 8 years ago

If the user doesn't specify a profile, should the default profile automatically be chosen? Or is that what is meant by "no profile configured"?

If no profile is specified in the shell (via aws-shell --profile or .profile), then we'll fall back to the logic in the AWS CLI, which will first look at AWS_DEFAULT_PROFILE before falling back to the default profile if it exists. If there's no default profile we'll start looking at other credential providers for credentials.

Curious what the user sees if an invalid profile is specified. Let's say 'default' and 'prod' are available but 'beta' is chosen.

There's no validation at the time of switching profiles that the profile does not exist, you'll just get an error when you try to make a CLI call. The previous PR fixes the issue with crashing if we can't create a client, which would also cover this case. I think it'd be cool to autocomplete profile names in the future.

Right now, here's the behavior:

$ aws-shell
aws> .profile badprofile
Current shell profile changed to: badprofile
aws> s3 ls

The config profile (badprofile) could not be found
aws> iam delete-user --user-name        #<--- no autocomplete happens because we can't create a client for the "badprofile" profile
jamesls commented 8 years ago

Merged via 65d4917