UNPKG

@cloud-copilot/iam-lens

Version:

Visibility in IAM in and across AWS accounts

95 lines 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.saveManagedPolicy = saveManagedPolicy; exports.saveUser = saveUser; exports.saveRole = saveRole; exports.saveGroup = saveGroup; const iam_utils_1 = require("@cloud-copilot/iam-utils"); /** * Useful functions for unit tests. */ /** * Save a managed policy * * @param store the AWS IAM store * @param details the details of the managed policy */ async function saveManagedPolicy(store, details) { const name = details.arn.split('/').pop(); const accountId = (0, iam_utils_1.splitArnParts)(details.arn).accountId; await store.saveResourceMetadata(accountId, details.arn, 'metadata', { arn: details.arn, name, description: details.description }); await store.saveResourceMetadata(accountId, details.arn, 'current-policy', details.policy); } /** * Save a user for testing * * @param store the AWS IAM store * @param details the details of the user */ async function saveUser(store, details) { const name = details.arn.split('/').pop(); const accountId = (0, iam_utils_1.splitArnParts)(details.arn).accountId; const metadata = { arn: details.arn, id: `AIDAEXAMPLE${accountId}`, name, path: '/', created: '2024-01-01T00:00:00Z' }; if (details.permissionBoundary) { metadata.permissionBoundary = details.permissionBoundary; } await store.saveResourceMetadata(accountId, details.arn, 'metadata', metadata); await store.saveResourceMetadata(accountId, details.arn, 'managed-policies', details.managedPolicies); await store.saveResourceMetadata(accountId, details.arn, 'inline-policies', details.inlinePolicies); await store.saveResourceMetadata(accountId, details.arn, 'groups', details.groups); } /** * Save a role for testing * * @param store the AWS IAM store * @param details the details of the role */ async function saveRole(store, details) { const name = details.arn.split('/').pop(); const accountId = (0, iam_utils_1.splitArnParts)(details.arn).accountId; const metadata = { arn: details.arn, id: `AROAEXAMPLE${accountId}`, name, path: '/', created: '2024-01-01T00:00:00Z' }; if (details.permissionBoundary) { metadata.permissionBoundary = details.permissionBoundary; } await store.saveResourceMetadata(accountId, details.arn, 'metadata', metadata); await store.saveResourceMetadata(accountId, details.arn, 'managed-policies', details.managedPolicies); await store.saveResourceMetadata(accountId, details.arn, 'inline-policies', details.inlinePolicies); await store.saveResourceMetadata(accountId, details.arn, 'trust-policy', details.trustPolicy); } /** * Save a group for testing * * @param store the AWS IAM store * @param details the details of the group */ async function saveGroup(store, details) { const name = details.arn.split('/').pop(); const accountId = (0, iam_utils_1.splitArnParts)(details.arn).accountId; const metadata = { arn: details.arn, id: `AGPAEXAMPLE${accountId}`, name, path: '/', created: '2024-01-01T00:00:00Z' }; await store.saveResourceMetadata(accountId, details.arn, 'metadata', metadata); await store.saveResourceMetadata(accountId, details.arn, 'managed-policies', details.managedPolicies); await store.saveResourceMetadata(accountId, details.arn, 'inline-policies', details.inlinePolicies); } //# sourceMappingURL=testUtils.js.map