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

Support AWS credential_process #72

Merged
merged 1 commit into from
May 24, 2024
Merged

Conversation

JesseStimpson
Copy link
Contributor

@JesseStimpson JesseStimpson commented May 22, 2024

AWS credentials file supports a configuration called credential_process that executes a program to retrieve credentials.

https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-sourcing-external.html

Comment on lines 146 to 156
CredsMap = maps:from_list(lists:filtermap(
fun
({<<"AccessKeyId">>, AKI}) -> {true, {<<"aws_access_key_id">>, AKI}};
({<<"SecretAccessKey">>, SAK}) -> {true, {<<"aws_secret_access_key">>, SAK}};
({<<"SessionToken">>, ST}) -> {true, {<<"aws_session_token">>, ST}};
(_) -> false
end, maps:to_list(CredResult))),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CredsMap = maps:from_list(lists:filtermap(
fun
({<<"AccessKeyId">>, AKI}) -> {true, {<<"aws_access_key_id">>, AKI}};
({<<"SecretAccessKey">>, SAK}) -> {true, {<<"aws_secret_access_key">>, SAK}};
({<<"SessionToken">>, ST}) -> {true, {<<"aws_session_token">>, ST}};
(_) -> false
end, maps:to_list(CredResult))),
Keys = [<<"AccessKeyId">>,<<"SecretAccessKey">>,<<"SessionToken">>],
CredsMap = maps:filter(fun(K, V) -> lists:member(K, Keys) end, CredResult),

@onno-vos-dev
Copy link
Member

onno-vos-dev commented May 22, 2024

First off, thank you for the PR! This is great! 🚀 🙏

Couple of initial comments:

  • Linting fails. (You have a line too long at line 149). My suggestion should sort that out and simplify things IMHO.
  • I'd really like to see a test which I'm perfectly fine in using some mecking 👍 But "something" to exercise this sort of codepath. Happy to help if you don't have time or aren't as comfortable fiddling around with our test SUITE 👍

@JesseStimpson
Copy link
Contributor Author

Ah sorry I tried to fix the lint before I saw your message. I'll take your approach, thanks!

I'll have a go at the test as well.

@JesseStimpson
Copy link
Contributor Author

JesseStimpson commented May 22, 2024

Test added.

I wasn't able to follow your approach for the map construction. Annoyingly, the keys are different between the JSON representation from the credential_process (e.g. AccessKeyId) and the keys in the credentials file itself (e.g. aws_access_key_id)

Moreover, since SessionToken/aws_session_token is optional, I think the current code is the most succinct I can make it.

I can break it out into a separate function if you think that would help readability.

@onno-vos-dev
Copy link
Member

Test added.

I wasn't able to follow your approach for the map construction. Annoyingly, the keys are different between the JSON representation from the credential_process (e.g. AccessKeyId) and the keys in the credentials file itself (e.g. aws_access_key_id)

Moreover, since SessionToken/aws_session_token is optional, I think the current code is the most succinct I can make it.

I can break it out into a separate function if you think that would help readability.

Ofcourse. My coffee-deprived brain didn't take that into account 😅

Looks good ❤️ I've added a few more reviewers. I'll grab a cup of coffee and take a look around lunch 👍

@onno-vos-dev onno-vos-dev self-requested a review May 23, 2024 08:59
@onno-vos-dev
Copy link
Member

LGTM 👌 Thank you! Will merge and tag in a couple of hours 👌

@onno-vos-dev onno-vos-dev merged commit 2c9cea4 into aws-beam:master May 24, 2024
8 checks passed
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.

2 participants