-
Notifications
You must be signed in to change notification settings - Fork 24
Sigv4 AuthScheme + Static/Environment Credentials Providers #406
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
Changes from 2 commits
c5c137b
a2dac51
29bf5af
04c8e4a
bf7ac20
09d513c
351c753
45cce24
5c043c2
96ae7f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from .sigv4 import SigV4AuthScheme | ||
|
|
||
| __all__ = ("SigV4AuthScheme",) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||
| from dataclasses import dataclass | ||||||
| from typing import Protocol | ||||||
|
|
||||||
| from smithy_aws_core.identity import AWSCredentialsIdentity | ||||||
| from smithy_core.aio.interfaces.identity import IdentityResolver | ||||||
| from smithy_core.exceptions import SmithyIdentityException | ||||||
| from smithy_core.interfaces.identity import IdentityProperties | ||||||
| from smithy_http.aio.interfaces.auth import HTTPAuthScheme, HTTPSigner | ||||||
| from aws_sdk_signers import SigV4SigningProperties, SigV4Signer | ||||||
|
|
||||||
|
|
||||||
| class SigV4Config(Protocol): | ||||||
| aws_credentials_identity_resolver: ( | ||||||
| IdentityResolver[AWSCredentialsIdentity, IdentityProperties] | None | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @dataclass(init=False) | ||||||
| class SigV4AuthScheme( | ||||||
| HTTPAuthScheme[ | ||||||
| AWSCredentialsIdentity, SigV4Config, IdentityProperties, SigV4SigningProperties | ||||||
| ] | ||||||
| ): | ||||||
| """SigV4 AuthScheme.""" | ||||||
|
|
||||||
| scheme_id: str | ||||||
|
||||||
| scheme_id: str | |
| scheme_id: Final = "aws.auth#sigv4" |
Well this should also be a ShapeID but that's probably a bit more involved to do just now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we'd need to update the HttpAuthScheme protocol as well for that. I wasn't able to update this to Final without changing the HttpAuthScheme as well, which breaks with Final (since nothing is initialized on it).
For now, I've left the type as str but moved the initialization of it out of __init__
alextwoods marked this conversation as resolved.
Show resolved
Hide resolved
jonathan343 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from .environment_credentials_resolver import EnvironmentCredentialsResolver | ||
| from .static_credentials_resolver import StaticCredentialsResolver | ||
|
|
||
| __all__ = ("EnvironmentCredentialsResolver", "StaticCredentialsResolver") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| import os | ||
|
|
||
| from smithy_aws_core.identity import AWSCredentialsIdentity | ||
| from smithy_core.aio.interfaces.identity import IdentityResolver | ||
| from smithy_core.exceptions import SmithyIdentityException | ||
| from smithy_core.interfaces.identity import IdentityProperties | ||
|
|
||
|
|
||
| class EnvironmentCredentialsResolver( | ||
| IdentityResolver[AWSCredentialsIdentity, IdentityProperties] | ||
| ): | ||
| """Resolves AWS Credentials from system environment variables.""" | ||
|
|
||
| async def get_identity( | ||
| self, *, identity_properties: IdentityProperties | ||
| ) -> AWSCredentialsIdentity: | ||
| access_key_id = os.getenv("AWS_ACCESS_KEY_ID") | ||
| secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY") | ||
| session_token = os.getenv("AWS_SESSION_TOKEN") | ||
| account_id = os.getenv("AWS_ACCOUNT_ID") | ||
|
|
||
| if access_key_id is None or secret_access_key is None: | ||
| raise SmithyIdentityException( | ||
| "AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are required" | ||
| ) | ||
|
|
||
| return AWSCredentialsIdentity( | ||
| access_key_id=access_key_id, | ||
| secret_access_key=secret_access_key, | ||
| session_token=session_token, | ||
| account_id=account_id, | ||
| ) |
jonathan343 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from smithy_aws_core.identity import AWSCredentialsIdentity | ||
| from smithy_core.aio.interfaces.identity import IdentityResolver | ||
| from smithy_core.interfaces.identity import IdentityProperties | ||
|
|
||
|
|
||
| class StaticCredentialsResolver( | ||
| IdentityResolver[AWSCredentialsIdentity, IdentityProperties] | ||
| ): | ||
| """Resolve Static AWS Credentials.""" | ||
|
|
||
| def __init__(self, *, credentials: AWSCredentialsIdentity) -> None: | ||
| self._credentials = credentials | ||
|
|
||
| async def get_identity( | ||
| self, *, identity_properties: IdentityProperties | ||
| ) -> AWSCredentialsIdentity: | ||
| return self._credentials |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tragic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the alternative would be to add signingService as an auth param. We would then need a way to wire that up during the request. It could be an undocumented config property or have it somewhere else.