Skip to content

Commit ca13044

Browse files
committed
Port aws#3592
1 parent f80be22 commit ca13044

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

awscli/botocore/serialize.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,10 @@ def serialize_to_request(self, parameters, operation_model):
10361036
if input_shape is not None:
10371037
self._serialize_payload(parameters, serialized, input_shape)
10381038

1039+
host_prefix = self._expand_host_prefix(parameters, operation_model)
1040+
if host_prefix is not None:
1041+
serialized['host_prefix'] = host_prefix
1042+
10391043
self._serialize_headers(serialized, operation_model)
10401044

10411045
return serialized

tests/unit/botocore/test_serialize.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,3 +735,58 @@ def test_invalid_timestamp_precision_raises_error(self):
735735
timestamp_precision='invalid',
736736
)
737737
self.assertIn("Invalid timestamp precision", str(context.exception))
738+
739+
class TestRpcV2CBORHostPrefix(unittest.TestCase):
740+
def setUp(self):
741+
self.model = {
742+
'metadata': {
743+
'protocol': 'smithy-rpc-v2-cbor',
744+
'apiVersion': '2014-01-01',
745+
'serviceId': 'MyService',
746+
'targetPrefix': 'sampleservice',
747+
'documentation': '',
748+
},
749+
'operations': {
750+
'TestHostPrefixOperation': {
751+
'name': 'TestHostPrefixOperation',
752+
'input': {'shape': 'InputShape'},
753+
'endpoint': {'hostPrefix': '{Foo}'},
754+
},
755+
'TestNoHostPrefixOperation': {
756+
'name': 'TestNoHostPrefixOperation',
757+
'input': {'shape': 'InputShape'},
758+
},
759+
},
760+
'shapes': {
761+
'InputShape': {
762+
'type': 'structure',
763+
'members': {
764+
'Foo': {'shape': 'StringType', 'hostLabel': True},
765+
},
766+
},
767+
'StringType': {'type': 'string'},
768+
},
769+
}
770+
self.service_model = ServiceModel(self.model)
771+
772+
def test_host_prefix_added_to_serialized_request(self):
773+
operation_model = self.service_model.operation_model(
774+
'TestHostPrefixOperation'
775+
)
776+
serializer = serialize.create_serializer('smithy-rpc-v2-cbor')
777+
778+
params = {'Foo': 'bound'}
779+
serialized = serializer.serialize_to_request(params, operation_model)
780+
781+
self.assertEqual(serialized['host_prefix'], 'bound')
782+
783+
def test_no_host_prefix_when_not_configured(self):
784+
operation_model = self.service_model.operation_model(
785+
'TestNoHostPrefixOperation'
786+
)
787+
serializer = serialize.create_serializer('smithy-rpc-v2-cbor')
788+
789+
params = {'Foo': 'bound'}
790+
serialized = serializer.serialize_to_request(params, operation_model)
791+
792+
self.assertNotIn('host_prefix', serialized)

0 commit comments

Comments
 (0)