Skip to content

Commit

Permalink
Have only one format of return value
Browse files Browse the repository at this point in the history
'dict' was chosen
  • Loading branch information
fotto committed Feb 28, 2021
1 parent ed17058 commit b11fcb8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
46 changes: 26 additions & 20 deletions plugins/modules/mq_user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,39 @@


EXAMPLES = '''
# Note: These examples do not set authentication details, see the AWS Guide for details.
# or check tests/integration/targets/mq/tasks/test_mq_user_info.yml
- name: get all users as list
- name: get all users as list - relying on environment for API credentials
amazon.aws.mq_user_info:
broker_id: "aws-mq-broker-id"
max_results: 1000
max_results: 50
region: "{{ aws_region }}"
register: result
- name: show number of users retrieved
debug:
msg: "{{ result.users | length }}"
- name: get users as dict - relying on default limit
- name: get users as dict - explicitly specifying all credentials
amazon.aws.mq_user_info:
broker_id: "aws-mq-broker-id"
as_dict: true
region: "{{ aws_region }}"
aws_access_key: "{{ aws_access_key_id }}"
aws_secret_key: "{{ aws_secret_access_key }}"
security_token: "{{ aws_session_token }}"
register: result
- name: check if some specific user exists
debug:
msg: "user sample_user1 exists"
when: "'sample_user1' in result.users"
- name: get list of users to decide which may need to be deleted
amazon.aws.mq_user_info:
broker_id: "aws-mq-broker-id"
skip_pending_delete: true
region: "{{ aws_region }}"
- name: get list of users to decide which may need to be created
amazon.aws.mq_user_info:
broker_id: "aws-mq-broker-id"
skip_pending_create: true
region: "{{ aws_region }}"
'''

RETURN = '''
user:
users:
type: dict
returned: success
description:
- list of users as array or as dict keyed by username (if as_dict=true)
- each elements/entry are 1:1 those from the 'Users' list in the API response of list_users()
- dict key is username
- each entry is the record for a user as returned by API
'''

try:
Expand All @@ -99,7 +104,8 @@
DEFAULTS = {
'max_results': 100,
'skip_pending_create': False,
'skip_pending_delete': False
'skip_pending_delete': False,
'as_dict': True
}


Expand All @@ -124,7 +130,7 @@ def get_user_info(conn, module):
#
records.append(record)
#
if module.params['as_dict']:
if DEFAULTS['as_dict']:
user_records = {}
for record in records:
user_records[record['Username']] = record
Expand All @@ -148,11 +154,11 @@ def main():
connection = module.client('mq')

try:
user_list = get_user_info(connection, module)
user_records = get_user_info(connection, module)
except botocore.exceptions.ClientError as e:
module.fail_json_aws(e)

module.exit_json(users=user_list)
module.exit_json(users=user_records)


if __name__ == '__main__':
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/targets/mq/tasks/test_mq_user_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
mq_user_info:
broker_id: "{{ broker_id }}"
region: "{{ aws_region }}"
as_dict: true
aws_access_key: "{{ aws_access_key_id }}"
aws_secret_key: "{{ aws_secret_access_key }}"
security_token: "{{ aws_session_token }}"
Expand All @@ -92,7 +91,6 @@
mq_user_info:
broker_id: "{{ broker_id }}"
region: "{{ aws_region }}"
as_dict: true
skip_pending_create: true
aws_access_key: "{{ aws_access_key_id }}"
aws_secret_key: "{{ aws_secret_access_key }}"
Expand All @@ -113,7 +111,6 @@
mq_user_info:
broker_id: "{{ broker_id }}"
region: "{{ aws_region }}"
as_dict: true
skip_pending_delete: true
aws_access_key: "{{ aws_access_key_id }}"
aws_secret_key: "{{ aws_secret_access_key }}"
Expand Down

0 comments on commit b11fcb8

Please sign in to comment.