-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix an assumption in argprocess.py that all map types will have an enum of possible keys. #525
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,11 @@ | |
# language governing permissions and limitations under the License. | ||
"""Module for processing CLI args.""" | ||
import os | ||
import json | ||
import logging | ||
import six | ||
|
||
from botocore.compat import OrderedDict, json | ||
|
||
from awscli import utils | ||
from awscli import SCALAR_TYPES, COMPLEX_TYPES | ||
|
||
|
@@ -243,28 +244,31 @@ def _key_value_parse(self, param, value): | |
# that is, csv key value pairs, where the key and values | ||
# are separated by '='. All of this should be whitespace | ||
# insensitive. | ||
parsed = {} | ||
parsed = OrderedDict() | ||
parts = self._split_on_commas(value) | ||
valid_names = self._create_name_to_params(param) | ||
LOG.debug('valid_names=%s', valid_names) | ||
for part in parts: | ||
try: | ||
key, value = part.split('=', 1) | ||
except ValueError: | ||
raise ParamSyntaxError(part) | ||
key = key.strip() | ||
value = value.strip() | ||
if key not in valid_names: | ||
if valid_names and key not in valid_names: | ||
raise ParamUnknownKeyError(param, key, valid_names) | ||
sub_param = valid_names[key] | ||
if sub_param is not None: | ||
value = unpack_scalar_cli_arg(sub_param, value) | ||
if valid_names: | ||
sub_param = valid_names[key] | ||
if sub_param is not None: | ||
value = unpack_scalar_cli_arg(sub_param, value) | ||
parsed[key] = value | ||
LOG.debug('parsed=%s', parsed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug logs no longer needed? |
||
return parsed | ||
|
||
def _create_name_to_params(self, param): | ||
if param.type == 'structure': | ||
return dict([(p.name, p) for p in param.members]) | ||
elif param.type == 'map': | ||
elif param.type == 'map' and hasattr(param.keys, 'enum'): | ||
return dict([(v, None) for v in param.keys.enum]) | ||
|
||
def _docs_list_scalar_list_parse(self, param): | ||
|
@@ -351,7 +355,7 @@ def unpack_cli_arg(parameter, value): | |
def unpack_complex_cli_arg(parameter, value): | ||
if parameter.type == 'structure' or parameter.type == 'map': | ||
if value.lstrip()[0] == '{': | ||
d = json.loads(value) | ||
d = json.loads(value, object_pairs_hook=OrderedDict) | ||
else: | ||
msg = 'The value for parameter "%s" must be JSON or path to file.' % ( | ||
parameter.cli_name) | ||
|
@@ -360,11 +364,11 @@ def unpack_complex_cli_arg(parameter, value): | |
elif parameter.type == 'list': | ||
if isinstance(value, six.string_types): | ||
if value.lstrip()[0] == '[': | ||
return json.loads(value) | ||
return json.loads(value, object_pairs_hook=OrderedDict) | ||
elif isinstance(value, list) and len(value) == 1: | ||
single_value = value[0].strip() | ||
if single_value and single_value[0] == '[': | ||
return json.loads(value[0]) | ||
return json.loads(value[0], object_pairs_hook=OrderedDict) | ||
return [unpack_cli_arg(parameter.members, v) for v in value] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
from tests.unit import BaseAWSCommandParamsTest | ||
|
||
|
||
class TestCreatePlatformApplication(BaseAWSCommandParamsTest): | ||
|
||
prefix = 'sns create-platform-application' | ||
|
||
def test_gcm_shorthand(self): | ||
cmdline = self.prefix | ||
cmdline += ' --name gcmpushapp' | ||
cmdline += ' --platform GCM' | ||
cmdline += ' --attributes ' | ||
cmdline += 'PlatformCredential=foo,' | ||
cmdline += 'PlatformPrincipal=bar' | ||
result = {'Name': 'gcmpushapp', | ||
'Platform': 'GCM', | ||
'Attributes.entry.1.key': 'PlatformCredential', | ||
'Attributes.entry.1.value': 'foo', | ||
'Attributes.entry.2.key': 'PlatformPrincipal', | ||
'Attributes.entry.2.value': 'bar'} | ||
self.assert_params_for_cmd(cmdline, result) | ||
|
||
def test_gcm_json(self): | ||
cmdline = self.prefix | ||
cmdline += ' --name gcmpushapp' | ||
cmdline += ' --platform GCM' | ||
cmdline += ' --attributes ' | ||
cmdline += ('{"PlatformCredential":"AIzaSyClE2lcV2zEKTLYYo645zfk2jhQPFeyxDo",' | ||
'"PlatformPrincipal":"There+is+no+principal+for+GCM"}') | ||
result = {'Name': 'gcmpushapp', | ||
'Platform': 'GCM', | ||
'Attributes.entry.1.key': 'PlatformCredential', | ||
'Attributes.entry.1.value': 'AIzaSyClE2lcV2zEKTLYYo645zfk2jhQPFeyxDo', | ||
'Attributes.entry.2.key': 'PlatformPrincipal', | ||
'Attributes.entry.2.value': 'There+is+no+principal+for+GCM'} | ||
self.assert_params_for_cmd(cmdline, result) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug logs no longer needed?