-
Notifications
You must be signed in to change notification settings - Fork 10
/
account_authorization_details.py
32 lines (24 loc) · 1.07 KB
/
account_authorization_details.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Print authorization details of User, Role, Group, LocalManagedPolicy, and/or AWSManagedPolicy in account(s).
"""
import click
import logging
import yaml
from helper.aws import AwsApiHelper
logging.getLogger().setLevel(logging.DEBUG)
CHOICES = ["User", "Role", "Group", "LocalManagedPolicy", "AWSManagedPolicy"]
class Helper(AwsApiHelper):
def process_request(self, session, account_id, region, kwargs):
paginator = session.client("iam").get_paginator("get_account_authorization_details")
for page in paginator.paginate(**kwargs):
for k, v in page.items():
if v and k not in ["ResponseMetadata", "IsTruncated"]:
print(yaml.dump(page[k]))
@click.command()
@click.option("--filter", "-f", type=click.Choice(CHOICES, case_sensitive=False))
@click.option("--profile", "-p", help="AWS profile name. Use profiles in ~/.aws if not specified.")
def main(filter, profile):
kwargs = {"Filter": [filter]} if filter else {}
Helper().start(profile, "ap-southeast-2", "iam", kwargs)
if __name__ == "__main__":
main()