Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"pyproject.toml": "3bf9e8ba4f2d5620cb43a34b5a05445485d96bbc71b79d568cfe10e92d3deef6",
"src/features_client/__init__.py": "32592f5725712e19c306d0c817040e64c67203ae420e3fac2a05301915b742aa",
"src/features_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"src/features_client/_private/endpoints.py": "f5bec5c0c17f9ec3fab86ea81c1472b1771118e6064f52cbb58cf85d89e09b20",
"src/features_client/_private/endpoints.py": "90e1bc94c3ca6338b495b94870e7b1e433c1c2da064e336a85ad94616953916a",
"src/features_client/_private/schemas.py": "7b2007610a0ec1e352198c77230810edaa6a2ec41cc4d3034b58fd36b278b613",
"src/features_client/aio/__init__.py": "2d6c204a7bbceeed5b175fe0df922722d341068027b29287cfdcbb9cb29403af",
"src/features_client/aio/client.py": "910b8914637d5e09218664a96792ca6727c941a52d4e678ba4c31fdbc81e360e",
"src/features_client/aio/config.py": "c341294cd16f4940fceb60c8513e29b5b81636a8ba4b999951e09c23efa9e093",
"src/features_client/aio/config.py": "96baec406f19b8641e301fa89088e83a3cdde57a8ae14a270fd16ffe25e70214",
"src/features_client/aio/user_agent.py": "05cbb5932a96cb83d55ece172f9b9b5b8aeb625782140647e177d5d5cbd18dd5",
"src/features_client/client.py": "fb0acd7beabe576c39ba2f1f1067366d5ba63635ad66f4849280c546fe3d059d",
"src/features_client/config.py": "9ac6470542449161d0aa85f94eec11623e79cf5fbc5db6749b8ce462940e8fdb",
"src/features_client/config.py": "0380227b86fc8409c15e381894be6396fdaa00cdd9a76c7da968537f855adb68",
"src/features_client/models.py": "b326674510de3a4f6dd77a4d172cf4dfce08a6ed24f01fa162e99c31dfa13567",
"src/features_client/models.pyi": "26858d43ae4e5d88d0ef0db95bd332d12de4784e8b8bf9b0a0a71d54cec5b93a",
"src/features_client/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"src/features_client/user_agent.py": "6d7e1477fa0123330b26d750070dcb49afe76bd14baa8bbe4b66a3d28e7ad75f",
"tests/test_endpoints.py": "dd98319dec82644ab5f58d0793e0c2dcf877f358b60b96dcb26f2367c8c37f21"
"tests/test_endpoints.py": "395f805a2889159097487f70f8ee3d6bfb83403ec370dc97e56e5e9304ba93a9"
},
"version": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@
parameters=(
("Endpoint", "string", False, None, "SDK::Endpoint", None),
("Region", "string", False, None, "AWS::Region", None),
("UseFIPS", "boolean", True, False, "AWS::UseFIPS", None),
("Stage", "string", False, None, None, "stage"),
("ForcePathStyle", "boolean", True, False, None, "force_path_style"),
("Name", "string", False, None, None, None),
("Kind", "string", False, None, None, None),
),
functions=("booleanEquals", "isSet", "isValidHostLabel"),
functions=("aws.partition", "booleanEquals", "isSet", "isValidHostLabel"),
conditions=(
((2, "isSet", (0, "Endpoint")), None), # 0: isSet(Endpoint)
((2, "isSet", (0, "Region")), None), # 1: isSet(Region)
((2, "booleanEquals", (0, "ForcePathStyle"), True), None), # 2: booleanEquals(ForcePathStyle, true)
((2, "isSet", (0, "Kind")), None), # 3: isSet(Kind)
((2, "isSet", (0, "Stage")), None), # 4: isSet(Stage)
((2, "isSet", (0, "Name")), None), # 5: isSet(Name)
((2, "isValidHostLabel", (0, "Name"), False), None), # 6: isValidHostLabel(Name, false)
((2, "booleanEquals", (0, "ForcePathStyle"), True), None), # 1: booleanEquals(ForcePathStyle, true)
((2, "isSet", (0, "Kind")), None), # 2: isSet(Kind)
((2, "isSet", (0, "Stage")), None), # 3: isSet(Stage)
((2, "isSet", (0, "Region")), None), # 4: isSet(Region)
((2, "aws.partition", (0, "Region")), "PartitionResult"), # 5: PartitionResult = aws.partition(Region)
((2, "booleanEquals", (0, "UseFIPS"), True), None), # 6: booleanEquals(UseFIPS, true)
((2, "isSet", (0, "Name")), None), # 7: isSet(Name)
((2, "isValidHostLabel", (0, "Name"), False), None), # 8: isValidHostLabel(Name, false)
),
results=(
None, # 0: no match
(6, (0, "Endpoint"), None, ()), # 1
(6, "https://{Region}.example.com", None, ()), # 2
(6, "https://path.example.com", None, ()), # 3
(6, "https://{Name}.{Stage}.example.com", None, (("x-kind", ("{Kind}",)),)), # 4
(6, "https://{Stage}.example.com", (4, ("kind",), "{Kind}"), ()), # 5
(5, "No stage"), # 6
(6, "https://path.example.com", None, ()), # 2
(6, "https://{Name}.{Stage}.example.com", None, (("x-kind", ("{Kind}",)),)), # 3
(6, "https://{Stage}.example.com", (4, ("kind",), "{Kind}"), ()), # 4
(6, "https://fieldnotes-fips.{Region}.{PartitionResult#dnsSuffix}", None, ()), # 5
(6, "https://fieldnotes.{Region}.{PartitionResult#dnsSuffix}", (4, ("authSchemes",), (3, (4, ("name", "signingName", "signingRegion"), "sigv4", "fieldnotes", "{Region}"))), ()), # 6
(5, "No region or stage"), # 7
),
root=2,
# (condition, high, low); 1 and -1 are terminals, a negative reference is a
Expand All @@ -38,11 +42,13 @@
-1, 1, -1,
0, 100_000_001, 3,
1, 100_000_002, 4,
2, 100_000_003, 5,
3, 6, 100_000_006,
4, 7, 100_000_006,
5, 8, 100_000_005,
6, 100_000_004, 100_000_005,
2, 5, 6,
3, 9, 6,
4, 7, 100_000_007,
5, 8, 100_000_007,
6, 100_000_005, 100_000_006,
7, 10, 100_000_004,
8, 100_000_003, 100_000_004,
),
)
# fmt: on
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
AsyncAwsConfigOverrides,
)
from smithy_aws_core.aio.config.filesystem import AsyncFileSystem
from smithy_aws_core.config.resolvers import EndpointUriResolver
from smithy_aws_core.config.resolvers import (
EndpointUriResolver,
resolve_use_fips_endpoint_program,
)
from smithy_aws_core.config.types import FieldSpec
from smithy_aws_core.endpoints import AWS_RULES_EXTENSION
from smithy_core.aio.interfaces import AsyncEndpointResolver
from smithy_core.aio.interfaces.auth import AsyncAuthScheme
from smithy_core.aio.interfaces.identity import AsyncIdentityResolver
Expand Down Expand Up @@ -57,6 +61,7 @@ class _AsyncFieldNotesConfigOverrides(AsyncAwsConfigOverrides, total=False):
)
stage: str | None
force_path_style: bool | None
use_fips_endpoint: bool | None


