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

returns boolean if a user has access to console login #2012

Merged
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 3 additions & 0 deletions changelogs/fragments/20240321-iam-user-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- iam_user_info - Add ``login_profile`` to return info that is get from a user, to know if they can login from AWS console (https://github.com/ansible-collections/amazon.aws/pull/2012).
15 changes: 15 additions & 0 deletions plugins/modules/iam_user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,27 @@
type: dict
returned: if user exists
sample: '{"Env": "Prod"}'
login_profile:
description: Detailed login profile information if the user has access to log in from AWS default console. Returns an empty object {} if no access.
returned: always
type: dict
sample: {"create_date": "2024-03-20T12:50:56+00:00", "password_reset_required": false, "user_name": "i_am_a_user"}
"""

from ansible_collections.amazon.aws.plugins.module_utils.iam import AnsibleIAMError
valkiriaaquatica marked this conversation as resolved.
Show resolved Hide resolved
from ansible_collections.amazon.aws.plugins.module_utils.iam import IAMErrorHandler
from ansible_collections.amazon.aws.plugins.module_utils.iam import get_iam_group
from ansible_collections.amazon.aws.plugins.module_utils.iam import get_iam_user
from ansible_collections.amazon.aws.plugins.module_utils.iam import list_iam_users
from ansible_collections.amazon.aws.plugins.module_utils.iam import normalize_iam_user
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry


@IAMErrorHandler.list_error_handler("get login profile", {})
@AWSRetry.jittered_backoff()
def check_console_access(connection, user_name):
return connection.get_login_profile(UserName=user_name)['LoginProfile']


def _list_users(connection, name, group, path):
Expand All @@ -136,6 +149,8 @@ def _list_users(connection, name, group, path):
def list_users(connection, name, group, path):
users = _list_users(connection, name, group, path)
users = [u for u in users if u is not None]
for user in users:
user['LoginProfile'] = check_console_access(connection, user['UserName'])
return [normalize_iam_user(user) for user in users]


Expand Down
Loading