From ea92a52d72f651d4bec4ecea2449e90325d48c9e Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Tue, 27 Oct 2015 16:48:25 -0700 Subject: [PATCH 1/2] Add backcompat args for argument renames In boto/botocore#703, there were some correction made to the CamelCase->snake_case conversions. However, in the CLI, we still need to support these arguments. This fix for this is to: * Add a copy of the correct arg into the arg table with the "wrong" name. * Mark the "wrong" name entry as undocumented. There were no unit tests for this module, so I added a few. I also added some functional tests for some (but not all) the rename cases, just to ensure the end to end functionality is working as we expect. --- awscli/customizations/argrename.py | 25 +++++++++++ awscli/customizations/utils.py | 20 +++++++++ tests/functional/cognito_identity/__init__.py | 12 +++++ .../test_create_identity_pool.py | 44 ++++++++++++++++++ tests/functional/storagegateway/__init__.py | 12 +++++ .../storagegateway/test_describe_tapes.py | 42 +++++++++++++++++ tests/unit/customizations/test_argrename.py | 45 +++++++++++++++++++ 7 files changed, 200 insertions(+) create mode 100644 tests/functional/cognito_identity/__init__.py create mode 100644 tests/functional/cognito_identity/test_create_identity_pool.py create mode 100644 tests/functional/storagegateway/__init__.py create mode 100644 tests/functional/storagegateway/test_describe_tapes.py create mode 100644 tests/unit/customizations/test_argrename.py diff --git a/awscli/customizations/argrename.py b/awscli/customizations/argrename.py index e39be2a0f09c..08d65bfb0422 100644 --- a/awscli/customizations/argrename.py +++ b/awscli/customizations/argrename.py @@ -44,12 +44,30 @@ 'codepipeline.delete-custom-action-type.version': 'action-version', } +# Same format as ARGUMENT_RENAMES, but instead of renaming the arguments, +# an alias is created to the original arugment and marked as undocumented. +# This is useful when you need to change the name of an argument but you +# still need to support the old argument. +HIDDEN_ALIASES = { + 'cognito-identity.create-identity-pool.open-id-connect-provider-arns': + 'open-id-connect-provider-ar-ns', + 'storagegateway.describe-tapes.tape-arns': 'tape-ar-ns', + 'storagegateway.describe-tape-archives.tape-arns': 'tape-ar-ns', + 'storagegateway.describe-vtl-devices.vtl-device-arns': 'vtl-device-ar-ns', + 'storagegateway.describe-cached-iscsi-volumes.volume-arns': 'volume-ar-ns', + 'storagegateway.describe-stored-iscsi-volumes.volume-arns': 'volume-ar-ns', +} + def register_arg_renames(cli): for original, new_name in ARGUMENT_RENAMES.items(): event_portion, original_arg_name = original.rsplit('.', 1) cli.register('building-argument-table.%s' % event_portion, rename_arg(original_arg_name, new_name)) + for original, new_name in HIDDEN_ALIASES.items(): + event_portion, original_arg_name = original.rsplit('.', 1) + cli.register('building-argument-table.%s' % event_portion, + hidden_alias(original_arg_name, new_name)) def rename_arg(original_arg_name, new_name): @@ -57,3 +75,10 @@ def _rename_arg(argument_table, **kwargs): if original_arg_name in argument_table: utils.rename_argument(argument_table, original_arg_name, new_name) return _rename_arg + + +def hidden_alias(original_arg_name, alias_name): + def _alias_arg(argument_table, **kwargs): + if original_arg_name in argument_table: + utils.make_hidden_alias(argument_table, original_arg_name, alias_name) + return _alias_arg diff --git a/awscli/customizations/utils.py b/awscli/customizations/utils.py index 746a72b0780e..c962bc0f3247 100644 --- a/awscli/customizations/utils.py +++ b/awscli/customizations/utils.py @@ -14,6 +14,7 @@ Utility functions to make it easier to work with customizations. """ +import copy from botocore.exceptions import ClientError @@ -25,6 +26,25 @@ def rename_argument(argument_table, existing_name, new_name): del argument_table[existing_name] +def make_hidden_alias(argument_table, existing_name, alias_name): + """Create a hidden alias for an existing argument. + + This will copy an existing argument object in an arg table, + and add a new entry to the arg table with a different name. + The new argument will also be undocumented. + + This is needed if you want to check an existing argument, + but you still need the other one to work for backwards + compatibility reasons. + + """ + current = argument_table[existing_name] + copy_arg = copy.copy(current) + copy_arg._UNDOCUMENTED = True + copy_arg.name = alias_name + argument_table[alias_name] = copy_arg + + def rename_command(command_table, existing_name, new_name): current = command_table[existing_name] command_table[new_name] = current diff --git a/tests/functional/cognito_identity/__init__.py b/tests/functional/cognito_identity/__init__.py new file mode 100644 index 000000000000..d16f112a1849 --- /dev/null +++ b/tests/functional/cognito_identity/__init__.py @@ -0,0 +1,12 @@ +# Copyright 2015 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. diff --git a/tests/functional/cognito_identity/test_create_identity_pool.py b/tests/functional/cognito_identity/test_create_identity_pool.py new file mode 100644 index 000000000000..5710e67d46a3 --- /dev/null +++ b/tests/functional/cognito_identity/test_create_identity_pool.py @@ -0,0 +1,44 @@ +# Copyright 2015 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 awscli.testutils import BaseAWSCommandParamsTest + + +class TestCreateIdentityPool(BaseAWSCommandParamsTest): + + PREFIX = 'cognito-identity create-identity-pool' + + def test_accepts_old_argname(self): + cmdline = ( + self.PREFIX + ' --identity-pool-name foo ' + '--allow-unauthenticated-identities ' + + '--open-id-connect-provider-ar-ns aaaabbbbccccddddeeee' + ) + params = { + 'AllowUnauthenticatedIdentities': True, + 'IdentityPoolName': 'foo', + 'OpenIdConnectProviderARNs': ['aaaabbbbccccddddeeee'] + } + self.assert_params_for_cmd(cmdline, params) + + def test_accepts_fixed_param_name(self): + cmdline = ( + self.PREFIX + ' --identity-pool-name foo ' + '--allow-unauthenticated-identities ' + + '--open-id-connect-provider-arns aaaabbbbccccddddeeee' + ) + params = { + 'AllowUnauthenticatedIdentities': True, + 'IdentityPoolName': 'foo', + 'OpenIdConnectProviderARNs': ['aaaabbbbccccddddeeee'] + } + self.assert_params_for_cmd(cmdline, params) diff --git a/tests/functional/storagegateway/__init__.py b/tests/functional/storagegateway/__init__.py new file mode 100644 index 000000000000..d16f112a1849 --- /dev/null +++ b/tests/functional/storagegateway/__init__.py @@ -0,0 +1,12 @@ +# Copyright 2015 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. diff --git a/tests/functional/storagegateway/test_describe_tapes.py b/tests/functional/storagegateway/test_describe_tapes.py new file mode 100644 index 000000000000..0990a2275fee --- /dev/null +++ b/tests/functional/storagegateway/test_describe_tapes.py @@ -0,0 +1,42 @@ +# Copyright 2015 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 awscli.testutils import BaseAWSCommandParamsTest + + +class TestDescribeTapes(BaseAWSCommandParamsTest): + + PREFIX = 'storagegateway describe-tapes' + + def test_accepts_old_argname(self): + foo_arn = 'a' * 50 + bar_arn = 'b' * 50 + cmdline = ( + self.PREFIX + ' --gateway-arn %s --tape-ar-ns %s' + ) % (foo_arn, bar_arn) + params = { + 'GatewayARN': foo_arn, + 'TapeARNs': [bar_arn], + } + self.assert_params_for_cmd(cmdline, params) + + def test_accepts_fixed_param_name(self): + foo_arn = 'a' * 50 + bar_arn = 'b' * 50 + cmdline = ( + self.PREFIX + ' --gateway-arn %s --tape-arns %s' + ) % (foo_arn, bar_arn) + params = { + 'GatewayARN': foo_arn, + 'TapeARNs': [bar_arn], + } + self.assert_params_for_cmd(cmdline, params) diff --git a/tests/unit/customizations/test_argrename.py b/tests/unit/customizations/test_argrename.py new file mode 100644 index 000000000000..2d41a5b99e27 --- /dev/null +++ b/tests/unit/customizations/test_argrename.py @@ -0,0 +1,45 @@ +# Copyright 2015 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 awscli.testutils import unittest +from awscli.customizations import argrename +from awscli.customizations import arguments + +from botocore import model + + +class TestArgumenManipulations(unittest.TestCase): + def setUp(self): + self.argument_table = {} + + def test_can_rename_argument(self): + arg = arguments.CustomArgument('foo') + self.argument_table['foo'] = arg + handler = argrename.rename_arg('foo', 'bar') + handler(self.argument_table) + + self.assertIn('bar', self.argument_table) + self.assertNotIn('foo', self.argument_table) + self.assertEqual(arg.name, 'bar') + + def test_can_alias_an_argument(self): + arg = arguments.CustomArgument( + 'foo', dest='foo', + argument_model=model.Shape('FooArg', {'type': 'string'})) + self.argument_table['foo'] = arg + handler = argrename.hidden_alias('foo', 'alias-name') + + handler(self.argument_table) + + self.assertIn('alias-name', self.argument_table) + self.assertIn('foo', self.argument_table) + self.assertEqual(self.argument_table['alias-name'].name, 'alias-name') From a960a2d25c891b1d69a61bc3474ec22756203405 Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Tue, 27 Oct 2015 16:55:21 -0700 Subject: [PATCH 2/2] Add issue to changelog --- CHANGELOG.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c248e8da92ef..c3b316693968 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,8 +4,15 @@ CHANGELOG Next Release (TBD) ================== + * bugfix:``aws s3``: Fix some local path validation issues (`issue 1575 `__) +* bugfix:``aws storagegateway``: Fix ``--tape-ar-ns``, + ``--volume-ar-ns``, and ``--vtl-device-ar-ns`` to + ``--tape-arns``, ``--volume-arns``, and ``--vtl-device-arns``, + respectively. The old arguments are still supported for backwards + compatibility, but are no longer documented. + (`issue 1599 `__) 1.9.1