@dataclass(kw_only=True, repr=False, init=False)
Expand Down Expand Up @@ -94,13 +99,18 @@ class AsyncFieldNotesConfig(AsyncAwsConfig):
force_path_style: bool | None = None
"Forces path-style addressing."

use_fips_endpoint: bool | None = None
"Whether to use a FIPS endpoint."

_FIELDS: ClassVar[dict[str, FieldSpec]] = {
**AsyncAwsConfig._FIELDS,
"endpoint_uri": FieldSpec(
default=None, resolver=EndpointUriResolver("field_notes").program
),
"endpoint_resolver": FieldSpec(
default_factory=lambda: BddEndpointResolver(BDD)
default_factory=lambda: BddEndpointResolver(
BDD, extensions=[AWS_RULES_EXTENSION]
)
),
"protocol": FieldSpec(
default_factory=lambda: AsyncRpcV2CborClientProtocol(_PROTOCOL_SETTINGS),
Expand All @@ -123,6 +133,9 @@ class AsyncFieldNotesConfig(AsyncAwsConfig):
),
"stage": FieldSpec(default=None),
"force_path_style": FieldSpec(default=None),
"use_fips_endpoint": FieldSpec(
default=None, resolver=resolve_use_fips_endpoint_program
),
"transport": FieldSpec(default_factory=lambda: AIOHTTPClient()),
}

