@@ -11,6 +11,7 @@ import KMS, {
1111 KeyMetadata ,
1212 ListKeysRequest ,
1313 ListKeysResponse ,
14+ GrantListEntry
1415} from 'aws-sdk/clients/kms'
1516
1617import { TagMap } from '../../types'
@@ -35,6 +36,7 @@ export type AwsKms = KeyListEntry &
3536 Tags : TagMap
3637 keyRotationEnabled : boolean
3738 Aliases ?: AliasListEntry [ ]
39+ Grants ?: GrantListEntry [ ]
3840 }
3941
4042export default async ( {
@@ -53,6 +55,7 @@ export default async ({
5355 const policyPromises = [ ]
5456 const tagPromises = [ ]
5557 const aliasesPromises = [ ]
58+ const grantsPromises = [ ]
5659
5760 /**
5861 * Step 1) for all regions, list the kms keys
@@ -373,11 +376,43 @@ export default async ({
373376 resolveAliases ( )
374377 } )
375378 )
376-
377379 aliasesPromises . push ( aliasesPromise )
380+
381+ const grantsPromise = new Promise < void > ( resolveGrants =>
382+ kms . listGrants ( { KeyId } , ( err , data ) => {
383+ if ( err ) {
384+ errorLog . generateAwsErrorLog ( {
385+ functionName : 'kms:listGrants' ,
386+ err,
387+ } )
388+ resolveGrants ( )
389+ }
390+
391+ /**
392+ * No grants data
393+ */
394+
395+ if ( isEmpty ( data ) ) {
396+ return resolveGrants ( )
397+ }
398+
399+ /**
400+ * Add the grants to the key
401+ */
402+
403+ const { Grants : grants } = data || { }
404+
405+ kmsData [ idx ] . Grants = grants
406+
407+ resolveGrants ( )
408+ } )
409+ )
410+
411+ grantsPromises . push ( grantsPromise )
378412 } )
379413
380414 await Promise . all ( aliasesPromises )
415+ await Promise . all ( grantsPromises )
381416 errorLog . reset ( )
382417
383418 resolve ( groupBy ( kmsData , 'region' ) )
0 commit comments