Skip to content
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

Add backcompat args for argument renames #1599

Merged
merged 2 commits into from
Oct 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ CHANGELOG

Next Release (TBD)
==================

* bugfix:``aws s3``: Fix some local path validation issues
(`issue 1575 <https://github.com/aws/aws-cli/pull/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 <https://github.com/aws/aws-cli/pull/1599>`__)


1.9.1
Expand Down
25 changes: 25 additions & 0 deletions awscli/customizations/argrename.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,41 @@
'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):
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
20 changes: 20 additions & 0 deletions awscli/customizations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Utility functions to make it easier to work with customizations.

"""
import copy

from botocore.exceptions import ClientError

Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/cognito_identity/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
44 changes: 44 additions & 0 deletions tests/functional/cognito_identity/test_create_identity_pool.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions tests/functional/storagegateway/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 42 additions & 0 deletions tests/functional/storagegateway/test_describe_tapes.py
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions tests/unit/customizations/test_argrename.py
Original file line number Diff line number Diff line change
@@ -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')