Expand Down
17 changes: 15 additions & 2 deletions codegen-output-py/features-client/src/features_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from smithy_aws_core.auth.sigv4 import SigV4AuthScheme
from smithy_aws_core.config.aws_config import AwsConfig, AwsConfigOverrides
from smithy_aws_core.config.filesystem import FileSystem
from smithy_aws_core.config.resolvers import EndpointUriResolver
from smithy_aws_core.config.resolvers import (
EndpointUriResolver,
resolve_use_fips_endpoint_program,
)
from smithy_aws_core.config.types import FieldSpec
from smithy_aws_core.endpoints import AWS_RULES_EXTENSION
from smithy_core.auth import DefaultAuthResolver
from smithy_core.endpoints import BddEndpointResolver
from smithy_core.interceptors import Interceptor
Expand Down Expand Up @@ -52,6 +56,7 @@ class _FieldNotesConfigOverrides(AwsConfigOverrides, total=False):
)
stage: str | None
force_path_style: bool | None
use_fips_endpoint: bool | None


@dataclass(kw_only=True, repr=False, init=False)
Expand Down Expand Up @@ -89,13 +94,18 @@ class FieldNotesConfig(AwsConfig):
force_path_style: bool | None = None
"Forces path-style addressing."

use_fips_endpoint: bool | None = None
"Whether to use a FIPS endpoint."

_FIELDS: ClassVar[dict[str, FieldSpec]] = {
**AwsConfig._FIELDS,
"endpoint_uri": FieldSpec(
default=None, resolver=EndpointUriResolver("field_notes").program
),
"endpoint_resolver": FieldSpec(
default_factory=lambda: BddEndpointResolver(BDD)
default_factory=lambda: BddEndpointResolver(
BDD, extensions=[AWS_RULES_EXTENSION]
)
),
"protocol": FieldSpec(
default_factory=lambda: RpcV2CborClientProtocol(_PROTOCOL_SETTINGS),
Expand All @@ -118,6 +128,9 @@ class FieldNotesConfig(AwsConfig):
),
"stage": FieldSpec(default=None),
"force_path_style": FieldSpec(default=None),
"use_fips_endpoint": FieldSpec(
default=None, resolver=resolve_use_fips_endpoint_program
),
"transport": FieldSpec(default_factory=lambda: Urllib3HTTPClient()),
}

Expand Down
116 changes: 99 additions & 17 deletions codegen-output-py/features-client/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from features_client.aio.client import AsyncFieldNotesClient
from features_client.aio.config import AsyncFieldNotesConfig
from pytest import mark, param
from smithy_aws_core.aio.identity.static import AsyncStaticCredentialsResolver
from smithy_aws_core.endpoints import AWS_RULES_EXTENSION
from smithy_aws_core.identity.components import AWSCredentialsIdentity
from smithy_core.aio.utils import close_async
from smithy_core.endpoints import BddEndpointResolver
from smithy_core.interceptors import Interceptor
Expand All @@ -18,8 +21,14 @@

_TEST_CONFIG: dict[str, Any] = {
"region": "us-east-1",
"aws_access_key_id": "AKIDTEST",
"aws_secret_access_key": "secret",
"endpoint_uri": None,
"aws_credentials_identity_resolver": AsyncStaticCredentialsResolver(
AWSCredentialsIdentity(
access_key_id="test-access-key-id",
secret_access_key="test-secret-access-key",
)
),
"use_fips_endpoint": None,
}
"Config fields every test sets. A case's own fields replace them."

