Skip to content

Commit 8ee08ff

Browse files
authored
[v2] Update protocol tests (#9554)
1 parent 6719b2f commit 8ee08ff

File tree

25 files changed

+24900
-6511
lines changed

25 files changed

+24900
-6511
lines changed

awscli/botocore/args.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from botocore.regions import EndpointRulesetResolver
3030
from botocore.signers import RequestSigner
3131
from botocore.useragent import UserAgentString, register_feature_id
32+
from botocore.utils import PRIORITY_ORDERED_SUPPORTED_PROTOCOLS # noqa: F401
3233
from botocore.utils import ensure_boolean, is_s3_accelerate_url
3334

3435
logger = logging.getLogger(__name__)
@@ -46,14 +47,6 @@
4647
"when_required",
4748
)
4849

49-
PRIORITY_ORDERED_SUPPORTED_PROTOCOLS = (
50-
'smithy-rpc-v2-cbor',
51-
'json',
52-
'rest-json',
53-
'rest-xml',
54-
'query',
55-
'ec2',
56-
)
5750

5851
VALID_ACCOUNT_ID_ENDPOINT_MODE_CONFIG = (
5952
'preferred',
@@ -204,7 +197,7 @@ def compute_client_args(
204197
scoped_config,
205198
):
206199
service_name = service_model.endpoint_prefix
207-
protocol = self._resolve_protocol(service_model)
200+
protocol = service_model.resolved_protocol
208201
parameter_validation = True
209202
if client_config and not client_config.parameter_validation:
210203
parameter_validation = False
@@ -722,23 +715,6 @@ def _compute_checksum_config(self, config_kwargs):
722715
valid_options=VALID_RESPONSE_CHECKSUM_VALIDATION_CONFIG,
723716
)
724717

725-
def _resolve_protocol(self, service_model):
726-
# We need to ensure `protocols` exists in the metadata before attempting to
727-
# access it directly since referencing service_model.protocols directly will
728-
# raise an UndefinedModelAttributeError if protocols is not defined
729-
if service_model.metadata.get('protocols'):
730-
for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS:
731-
if protocol in service_model.protocols:
732-
return protocol
733-
raise botocore.exceptions.UnsupportedServiceProtocolsError(
734-
botocore_supported_protocols=PRIORITY_ORDERED_SUPPORTED_PROTOCOLS,
735-
service_supported_protocols=service_model.protocols,
736-
service=service_model.service_name,
737-
)
738-
# If a service does not have a `protocols` trait, fall back to the legacy
739-
# `protocol` trait
740-
return service_model.protocol
741-
742718
def _handle_checksum_config(
743719
self,
744720
config_kwargs,

awscli/botocore/endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _do_get_response(self, request, operation_model, context):
252252
)
253253
history_recorder.record('HTTP_RESPONSE', http_response_record_dict)
254254

255-
protocol = operation_model.metadata['protocol']
255+
protocol = operation_model.service_model.resolved_protocol
256256
customized_response_dict = {}
257257
self._event_emitter.emit(
258258
f"before-parse.{service_id}.{operation_model.name}",

awscli/botocore/model.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020
from botocore.exceptions import (
2121
MissingServiceIdError,
2222
UndefinedModelAttributeError,
23+
UnsupportedServiceProtocolsError,
24+
)
25+
from botocore.utils import (
26+
PRIORITY_ORDERED_SUPPORTED_PROTOCOLS,
27+
CachedProperty,
28+
hyphenize_service_id,
29+
instance_cache,
2330
)
24-
from botocore.utils import CachedProperty, hyphenize_service_id, instance_cache
2531

2632
NOT_SET = object()
2733

@@ -424,6 +430,24 @@ def protocol(self):
424430
def protocols(self):
425431
return self._get_metadata_property('protocols')
426432

433+
@CachedProperty
434+
def resolved_protocol(self):
435+
# We need to ensure `protocols` exists in the metadata before attempting to
436+
# access it directly since referencing service_model.protocols directly will
437+
# raise an UndefinedModelAttributeError if protocols is not defined
438+
if self.metadata.get('protocols'):
439+
for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS:
440+
if protocol in self.protocols:
441+
return protocol
442+
raise UnsupportedServiceProtocolsError(
443+
botocore_supported_protocols=PRIORITY_ORDERED_SUPPORTED_PROTOCOLS,
444+
service_supported_protocols=self.protocols,
445+
service=self.service_name,
446+
)
447+
# If a service does not have a `protocols` trait, fall back to the legacy
448+
# `protocol` trait
449+
return self.protocol
450+
427451
@CachedProperty
428452
def endpoint_prefix(self):
429453
return self._get_metadata_property('endpointPrefix')

awscli/botocore/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def close(self):
151151

152152

153153
def get_response(operation_model, http_response):
154-
protocol = operation_model.metadata['protocol']
154+
protocol = operation_model.service_model.resolved_protocol
155155
response_dict = {
156156
'headers': http_response.headers,
157157
'status_code': http_response.status_code,

0 commit comments

Comments
 (0)