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 keys_attr parameter to aws_kms_info #648

Merged
merged 1 commit into from
Aug 10, 2021
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
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`` parameter 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