Debian Codegraph @

ansible_collections/amazon/aws/plugins/modules/iam_access_key_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2021 Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r"""
8 ---
9 module: iam_access_key_info
10 version_added: 2.1.0
11 version_added_collection: community.aws
12 short_description: fetch information about AWS IAM User access keys
13 description:
14 - Fetches information AWS IAM user access keys.
15 - 'Note: It is not possible to fetch the secret access key.'
16 author:
17 - Mark Chappell (@tremble)
18 options:
19 user_name:
20 description:
21 - The name of the IAM User to which the keys belong.
22 required: true
23 type: str
24 aliases: ['username']
25
26 extends_documentation_fragment:
27 - amazon.aws.common.modules
28 - amazon.aws.region.modules
29 - amazon.aws.boto3
30 """
31
32 EXAMPLES = r"""
33 # Note: These examples do not set authentication details, see the AWS Guide for details.
34
35 - name: Fetch Access keys for a user
36 amazon.aws.iam_access_key_info:
37 user_name: example_user
38 """
39
40 RETURN = r"""
41 access_key:
42 description: A dictionary containing all the access key information.
43 returned: When the key exists.
44 type: list
45 elements: dict
46 contains:
47 access_key_id:
48 description: The ID for the access key.
49 returned: success
50 type: str
51 sample: AKIA1EXAMPLE1EXAMPLE
52 create_date:
53 description: The date and time, in ISO 8601 date-time format, when the access key was created.
54 returned: success
55 type: str
56 sample: "2021-10-09T13:25:42+00:00"
57 user_name:
58 description: The name of the IAM user to which the key is attached.
59 returned: success
60 type: str
61 sample: example_user
62 status:
63 description:
64 - The status of the key.
65 - C(Active) means it can be used.
66 - C(Inactive) means it can not be used.
67 returned: success
68 type: str
69 sample: Inactive
70 """
71
72 from ansible_collections.amazon.aws.plugins.module_utils.iam import AnsibleIAMError
73 from ansible_collections.amazon.aws.plugins.module_utils.iam import get_iam_access_keys
74 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
75 from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
76
77
78 def main():
79 argument_spec = dict(
80 user_name=dict(required=True, type="str", aliases=["username"]),
81 )
82
83 module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
84
85 client = module.client("iam", retry_decorator=AWSRetry.jittered_backoff())
86
87 try:
88 access_keys = get_iam_access_keys(client, module.params.get("user_name"))
89 module.exit_json(changed=False, access_keys=access_keys)
90 except AnsibleIAMError as e:
91 module.fail_json_aws_error(e)
92
93
94 if __name__ == "__main__":
95 main()