/
c3mc-ec2create-describe-role-list
executable file
·55 lines (41 loc) · 1.33 KB
/
c3mc-ec2create-describe-role-list
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env /data/Software/mydan/python3/bin/python3
# -*- coding: utf-8 -*-
import sys
import json
import subprocess
import boto3
def list_roles(access_id, access_key, region):
"""
查询角色列表
"""
client = boto3.client(
"iam",
aws_access_key_id=access_id,
aws_secret_access_key=access_key,
region_name=region
)
page_size = 1000
result = []
response = client.list_roles(MaxItems=page_size)
result.extend(response["Roles"])
marker = response["Marker"] if "Marker" in response else ""
while marker != "":
response = client.list_roles(MaxItems=page_size, Marker=marker)
result.extend(response["Roles"])
marker = response["Marker"] if "Marker" in response else ""
return result
def main(params):
account = params["account"]
region = params["region"]
key_info = json.loads(
subprocess.getoutput(f"c3mc-get-account-info aws {account}")
)
role_list = list_roles(
key_info["access_id"], key_info["access_key"], region)
for role in role_list:
print(json.dumps(role, default=str))
if __name__ == '__main__':
l = list(sys.stdin)
if not l or len(l) > 1:
raise type('WrongInputData', (Exception,), {})('数据格式不对, 需要一行json字符串"')
main(json.loads(l[0]))