@@ -9,7 +9,6 @@ import IAM, {
99 GetAccountAuthorizationDetailsResponse ,
1010 GetRoleResponse ,
1111 ListAttachedRolePoliciesResponse ,
12- ListRolePoliciesResponse ,
1312 ListRolesResponse ,
1413 ListRoleTagsResponse ,
1514 Role ,
@@ -44,8 +43,7 @@ export interface RawAwsIamRole extends Omit<Role, 'Tags'> {
4443 region : string
4544 Tags ?: TagMap
4645 PermissionsBoundaryArn : string
47- InlinePoliciesName : string [ ]
48- InlinePoliciesDocuments : string [ ]
46+ InlinePolicies : Array < { name : string ; document : string } >
4947}
5048
5149const roleByRoleName = async (
@@ -103,32 +101,6 @@ const tagsByRoleName = async (
103101 )
104102 } )
105103
106- const policiesByRoleName = async (
107- iam : IAM ,
108- { RoleName } : Role
109- ) : Promise < { RoleName : string ; Policies : string [ ] } > =>
110- new Promise ( resolve => {
111- iam . listRolePolicies (
112- { RoleName } ,
113- ( err : AWSError , data : ListRolePoliciesResponse ) => {
114- if ( err ) {
115- errorLog . generateAwsErrorLog ( {
116- functionName : 'iam:listRolePolicies' ,
117- err,
118- } )
119- }
120-
121- if ( ! isEmpty ( data ) ) {
122- const { PolicyNames = [ ] } = data
123-
124- resolve ( { RoleName, Policies : PolicyNames } )
125- }
126-
127- resolve ( null )
128- }
129- )
130- } )
131-
132104const managedPoliciesByRoleName = async (
133105 iam : IAM ,
134106 { RoleName } : Role
@@ -196,7 +168,6 @@ export const listIamRoles = async ({
196168} ) : Promise < RawAwsIamRole [ ] > =>
197169 new Promise ( resolve => {
198170 const result : RawAwsIamRole [ ] = [ ]
199- const policiesByRoleNamePromises = [ ]
200171 const tagsByRoleNamePromises = [ ]
201172 const managedPoliciesByRoleNamePromises = [ ]
202173 const roleByRoleNamePromises : Promise < { RoleName : string ; Role : Role } > [ ] =
@@ -216,15 +187,13 @@ export const listIamRoles = async ({
216187
217188 roles . map ( role => {
218189 tagsByRoleNamePromises . push ( tagsByRoleName ( iam , role ) )
219- policiesByRoleNamePromises . push ( policiesByRoleName ( iam , role ) )
220190 managedPoliciesByRoleNamePromises . push (
221191 managedPoliciesByRoleName ( iam , role )
222192 )
223193 roleByRoleNamePromises . push ( roleByRoleName ( iam , role ) )
224194 } )
225195
226196 const tags = await Promise . all ( tagsByRoleNamePromises )
227- const policies = await Promise . all ( policiesByRoleNamePromises )
228197 const managedPolicies = await Promise . all (
229198 managedPoliciesByRoleNamePromises
230199 )
@@ -249,11 +218,6 @@ export const listIamRoles = async ({
249218 RoleLastUsed : detailedRoles ?. find (
250219 r => r ?. RoleName === RoleName
251220 ) ?. Role . RoleLastUsed ,
252- InlinePoliciesName :
253- policies
254- ?. filter ( p => p ?. RoleName === RoleName )
255- . map ( p => p . Policies )
256- . reduce ( ( current , acc ) => [ ...acc , ...current ] , [ ] ) || [ ] ,
257221 ManagedPolicies :
258222 managedPolicies
259223 ?. filter ( p => p ?. RoleName === RoleName )
@@ -262,9 +226,12 @@ export const listIamRoles = async ({
262226 Tags : tags . find ( t => t ?. RoleName === RoleName ) ?. Tags || { } ,
263227 PermissionsBoundaryArn :
264228 PermissionsBoundary . PermissionsBoundaryArn ,
265- InlinePoliciesDocuments : roleAuthorizationDetails
229+ InlinePolicies : roleAuthorizationDetails
266230 . find ( rAD => rAD . RoleName === RoleName )
267- . RolePolicyList . map ( rPl => rPl . PolicyDocument ) ,
231+ . RolePolicyList . map ( rPl => ( {
232+ name : rPl . PolicyName ,
233+ document : rPl . PolicyDocument ,
234+ } ) ) ,
268235 }
269236 }
270237 )
0 commit comments