Skip to content

Commit

Permalink
Merge branch 'release-1.11.71'
Browse files Browse the repository at this point in the history
* release-1.11.71:
  Bumping version to 1.11.71
  Process json serializable arguments in the CLI
  Process json serializable arguments in the CLI
  Update changelog based on model updates
  • Loading branch information
AWS committed Apr 3, 2017
2 parents 385bb2f + 0cb9b08 commit abbaf55
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changes/1.11.71.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"category": "``lex-runtime``",
"description": "Update lex-runtime command to latest version",
"type": "api-change"
}
]
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
CHANGELOG
=========

1.11.71
=======

* api-change:``lex-runtime``: Update lex-runtime command to latest version


1.11.70
=======

Expand Down
2 changes: 1 addition & 1 deletion awscli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
import os

__version__ = '1.11.70'
__version__ = '1.11.71'

#
# Get our data path to be added to botocore's search path
Expand Down
24 changes: 22 additions & 2 deletions awscli/argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from awscli.paramfile import PARAMFILE_DISABLED
from awscli import shorthand
from awscli.utils import find_service_and_method_in_event_name

from botocore.utils import is_json_value_header

LOG = logging.getLogger('awscli.argprocess')

Expand Down Expand Up @@ -166,8 +166,19 @@ def unpack_cli_arg(cli_argument, value):
cli_argument.cli_name)


def _special_type(model):
# check if model is jsonvalue header and that value is serializable
if model.serialization.get('jsonvalue') and \
model.serialization.get('location') == 'header' and \
model.type_name == 'string':
return True
return False


def _unpack_cli_arg(argument_model, value, cli_name):
if argument_model.type_name in SCALAR_TYPES:
if is_json_value_header(argument_model):
return _unpack_json_cli_arg(argument_model, value, cli_name)
elif argument_model.type_name in SCALAR_TYPES:
return unpack_scalar_cli_arg(
argument_model, value, cli_name)
elif argument_model.type_name in COMPLEX_TYPES:
Expand All @@ -177,6 +188,15 @@ def _unpack_cli_arg(argument_model, value, cli_name):
return six.text_type(value)


def _unpack_json_cli_arg(argument_model, value, cli_name):
try:
return json.loads(value, object_pairs_hook=OrderedDict)
except ValueError as e:
raise ParamError(
cli_name, "Invalid JSON: %s\nJSON received: %s"
% (e, value))


def _unpack_complex_cli_arg(argument_model, value, cli_name):
type_name = argument_model.type_name
if type_name == 'structure' or type_name == 'map':
Expand Down
12 changes: 10 additions & 2 deletions awscli/clidocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from botocore import xform_name
from botocore.docs.bcdoc.docevents import DOC_EVENTS
from botocore.model import StringShape
from botocore.utils import is_json_value_header

from awscli import SCALAR_TYPES
from awscli.argprocess import ParamShorthandDocGen
Expand Down Expand Up @@ -43,6 +44,11 @@ def _build_arg_table_groups(self, help_command):
def build_translation_map(self):
return dict()

def _get_argument_type_name(self, shape, default):
if is_json_value_header(shape):
return 'JSON'
return default

def _map_handlers(self, session, event_class, mapfn):
for event in DOC_EVENTS:
event_handler_name = event.replace('-', '_')
Expand Down Expand Up @@ -160,7 +166,8 @@ def doc_option(self, arg_name, help_command, **kwargs):
self._documented_arg_groups.append(argument.group_name)
else:
name = '``%s``' % argument.cli_name
doc.write('%s (%s)\n' % (name, argument.cli_type_name))
doc.write('%s (%s)\n' % (name, self._get_argument_type_name(
argument.argument_model, argument.cli_type_name)))
doc.style.indent()
doc.include_doc_string(argument.documentation)
self._document_enums(argument, doc)
Expand Down Expand Up @@ -531,7 +538,8 @@ def _doc_member_for_output(self, doc, member_name, member_shape, stack):
def _do_doc_member_for_output(self, doc, member_name, member_shape, stack):
docs = member_shape.documentation
if member_name:
doc.write('%s -> (%s)' % (member_name, member_shape.type_name))
doc.write('%s -> (%s)' % (member_name, self._get_argument_type_name(
member_shape, member_shape.type_name)))
else:
doc.write('(%s)' % member_shape.type_name)
doc.style.indent()
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# The short X.Y version.
version = '1.11.'
# The full version, including alpha/beta/rc tags.
release = '1.11.70'
release = '1.11.71'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ universal = 1

[metadata]
requires-dist =
botocore==1.5.33
botocore==1.5.34
colorama>=0.2.5,<=0.3.7
docutils>=0.10
rsa>=3.1.2,<=3.5.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import awscli


requires = ['botocore==1.5.33',
requires = ['botocore==1.5.34',
'colorama>=0.2.5,<=0.3.7',
'docutils>=0.10',
'rsa>=3.1.2,<=3.5.0',
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/test_argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,5 +804,48 @@ def test_json_with_spaces(self):
self.assertIn('[{', str(e.exception))


class TestJSONValueHeaderParams(BaseArgProcessTest):
def setUp(self):
super(TestJSONValueHeaderParams, self).setUp()
self.p = self.get_param_model(
'lex-runtime.PostContent.sessionAttributes')

def test_json_value_dict(self):
value = '{"foo": "bar"}'
self.assertEqual(unpack_cli_arg(self.p, value),
OrderedDict([('foo', 'bar')]))

def test_json_value_list(self):
value = '["foo", "bar"]'
self.assertEqual(unpack_cli_arg(self.p, value), ['foo', 'bar'])

def test_json_value_int(self):
value = "5"
self.assertEqual(unpack_cli_arg(self.p, value), 5)

def test_json_value_float(self):
value = "1.2"
self.assertEqual(unpack_cli_arg(self.p, value), 1.2)

def test_json_value_string(self):
value = '"5"'
self.assertEqual(unpack_cli_arg(self.p, value), '5')

def test_json_value_boolean(self):
value = "true"
self.assertEqual(unpack_cli_arg(self.p, value), True)
value = "false"
self.assertEqual(unpack_cli_arg(self.p, value), False)

def test_json_value_null(self):
value = 'null'
self.assertEqual(unpack_cli_arg(self.p, value), None)

def test_json_value_decode_error(self):
value = 'invalid string to be serialized'
with self.assertRaises(ParamError):
unpack_cli_arg(self.p, value)


if __name__ == '__main__':
unittest.main()
21 changes: 21 additions & 0 deletions tests/unit/test_clidocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,27 @@ def test_breadcrumbs_wait_command_html(self):
' . :ref:`wait <cli:aws s3api wait>` ]')
)

def test_documents_json_header_shape(self):
shape = {
'type': 'string',
'jsonvalue': True,
'location': 'header',
'locationName': 'X-Amz-Header-Name'
}
shape = StringShape('JSONValueArg', shape)
arg_table = {'arg-name': mock.Mock(argument_model=shape)}
help_command = mock.Mock()
help_command.doc = ReSTDocument()
help_command.event_class = 'custom'
help_command.arg_table = arg_table
operation_model = mock.Mock()
operation_model.service_model.operation_names = []
help_command.obj = operation_model
operation_handler = OperationDocumentEventHandler(help_command)
operation_handler.doc_option('arg-name', help_command)
rendered = help_command.doc.getvalue().decode('utf-8')
self.assertIn('(JSON)', rendered)

def test_documents_enum_values(self):
shape = {
'type': 'string',
Expand Down

0 comments on commit abbaf55

Please sign in to comment.