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

Enable env var hints for --token #945

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

andersjanmyr
Copy link
Contributor

Example:

$ ./fastly list service --token $FASTLY<tab>
$FASTLY_ACCOUNT_DEV         $FASTLY_ACCOUNT_SALJA_PROD
$FASTLY_ACCOUNT_PROD        $FASTLY_ACCOUNT_SANDBOX
$FASTLY_ACCOUNT_SALJA_DEV

Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋🏻 @andersjanmyr thanks for opening this PR!

Implementation looks OK, I just have a few requests.

pkg/app/run.go Outdated Show resolved Hide resolved
pkg/app/run.go Outdated Show resolved Hide resolved
pkg/app/run.go Outdated
envVarCache = []string{}
for _, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2)
envVarCache = append(envVarCache, fmt.Sprintf("\\$%s", pair[0]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have concerns about Windows support, it would be good to see a test implemented for the env package that validates the logic will work for Windows users. Our CI runs the CLI test suite on all three major platforms: macOS, Linux and Windows so if the test passes on all three then we'll know the implementation is good.

Example: set some environment variables and see if this function returns back the expected list of variables.

On Windows, I believe, the way to reference an environment variable is %VAR_NAME% so I presume os.Environ() will normalize the output so it works across platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it probably needs some special treatment to handle Windows.

@Integralist
Copy link
Collaborator

@andersjanmyr out of interest, is there a reason you're using this approach rather than something like --profile (e.g. fastly service list --profile personal)?

@andersjanmyr
Copy link
Contributor Author

@Integralist I was thinking of using profile locally, but we're using the same script to deploy both locally and on CI.
Something like this.

case "$env" in
  prod|stage)
    export FASTLY_API_KEY=$FASTLY_ACCOUNT_PROD
    ;;
  main)
    env='dev'
    export FASTLY_API_KEY=$FASTLY_ACCOUNT_DEV
    ;;
  *)
    export FASTLY_API_KEY=$FASTLY_ACCOUNT_DEV
    ;;
esac

Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than two minor change requests this looks good to me.

Thanks!

pkg/env/env.go Show resolved Hide resolved
pkg/env/env.go Outdated Show resolved Hide resolved
Moved envVars to env.Vars
Add test case for env.Vars
Add slices package for slices.Contains
Actually test something sensible
Check error value from Setenv since windows does not set values
Test with common variables instead
Mark tests on other platforms as skip
Document Vars method
@Integralist Integralist merged commit b3c7c43 into fastly:main Jun 5, 2023
@andersjanmyr andersjanmyr deleted the complete_variables_for_token branch June 5, 2023 12:44
@Integralist Integralist added the enhancement New feature or request label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants