Skip to content
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

feat: AWS_PROFILE env var support #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

bilalq
Copy link

@bilalq bilalq commented Aug 26, 2023

Description of changes:

Motivation

This CLI tool previously defaulted to using the default AWS profile and allowed the user to override that by passing a --profile option.

However, the AWS CLI and other tools will respect the AWS_PROFILE environment variable as well. This can be observed in documentation here:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-using-profiles

To bring consistency with other tools and workflows and convenience for existing users of the environment variable, support for that env variable would be appreciated.

Implementation

Commander natively supports using environment variables as inputs for options. An example can be seen here:
https://github.com/tj/commander.js/blob/master/examples/options-env.js

However, the fluent .option method doesn't support setting that configuration. An instance of the Option class has to be created to set that. The diff required here is fairly small:

-  .option("-p, --profile <profile>", "AWS profile to use", "default")
+  .addOption(new program.Option("-p, --profile <profile>", "AWS profile to use").default("default").env("AWS_PROFILE"))

Impact

This change updates the command definition to support a value from that environment variable as well. The order of precedence is as follows:

  1. Use the value explicitly provided via the --profile option.
  2. If the option was not passed, use the value of AWS_PROFILE environment variable.
  3. If AWS_PROFILE is not set, use "default"

If the user does not have the AWS_PROFILE environment variable set, then there is no user-facing impact or change at all.

After this change, this is what the help output looks like:

$ xray t -h
Usage: xray traces|t [options]

Find and render trace timeline. All parameters are optional.

Options:
  -s, --start <start>               Start time (minutes ago) (default: 5)
  -e, --end <end>                   End time (minutes ago) (default: 0)
  -as, --absolute-start <start>     Start time (ISO 8601)
  -ae, --absolute-end <end>         End time (ISO 8601)
  -f, --filter-expression <filter>  Filter expression. Must be inside double or single quotes ("/')
  -p, --profile <profile>           AWS profile to use (default: "default", env: AWS_PROFILE)
  -h, --help                        display help for command

Checklist

  • Update tests
  • Update docs

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

No test setup exists in the package, so tests were not added.

Motivation
----------

This CLI tool previously defaulted to using the `default` AWS profile
and allowed the user to override that by passing a `--profile` option.

However, the AWS CLI and other tools will respect the `AWS_PROFILE`
environment variable as well. This can be observed in documentation
here:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-using-profiles

To bring consistency with other tools and workflows and convenience for
existing users of the environment variable, support for that env
variable would be appreciated.

Implementation
--------------

Commander natively supports using environment variables as inputs for
options. An example can be seen here:
https://github.com/tj/commander.js/blob/master/examples/options-env.js

However, the fluent `.option` method doesn't support setting that
configuration. An instance of the `Option` class has to be created to
set that. The diff required here is fairly small:

```diff
-  .option("-p, --profile <profile>", "AWS profile to use", "default")
+  .addOption(new program.Option("-p, --profile <profile>", "AWS profile to use").default("default").env("AWS_PROFILE"))
```

Impact
------

This change updates the command definition to support a value from that
environment variable as well. The order of precedence is as follows:

1. Use the value explicitly provided via the `--profile` option.
2. If the option was not passed, use the value of `AWS_PROFILE`
   environment variable.
3. If `AWS_PROFILE` is not set, use `"default"`

If the user does not have the `AWS_PROFILE` environment variable set,
then there is no user-facing impact or change at all.

After this change, this is what the help output looks like:

```
$ xray t -h
Usage: xray traces|t [options]

Find and render trace timeline. All parameters are optional.

Options:
  -s, --start <start>               Start time (minutes ago) (default: 5)
  -e, --end <end>                   End time (minutes ago) (default: 0)
  -as, --absolute-start <start>     Start time (ISO 8601)
  -ae, --absolute-end <end>         End time (ISO 8601)
  -f, --filter-expression <filter>  Filter expression. Must be inside double or single quotes ("/')
  -p, --profile <profile>           AWS profile to use (default: "default", env: AWS_PROFILE)
  -h, --help                        display help for command
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant