UPD: updated iam-last-activity.py and removed hard-coded account id
This commit is contained in:
parent
68761f216a
commit
b1af2b9d1b
@ -10,7 +10,7 @@ from jmespath.exceptions import JMESPathTypeError
|
||||
|
||||
# dump user/group/role last activity
|
||||
|
||||
def generateLastAccessed(myclient, arn, myAccountId: str):
|
||||
def generateLastAccessed(myclient, arn, myAccountId):
|
||||
response = myclient.generate_service_last_accessed_details(
|
||||
Arn=arn,
|
||||
Granularity='SERVICE_LEVEL')
|
||||
@ -28,13 +28,15 @@ def generateLastAccessed(myclient, arn, myAccountId: str):
|
||||
ServiceNamespaces=jmespath.search("ServicesLastAccessed[*].ServiceNamespace", accessDetails)
|
||||
)
|
||||
returnString = []
|
||||
try:
|
||||
for p in jmespath.search(
|
||||
f"PoliciesGrantingServiceAccess[*].Policies[?contains(PolicyArn,'${myAccountId}')].PolicyArn", r2):
|
||||
if len(p) > 0:
|
||||
returnString.append(p[0])
|
||||
except JMESPathTypeError:
|
||||
pass
|
||||
# try:
|
||||
for p in jmespath.search("PoliciesGrantingServiceAccess[*].Policies[]", r2):
|
||||
if p.get("PolicyType") == "INLINE":
|
||||
returnString.append("INLINE:" + p.get("PolicyName"))
|
||||
else:
|
||||
if myAccountId in p.get("PolicyArn"):
|
||||
returnString.append(p.get("PolicyArn"))
|
||||
# except JMESPathTypeError:
|
||||
# pass
|
||||
return list(dict.fromkeys(returnString))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user