Skip to content

Commit

Permalink
Endpoint resolution v2: builtin parameter values (#2759)
Browse files Browse the repository at this point in the history
* EndpointsResolverv2 builtins

* test coverage for ClientArgsCreator._should_set_global_sts_endpoint

* unit tests for endpoint resolver v2 builtins value lookup

* add typing information for EndpointResolverBuiltins

* PR review code style suggestions

* remove tests for _should_set_global_sts_endpoint

* rename to "compute_endpoint_resolver_builtin_defaults"

* refactor tests to avoid mocking private methods

* remove duplicate import

* cannot request fips or dualstack if SDK::Endpoint is set

* remove incorrect enum type annotations
  • Loading branch information
jonemo authored Sep 16, 2022
1 parent d075423 commit d10816a
Show file tree
Hide file tree
Showing 3 changed files with 325 additions and 10 deletions.
71 changes: 69 additions & 2 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import botocore.utils
from botocore.config import Config
from botocore.endpoint import EndpointCreator
from botocore.regions import EndpointResolverBuiltins as EPRBuiltins
from botocore.signers import RequestSigner

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -344,8 +345,10 @@ def _compute_sts_endpoint_config(self, **resolve_endpoint_kwargs):
def _should_set_global_sts_endpoint(
self, region_name, endpoint_url, endpoint_config
):
endpoint_variant_tags = endpoint_config['metadata'].get('tags')
if endpoint_url or endpoint_variant_tags:
has_variant_tags = endpoint_config and endpoint_config.get(
'metadata', {}
).get('tags')
if endpoint_url or has_variant_tags:
return False
return (
self._get_sts_regional_endpoints_config() == 'legacy'
Expand Down Expand Up @@ -464,3 +467,67 @@ def _ensure_boolean(self, val):
return val
else:
return val.lower() == 'true'

def compute_endpoint_resolver_builtin_defaults(
self,
region_name,
service_name,
s3_config,
endpoint_bridge,
client_endpoint_url,
legacy_endpoint_url,
):
# EndpointResolverv2 rulesets may accept an "SDK::Endpoint" as input.
# If the endpoint_url argument of create_client() is set, it always
# takes priority.
if client_endpoint_url:
given_endpoint = client_endpoint_url
# If an endpoints.json data file other than the one bundled within
# the botocore/data directory is used, the output of legacy
# endpoint resolution is provided to EndpointResolverv2.
elif not endpoint_bridge.endpoint_resolver.uses_builtin_data:
given_endpoint = legacy_endpoint_url
else:
given_endpoint = None

return {
EPRBuiltins.AWS_REGION: region_name,
EPRBuiltins.AWS_USE_FIPS: (
endpoint_bridge._resolve_endpoint_variant_config_var(
'use_fips_endpoint'
)
or False
and not given_endpoint
),
EPRBuiltins.AWS_USE_DUALSTACK: (
endpoint_bridge._resolve_use_dualstack_endpoint(service_name)
or False
and not given_endpoint
),
EPRBuiltins.AWS_STS_USE_GLOBAL_ENDPOINT: (
self._should_set_global_sts_endpoint(
region_name=region_name,
endpoint_url=None,
endpoint_config=None,
)
),
EPRBuiltins.AWS_S3_USE_GLOBAL_ENDPOINT: (
self._should_force_s3_global(region_name, s3_config)
),
EPRBuiltins.AWS_S3_ACCELERATE: s3_config.get(
'use_accelerate_endpoint', False
),
EPRBuiltins.AWS_S3_FORCE_PATH_STYLE: (
s3_config.get('addressing_style') == 'path'
),
EPRBuiltins.AWS_S3_USE_ARN_REGION: s3_config.get(
'use_arn_region', True
),
EPRBuiltins.AWS_S3CONTROL_USE_ARN_REGION: s3_config.get(
'use_arn_region', False
),
EPRBuiltins.AWS_S3_DISABLE_MRAP: s3_config.get(
's3_disable_multiregion_access_points', False
),
EPRBuiltins.SDK_ENDPOINT: given_endpoint,
}
32 changes: 32 additions & 0 deletions botocore/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""
import logging
import re
from enum import Enum

from botocore.exceptions import (
EndpointVariantError,
Expand Down Expand Up @@ -401,3 +402,34 @@ def _expand_template(
return template.format(
service=service_name, region=endpoint_name, dnsSuffix=dnsSuffix
)


class EndpointResolverBuiltins(str, Enum):
# The AWS Region configured for the SDK client (str)
AWS_REGION = "AWS::Region"
# Whether the UseFIPSEndpoint configuration option has been enabled for
# the SDK client (bool)
AWS_USE_FIPS = "AWS::UseFIPS"
# Whether the UseDualStackEndpoint configuration option has been enabled
# for the SDK client (bool)
AWS_USE_DUALSTACK = "AWS::UseDualStack"
# Whether the global endpoint should be used with STS, rather the the
# regional endpoint for us-east-1 (bool)
AWS_STS_USE_GLOBAL_ENDPOINT = "AWS::STS::UseGlobalEndpoint"
# Whether the global endpoint should be used with S3, rather then the
# regional endpoint for us-east-1 (bool)
AWS_S3_USE_GLOBAL_ENDPOINT = "AWS::S3::UseGlobalEndpoint"
# Whether S3 Transfer Acceleration has been requested (bool)
AWS_S3_ACCELERATE = "AWS::S3::Accelerate"
# Whether S3 Force Path Style has been enabled (bool)
AWS_S3_FORCE_PATH_STYLE = "AWS::S3::ForcePathStyle"
# Whether to use the ARN region or raise an error when ARN and client
# region differ (for s3 service only, bool)
AWS_S3_USE_ARN_REGION = "AWS::S3::UseArnRegion"
# Whether to use the ARN region or raise an error when ARN and client
# region differ (for s3-control service only, bool)
AWS_S3CONTROL_USE_ARN_REGION = 'AWS::S3Control::UseArnRegion'
# Whether multi-region access points (MRAP) should be disabled (bool)
AWS_S3_DISABLE_MRAP = "AWS::S3::DisableMultiRegionAccessPoints"
# Whether a custom endpoint has been configured (str)
SDK_ENDPOINT = "SDK::Endpoint"
Loading

0 comments on commit d10816a

Please sign in to comment.