Skip to content

Commit

Permalink
Check against Route53 parameter shape types
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Dec 5, 2014
1 parent ff24b1f commit a3d1128
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
11 changes: 9 additions & 2 deletions botocore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,21 @@ def base64_encode_user_data(params, **kwargs):
params['UserData'].encode('utf-8')).decode('utf-8')


def fix_route53_ids(params, **kwargs):
def fix_route53_ids(params, model, **kwargs):
"""
Check for and split apart Route53 resource IDs, setting
only the last piece. This allows the output of one operation
(e.g. ``'foo/1234'``) to be used as input in another
operation (e.g. it expects just ``'1234'``).
"""
for name in ['Id', 'HostedZoneId', 'ResourceId', 'DelegationSetId']:
input_shape = model.input_shape
if not input_shape or not hasattr(input_shape, 'members'):
return

members = [name for (name, shape) in input_shape.members.items()
if shape.name in ['ResourceId', 'DelegationSetId']]

for name in members:
if name in params:
orig_value = params[name]
params[name] = orig_value.split('/')[-1]
Expand Down
60 changes: 59 additions & 1 deletion tests/unit/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from botocore.hooks import first_non_none_response
from botocore.awsrequest import AWSRequest
from botocore.compat import quote
from botocore.model import OperationModel, ServiceModel
from botocore import handlers


Expand Down Expand Up @@ -179,7 +180,48 @@ def test_route53_resource_id(self):
'ResourceId': '/hostedzone/DEF456',
'DelegationSetId': '/hostedzone/GHI789',
'Other': '/hostedzone/foo'}
self.session.emit(event, params=params, model=mock.Mock())
operation_def = {
'name': 'GetHostedZone',
'input': {
'shape': 'GetHostedZoneInput'
}
}
service_def = {
'metadata': {},
'shapes': {
'GetHostedZoneInput': {
'type': 'structure',
'members': {
'Id': {
'shape': 'ResourceId'
},
'HostedZoneId': {
'shape': 'ResourceId'
},
'ResourceId': {
'shape': 'ResourceId'
},
'DelegationSetId': {
'shape': 'DelegationSetId'
},
'Other': {
'shape': 'String'
}
}
},
'ResourceId': {
'type': 'string'
},
'DelegationSetId': {
'type': 'string'
},
'String': {
'type': 'string'
}
}
}
model = OperationModel(operation_def, ServiceModel(service_def))
self.session.emit(event, params=params, model=model)

self.assertEqual(params['Id'], 'ABC123')
self.assertEqual(params['HostedZoneId'], 'ABC123')
Expand All @@ -189,6 +231,22 @@ def test_route53_resource_id(self):
# This one should have been left alone
self.assertEqual(params['Other'], '/hostedzone/foo')

def test_route53_resource_id_missing_input_shape(self):
event = self.session.create_event(
'before-parameter-build', 'route53', 'GetHostedZone')
params = {'HostedZoneId': '/hostedzone/ABC123',}
operation_def = {
'name': 'GetHostedZone'
}
service_def = {
'metadata': {},
'shapes': {}
}
model = OperationModel(operation_def, ServiceModel(service_def))
self.session.emit(event, params=params, model=model)

self.assertEqual(params['HostedZoneId'], '/hostedzone/ABC123')

def test_fix_s3_host_initial(self):
endpoint = mock.Mock(region_name='us-west-2')
request = AWSRequest(
Expand Down

0 comments on commit a3d1128

Please sign in to comment.