Skip to content

Commit

Permalink
Add keys_attr parameter to aws_kms_info
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Aug 7, 2021
1 parent 60aa1c7 commit d2e2707
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/648-kms_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minor_changes:
- kms_info - added a new ``keys_attr`` to continue returning the key details in the ``keys`` attribute as well as the ``kms_keys`` attribute (https://github.com/ansible-collections/community.aws/pull/648).
breaking_changes:
- kms_info - key details are now returned in the ``kms_keys`` attribute rather than the ``keys`` attribute (https://github.com/ansible-collections/community.aws/pull/648).
26 changes: 24 additions & 2 deletions plugins/modules/aws_kms_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
description: Whether to get full details (tags, grants etc.) of keys pending deletion
default: False
type: bool
keys_attr:
description:
- Whether to return the results in the C(keys) attribute as well as the
C(kms_keys) attribute.
- Returning the C(keys) attribute conflicts with the builtin keys()
method on dictionaries and as such has been deprecated.
- After version C(3.0.0) this parameter will do nothing, and after
version C(4.0.0) this parameter will be removed.
type: bool
default: True
version_added: 2.0.0
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2
Expand All @@ -70,7 +81,7 @@
'''

RETURN = '''
keys:
kms_keys:
description: list of keys
type: complex
returned: always
Expand Down Expand Up @@ -441,6 +452,7 @@ def main():
key_id=dict(aliases=['key_arn']),
filters=dict(type='dict'),
pending_deletion=dict(type='bool', default=False),
keys_attr=dict(type='bool', default=True),
)

module = AnsibleAWSModule(argument_spec=argument_spec,
Expand All @@ -455,7 +467,17 @@ def main():
module.fail_json_aws(e, msg='Failed to connect to AWS')

all_keys = get_kms_info(connection, module)
module.exit_json(keys=[key for key in all_keys if key_matches_filters(key, module.params['filters'])])
filtered_keys = [key for key in all_keys if key_matches_filters(key, module.params['filters'])]
ret_params = dict(kms_keys=filtered_keys)

# We originally returned "keys"
if module.params['keys_attr']:
module.deprecate("Returning results in the 'keys' attribute conflicts with the builtin keys() method on "
"dicts and as such is deprecated. Please use the kms_keys attribute. This warning can be "
"silenced by setting keys_attr to False.",
version='3.0.0', collection_name='community.aws')
ret_params.update(dict(keys=filtered_keys))
module.exit_json(**ret_params)


if __name__ == '__main__':
Expand Down

0 comments on commit d2e2707

Please sign in to comment.