Skip to content

Commit c700181

Browse files
committed
Port aws#3592
1 parent 5a3d9c5 commit c700181

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

awscli/botocore/serialize.py

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

992+
host_prefix = self._expand_host_prefix(parameters, operation_model)
993+
if host_prefix is not None:
994+
serialized['host_prefix'] = host_prefix
995+
992996
self._serialize_headers(serialized, operation_model)
993997

994998
return serialized

tests/unit/botocore/test_serialize.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,59 @@ def test_restxml_serializes_unicode(self):
614614
self.serialize_to_request(params)
615615
except UnicodeEncodeError:
616616
self.fail("RestXML serializer failed to serialize unicode text.")
617+
618+
class TestRpcV2CBORHostPrefix(unittest.TestCase):
619+
def setUp(self):
620+
self.model = {
621+
'metadata': {
622+
'protocol': 'smithy-rpc-v2-cbor',
623+
'apiVersion': '2014-01-01',
624+
'serviceId': 'MyService',
625+
'targetPrefix': 'sampleservice',
626+
'documentation': '',
627+
},
628+
'operations': {
629+
'TestHostPrefixOperation': {
630+
'name': 'TestHostPrefixOperation',
631+
'input': {'shape': 'InputShape'},
632+
'endpoint': {'hostPrefix': '{Foo}'},
633+
},
634+
'TestNoHostPrefixOperation': {
635+
'name': 'TestNoHostPrefixOperation',
636+
'input': {'shape': 'InputShape'},
637+
},
638+
},
639+
'shapes': {
640+
'InputShape': {
641+
'type': 'structure',
642+
'members': {
643+
'Foo': {'shape': 'StringType', 'hostLabel': True},
644+
},
645+
},
646+
'StringType': {'type': 'string'},
647+
},
648+
}
649+
self.service_model = ServiceModel(self.model)
650+
651+
def test_host_prefix_added_to_serialized_request(self):
652+
operation_model = self.service_model.operation_model(
653+
'TestHostPrefixOperation'
654+
)
655+
serializer = serialize.create_serializer('smithy-rpc-v2-cbor')
656+
657+
params = {'Foo': 'bound'}
658+
serialized = serializer.serialize_to_request(params, operation_model)
659+
660+
self.assertEqual(serialized['host_prefix'], 'bound')
661+
662+
def test_no_host_prefix_when_not_configured(self):
663+
operation_model = self.service_model.operation_model(
664+
'TestNoHostPrefixOperation'
665+
)
666+
serializer = serialize.create_serializer('smithy-rpc-v2-cbor')
667+
668+
params = {'Foo': 'bound'}
669+
serialized = serializer.serialize_to_request(params, operation_model)
670+
671+
self.assertNotIn('host_prefix', serialized)
672+

0 commit comments

Comments
 (0)