Skip to content

[v2] Port updated protocol tests #9554

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

Merged
merged 3 commits into from
Jun 18, 2025
Merged
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
28 changes: 2 additions & 26 deletions awscli/botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from botocore.regions import EndpointRulesetResolver
from botocore.signers import RequestSigner
from botocore.useragent import UserAgentString, register_feature_id
from botocore.utils import PRIORITY_ORDERED_SUPPORTED_PROTOCOLS # noqa: F401
from botocore.utils import ensure_boolean, is_s3_accelerate_url

logger = logging.getLogger(__name__)
Expand All @@ -46,14 +47,6 @@
"when_required",
)

PRIORITY_ORDERED_SUPPORTED_PROTOCOLS = (
'smithy-rpc-v2-cbor',
'json',
'rest-json',
'rest-xml',
'query',
'ec2',
)

VALID_ACCOUNT_ID_ENDPOINT_MODE_CONFIG = (
'preferred',
Expand Down Expand Up @@ -204,7 +197,7 @@ def compute_client_args(
scoped_config,
):
service_name = service_model.endpoint_prefix
protocol = self._resolve_protocol(service_model)
protocol = service_model.resolved_protocol
parameter_validation = True
if client_config and not client_config.parameter_validation:
parameter_validation = False
Expand Down Expand Up @@ -722,23 +715,6 @@ def _compute_checksum_config(self, config_kwargs):
valid_options=VALID_RESPONSE_CHECKSUM_VALIDATION_CONFIG,
)

def _resolve_protocol(self, service_model):
# We need to ensure `protocols` exists in the metadata before attempting to
# access it directly since referencing service_model.protocols directly will
# raise an UndefinedModelAttributeError if protocols is not defined
if service_model.metadata.get('protocols'):
for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS:
if protocol in service_model.protocols:
return protocol
raise botocore.exceptions.UnsupportedServiceProtocolsError(
botocore_supported_protocols=PRIORITY_ORDERED_SUPPORTED_PROTOCOLS,
service_supported_protocols=service_model.protocols,
service=service_model.service_name,
)
# If a service does not have a `protocols` trait, fall back to the legacy
# `protocol` trait
return service_model.protocol

def _handle_checksum_config(
self,
config_kwargs,
Expand Down
2 changes: 1 addition & 1 deletion awscli/botocore/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _do_get_response(self, request, operation_model, context):
)
history_recorder.record('HTTP_RESPONSE', http_response_record_dict)

protocol = operation_model.metadata['protocol']
protocol = operation_model.service_model.resolved_protocol
customized_response_dict = {}
self._event_emitter.emit(
f"before-parse.{service_id}.{operation_model.name}",
Expand Down
26 changes: 25 additions & 1 deletion awscli/botocore/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
from botocore.exceptions import (
MissingServiceIdError,
UndefinedModelAttributeError,
UnsupportedServiceProtocolsError,
)
from botocore.utils import (
PRIORITY_ORDERED_SUPPORTED_PROTOCOLS,
CachedProperty,
hyphenize_service_id,
instance_cache,
)
from botocore.utils import CachedProperty, hyphenize_service_id, instance_cache

NOT_SET = object()

Expand Down Expand Up @@ -424,6 +430,24 @@ def protocol(self):
def protocols(self):
return self._get_metadata_property('protocols')

@CachedProperty
def resolved_protocol(self):
# We need to ensure `protocols` exists in the metadata before attempting to
# access it directly since referencing service_model.protocols directly will
# raise an UndefinedModelAttributeError if protocols is not defined
if self.metadata.get('protocols'):
for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS:
if protocol in self.protocols:
return protocol
raise UnsupportedServiceProtocolsError(
botocore_supported_protocols=PRIORITY_ORDERED_SUPPORTED_PROTOCOLS,
service_supported_protocols=self.protocols,
service=self.service_name,
)
# If a service does not have a `protocols` trait, fall back to the legacy
# `protocol` trait
return self.protocol

@CachedProperty
def endpoint_prefix(self):
return self._get_metadata_property('endpointPrefix')
Expand Down
2 changes: 1 addition & 1 deletion awscli/botocore/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def close(self):


def get_response(operation_model, http_response):
protocol = operation_model.metadata['protocol']
protocol = operation_model.service_model.resolved_protocol
response_dict = {
'headers': http_response.headers,
'status_code': http_response.status_code,
Expand Down
Loading
Loading