Skip to content

Commit cee3e31

Browse files
authored
Add hostPrefix support to RPC v2 CBOR serializer (boto#3592)
* Add hostPrefix support to RPC v2 CBOR serializer
1 parent 8a5158e commit cee3e31

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

botocore/serialize.py

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

1060+
host_prefix = self._expand_host_prefix(parameters, operation_model)
1061+
if host_prefix is not None:
1062+
serialized['host_prefix'] = host_prefix
1063+
10601064
self._serialize_headers(serialized, operation_model)
10611065

10621066
return serialized

tests/unit/test_serialize.py

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

0 commit comments

Comments
 (0)