@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
37 lines • 1.55 kB
JavaScript
import { GetResourcePolicyCommand, GlueClient } from '@aws-sdk/client-glue';
import { AwsClientPool } from '../../aws/ClientPool.js';
import { runAndCatchError } from '../../utils/client-tools.js';
import { parseIfPresent } from '../../utils/json.js';
export const GlueCatalogSync = {
name: 'GlueCatalogSync',
awsService: 'glue',
execute: async (accountId, region, credentials, storage, endpoint, syncOptions) => {
const glueClient = AwsClientPool.defaultInstance.client(GlueClient, credentials, region, endpoint);
const policy = await runAndCatchError('EntityNotFoundException', async () => {
const result = await glueClient.send(new GetResourcePolicyCommand());
return parseIfPresent(result.PolicyInJson);
});
const arn = rootCatalogArn(credentials.partition, accountId, region);
if (policy) {
await storage.saveResourceMetadata(accountId, arn, 'policy', policy);
await storage.saveResourceMetadata(accountId, arn, 'metadata', {
arn
});
}
else {
await storage.deleteResource(accountId, arn);
}
}
};
/**
* Get the ARN for a root Glue catalog
*
* @param partition the partition (aws, aws-cn, aws-us-gov)
* @param accountId the account id
* @param region the region
* @returns the ARN for the root Glue catalog
*/
function rootCatalogArn(partition, accountId, region) {
return `arn:${partition}:glue:${region}:${accountId}:catalog`;
}
//# sourceMappingURL=catalogs.js.map