Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 4afb3dd

Browse files
chilangtoastdriven
authored andcommitted
fix serialization of parameter of type map
1 parent ffc6cc0 commit 4afb3dd

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

boto/sns/connection.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
7171
security_token=security_token,
7272
validate_certs=validate_certs)
7373

74+
def _build_dict_as_list_params(self, params, dictionary, name):
75+
"""
76+
Serialize a parameter 'name' which value is a 'dictionary' into a list of parameters.
77+
78+
See: http://docs.aws.amazon.com/sns/latest/api/API_SetPlatformApplicationAttributes.html
79+
For example::
80+
81+
dictionary = {'PlatformPrincipal': 'foo', 'PlatformCredential': 'bar'}
82+
name = 'Attributes'
83+
84+
would result in params dict being populated with:
85+
Attributes.entry.1.key = PlatformPrincipal
86+
Attributes.entry.1.value = foo
87+
Attributes.entry.2.key = PlatformCredential
88+
Attributes.entry.2.value = bar
89+
90+
:param params: the resulting parameters will be added to this dict
91+
:param dictionary: dict - value of the serialized parameter
92+
:param name: name of the serialized parameter
93+
"""
94+
for kv, index in zip(dictionary.items(), range(1, len(dictionary.items())+1)):
95+
key, value = kv
96+
prefix = '%s.entry.%s' % (name, index)
97+
params['%s.key' % prefix] = key
98+
params['%s.value' % prefix] = value
99+
74100
def _required_auth_capability(self):
75101
return ['hmac-v4']
76102

@@ -406,7 +432,7 @@ def create_platform_application(self, name=None, platform=None,
406432
if platform is not None:
407433
params['Platform'] = platform
408434
if attributes is not None:
409-
params['Attributes'] = attributes
435+
self._build_dict_as_list_params(params, attributes, 'Attributes')
410436
return self._make_request(action='CreatePlatformApplication',
411437
params=params)
412438

@@ -453,7 +479,7 @@ def set_platform_application_attributes(self,
453479
if platform_application_arn is not None:
454480
params['PlatformApplicationArn'] = platform_application_arn
455481
if attributes is not None:
456-
params['Attributes'] = attributes
482+
self._build_dict_as_list_params(params, attributes, 'Attributes')
457483
return self._make_request(action='SetPlatformApplicationAttributes',
458484
params=params)
459485

@@ -601,7 +627,7 @@ def create_platform_endpoint(self, platform_application_arn=None,
601627
if custom_user_data is not None:
602628
params['CustomUserData'] = custom_user_data
603629
if attributes is not None:
604-
params['Attributes'] = attributes
630+
self._build_dict_as_list_params(params, attributes, 'Attributes')
605631
return self._make_request(action='CreatePlatformEndpoint',
606632
params=params)
607633

@@ -654,7 +680,7 @@ def set_endpoint_attributes(self, endpoint_arn=None, attributes=None):
654680
if endpoint_arn is not None:
655681
params['EndpointArn'] = endpoint_arn
656682
if attributes is not None:
657-
params['Attributes'] = attributes
683+
self._build_dict_as_list_params(params, attributes, 'Attributes')
658684
return self._make_request(action='SetEndpointAttributes',
659685
params=params)
660686

0 commit comments

Comments
 (0)