Skip to content

Conversation

@aeitzman
Copy link
Contributor

No description provided.

@BigTailWolf
Copy link
Contributor

Please fix lint

Comment on lines +469 to +471
credentials.get("AccessKeyId"),
credentials.get("SecretAccessKey"),
credentials.get("Token"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be any type of validation here? Is it guaranteed that the credential variable has these keys?

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, the response we get back will have at least accessKeyId and SecretAccesskey, and token is optional. This code and the rest of the comments on the AWS credential aren't actually changed at all btw, just refactored and moved around a bit to support the supplier pattern we are using for programmatic. Since this isn't actually getting changed and won't cause a regression, are you OK if I pull all your suggestions into a to-do bug to go and do some of these fixes in a different PR targeted at that?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am okay with you tracking non-regressions in a separate bug and following up with small PRs if you prefer.

}
def _get_imdsv2_session_token(self, request):
if request is not None and self._imdsv2_session_token_url is not None:
headers = {"X-aws-ec2-metadata-token-ttl-seconds": "300"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 300? Can you make it a self-documenting variable.

credentials = self._get_metadata_security_credentials(
request, role_name, imdsv2_session_token
)
if imdsv2_session_token_response.status != 200:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a http status object instead of a magic number. See transport/__init__.py for examples.

Comment on lines +523 to +524
"Unable to retrieve AWS Session Token",
imdsv2_session_token_response.data,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this string be formatted?

audience (str): The STS audience field.
subject_token_type (str): The subject token type.
token_url (str): The STS endpoint URL.
credential_source (Mapping): The credential source dictionary used
Copy link
Contributor

Choose a reason for hiding this comment

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

This documentation is missing how to build a credential source dict

)

# Get the environment ID. Currently, only one version supported (v1).
matches = re.match(r"^(aws)([\d]+)$", environment_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment with an example string that this regex is matching.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ping

raise exceptions.InvalidResource(
"No valid AWS 'credential_source' provided"
)
elif int(env_version or "") != 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

int("") will result in a ValueError being raised.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ping

Comment on lines +772 to +775
# Serialize AWS signed request.
# Keeping inner keys in sorted order makes testing easier for Python
# versions <=3.5 as the stringified JSON string would have a predictable
# key order.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the tests be rewritten to not rely on order? This does not seem like a good reason to sort the data.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to follow up on this. It would be best to avoid sorting this data twice.

if not os.path.exists(self._path):
raise exceptions.RefreshError("File '{}' was not found.".format(self._path))

with io.open(self._path, "r", encoding="utf-8") as file_obj:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: open is a builtin, you don't need to use the io module.

Copy link
Contributor

@clundin25 clundin25 left a comment

Choose a reason for hiding this comment

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

Additional follow up tracked in b/328671918

@aeitzman aeitzman merged commit 948e843 into googleapis:programmatic-auth Mar 11, 2024
aeitzman added a commit that referenced this pull request Mar 15, 2024
…entials (#1496)

* feat: refactor AWS and identity pool credentials to use suppliers (#1484)

* feat: refactor aws and identity pool credentials to use supplier framework

* Linting

* changing class types

* linting

* remove unused import

* Fix typing

* add docstring and fix casing

* feat: Adds support for custom suppliers in AWS and Identity Pool credential instantiation (#1494)

* feat: refactor aws and identity pool credentials to use supplier framework

* Linting

* changing class types

* linting

* remove unused import

* Fix typing

* add docstring and fix casing

* feat: adds support for passing suppliers to credentials.

* fixes merge issues and adds _has_custom_supplier method

* adds _has_custom_supplier function to identity_pool

* Update google/auth/external_account.py

Co-authored-by: Carl Lundin <[email protected]>

* Apply suggestions from code review

Co-authored-by: Carl Lundin <[email protected]>

* Respond to comments and fix docs

---------

Co-authored-by: Carl Lundin <[email protected]>

* docs: add documentation for suppliers (#1495)

* docs: update docs for programmatic

* add space

* update user guide

* update docs

* Apply suggestions from code review

Co-authored-by: Leo <[email protected]>

* Update docs

* Add docs about context and request

---------

Co-authored-by: Carl Lundin <[email protected]>
Co-authored-by: Leo <[email protected]>
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.

5 participants