Expand All @@ -30,6 +39,10 @@ async def _config(**fields: Any) -> AsyncFieldNotesConfig:
)


_RULES_EXTENSIONS = [AWS_RULES_EXTENSION]
"The extensions of the default resolver, which build the auth schemes a case expects."


# Every rules test shares one resolver, so its caches see changing parameters.
_resolver: BddEndpointResolver | None = None

Expand Down Expand Up @@ -99,25 +112,58 @@ async def _client(
),
param(
{"Region": "us-west-2"},
{"endpoint": {"url": "https://us-west-2.example.com"}},
{
"endpoint": {
"url": "https://fieldnotes.us-west-2.amazonaws.com",
"properties": {
"authSchemes": [
{
"name": "sigv4",
"signingName": "fieldnotes",
"signingRegion": "us-west-2",
}
]
},
}
},
id="Region from the built-in",
),
param(
{},
{"error": "No stage"},
id="Missing stage",
{"Region": "cn-north-1"},
{
"endpoint": {
"url": "https://fieldnotes.cn-north-1.amazonaws.com.cn",
"properties": {
"authSchemes": [
{
"name": "sigv4",
"signingName": "fieldnotes",
"signingRegion": "cn-north-1",
}
]
},
}
},
id="Partition from the region",
),
param(
{"Kind": "put"},
{"error": "No stage"},
id="Missing stage (2)",
{"Region": "us-east-1", "UseFIPS": True},
{"endpoint": {"url": "https://fieldnotes-fips.us-east-1.amazonaws.com"}},
id="FIPS from the built-in",
),
param(
{},
{"error": "No region or stage"},
id="No region or stage",
),
]


@mark.parametrize(("params", "expect"), RULES_CASES)
async def test_endpoint_rules(params: dict[str, Any], expect: dict[str, Any]) -> None:
check_rules_case(await _endpoint_resolver(), params, expect)
check_rules_case(
await _endpoint_resolver(), params, expect, extensions=_RULES_EXTENSIONS
)


CLIENT_CASES = [
Expand Down Expand Up @@ -172,19 +218,51 @@ async def test_endpoint_rules(params: dict[str, Any], expect: dict[str, Any]) ->
id="Custom endpoint",
),
param(
{"region": "us-west-2"},
AsyncFieldNotesClient.put_note,
{},
AsyncFieldNotesClient.ping,
{},
{"endpoint": {"url": "https://us-west-2.example.com"}},
{
"endpoint": {
"url": "https://fieldnotes.us-west-2.amazonaws.com",
"properties": {
"authSchemes": [
{
"name": "sigv4",
"signingName": "fieldnotes",
"signingRegion": "us-west-2",
}
]
},
}
},
id="Region from the built-in",
marks=mark.skip(reason="No config field sets the built-in AWS::Region"),
),
param(
{"region": "cn-north-1"},
AsyncFieldNotesClient.ping,
{},
{
"endpoint": {
"url": "https://fieldnotes.cn-north-1.amazonaws.com.cn",
"properties": {
"authSchemes": [
{
"name": "sigv4",
"signingName": "fieldnotes",
"signingRegion": "cn-north-1",
}
]
},
}
},
id="Partition from the region",
),
param(
{"region": "us-east-1", "use_fips_endpoint": True},
AsyncFieldNotesClient.ping,
{},
{"error": "No stage"},
id="Missing stage",
{"endpoint": {"url": "https://fieldnotes-fips.us-east-1.amazonaws.com"}},
id="FIPS from the built-in",
),
]

Expand All @@ -197,5 +275,9 @@ async def test_endpoint_client(
expect: dict[str, Any],
) -> None:
await check_client_case_async(
lambda capture: _client(config, capture), operation, input, expect
lambda capture: _client(config, capture),
operation,
input,
expect,
extensions=_RULES_EXTENSIONS,
)
Loading
Loading