@cloud-copilot/iam-collect 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -1
- package/dist/cjs/aws/ClientPool.d.ts +27 -0
- package/dist/cjs/aws/ClientPool.d.ts.map +1 -0
- package/dist/cjs/aws/ClientPool.js +52 -0
- package/dist/cjs/aws/ClientPool.js.map +1 -0
- package/dist/cjs/aws/auth.d.ts +16 -0
- package/dist/cjs/aws/auth.d.ts.map +1 -0
- package/dist/cjs/aws/auth.js +76 -0
- package/dist/cjs/aws/auth.js.map +1 -0
- package/dist/cjs/cli.js +46 -8
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/config/config.d.ts +22 -11
- package/dist/cjs/config/config.d.ts.map +1 -1
- package/dist/cjs/config/config.js +52 -7
- package/dist/cjs/config/config.js.map +1 -1
- package/dist/cjs/config/configFile.d.ts +16 -0
- package/dist/cjs/config/configFile.d.ts.map +1 -0
- package/dist/cjs/config/configFile.js +49 -0
- package/dist/cjs/config/configFile.js.map +1 -0
- package/dist/cjs/config/defaultConfig.d.ts.map +1 -1
- package/dist/cjs/config/defaultConfig.js +38 -1
- package/dist/cjs/config/defaultConfig.js.map +1 -1
- package/dist/cjs/download/download.d.ts +3 -0
- package/dist/cjs/download/download.d.ts.map +1 -0
- package/dist/cjs/download/download.js +67 -0
- package/dist/cjs/download/download.js.map +1 -0
- package/dist/cjs/persistence/AwsIamStore.d.ts +95 -0
- package/dist/cjs/persistence/AwsIamStore.d.ts.map +1 -0
- package/dist/cjs/persistence/AwsIamStore.js +3 -0
- package/dist/cjs/persistence/AwsIamStore.js.map +1 -0
- package/dist/cjs/persistence/file/FileSystemAdapter.d.ts +20 -0
- package/dist/cjs/persistence/file/FileSystemAdapter.d.ts.map +1 -0
- package/dist/cjs/persistence/file/FileSystemAdapter.js +77 -0
- package/dist/cjs/persistence/file/FileSystemAdapter.js.map +1 -0
- package/dist/cjs/persistence/file/FileSystemAwsIamStore.d.ts +19 -0
- package/dist/cjs/persistence/file/FileSystemAwsIamStore.d.ts.map +1 -0
- package/dist/cjs/persistence/file/FileSystemAwsIamStore.js +96 -0
- package/dist/cjs/persistence/file/FileSystemAwsIamStore.js.map +1 -0
- package/dist/cjs/persistence/util.d.ts +28 -0
- package/dist/cjs/persistence/util.d.ts.map +1 -0
- package/dist/cjs/persistence/util.js +46 -0
- package/dist/cjs/persistence/util.js.map +1 -0
- package/dist/cjs/regions.d.ts +3 -0
- package/dist/cjs/regions.d.ts.map +1 -0
- package/dist/cjs/regions.js +15 -0
- package/dist/cjs/regions.js.map +1 -0
- package/dist/cjs/services.d.ts +3 -0
- package/dist/cjs/services.d.ts.map +1 -0
- package/dist/cjs/services.js +5 -0
- package/dist/cjs/services.js.map +1 -0
- package/dist/cjs/syncs/iam/authorizationDetails.d.ts +104 -0
- package/dist/cjs/syncs/iam/authorizationDetails.d.ts.map +1 -0
- package/dist/cjs/syncs/iam/authorizationDetails.js +490 -0
- package/dist/cjs/syncs/iam/authorizationDetails.js.map +1 -0
- package/dist/cjs/syncs/lambda/lambda.d.ts +3 -0
- package/dist/cjs/syncs/lambda/lambda.d.ts.map +1 -0
- package/dist/cjs/syncs/lambda/lambda.js +54 -0
- package/dist/cjs/syncs/lambda/lambda.js.map +1 -0
- package/dist/cjs/syncs/sync.d.ts +27 -0
- package/dist/cjs/syncs/sync.d.ts.map +1 -0
- package/dist/cjs/syncs/sync.js +16 -0
- package/dist/cjs/syncs/sync.js.map +1 -0
- package/dist/cjs/syncs/syncMap.d.ts +17 -0
- package/dist/cjs/syncs/syncMap.d.ts.map +1 -0
- package/dist/cjs/syncs/syncMap.js +51 -0
- package/dist/cjs/syncs/syncMap.js.map +1 -0
- package/dist/cjs/utils/arn.d.ts +26 -0
- package/dist/cjs/utils/arn.d.ts.map +1 -0
- package/dist/cjs/utils/arn.js +60 -0
- package/dist/cjs/utils/arn.js.map +1 -0
- package/dist/cjs/utils/client-tools.d.ts +15 -0
- package/dist/cjs/utils/client-tools.d.ts.map +1 -0
- package/dist/cjs/utils/client-tools.js +42 -0
- package/dist/cjs/utils/client-tools.js.map +1 -0
- package/dist/cjs/utils/strings.d.ts +8 -0
- package/dist/cjs/utils/strings.d.ts.map +1 -0
- package/dist/cjs/utils/strings.js +19 -0
- package/dist/cjs/utils/strings.js.map +1 -0
- package/dist/cjs/utils/types.d.ts +2 -0
- package/dist/cjs/utils/types.d.ts.map +1 -0
- package/dist/cjs/utils/types.js +7 -0
- package/dist/cjs/utils/types.js.map +1 -0
- package/dist/esm/aws/ClientPool.d.ts +27 -0
- package/dist/esm/aws/ClientPool.d.ts.map +1 -0
- package/dist/esm/aws/ClientPool.js +50 -0
- package/dist/esm/aws/ClientPool.js.map +1 -0
- package/dist/esm/aws/auth.d.ts +16 -0
- package/dist/esm/aws/auth.d.ts.map +1 -0
- package/dist/esm/aws/auth.js +71 -0
- package/dist/esm/aws/auth.js.map +1 -0
- package/dist/esm/cli.js +46 -8
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/config/config.d.ts +22 -11
- package/dist/esm/config/config.d.ts.map +1 -1
- package/dist/esm/config/config.js +50 -7
- package/dist/esm/config/config.js.map +1 -1
- package/dist/esm/config/configFile.d.ts +16 -0
- package/dist/esm/config/configFile.d.ts.map +1 -0
- package/dist/esm/config/configFile.js +45 -0
- package/dist/esm/config/configFile.js.map +1 -0
- package/dist/esm/config/defaultConfig.d.ts.map +1 -1
- package/dist/esm/config/defaultConfig.js +38 -1
- package/dist/esm/config/defaultConfig.js.map +1 -1
- package/dist/esm/download/download.d.ts +3 -0
- package/dist/esm/download/download.d.ts.map +1 -0
- package/dist/esm/download/download.js +64 -0
- package/dist/esm/download/download.js.map +1 -0
- package/dist/esm/persistence/AwsIamStore.d.ts +95 -0
- package/dist/esm/persistence/AwsIamStore.d.ts.map +1 -0
- package/dist/esm/persistence/AwsIamStore.js +2 -0
- package/dist/esm/persistence/AwsIamStore.js.map +1 -0
- package/dist/esm/persistence/file/FileSystemAdapter.d.ts +20 -0
- package/dist/esm/persistence/file/FileSystemAdapter.d.ts.map +1 -0
- package/dist/esm/persistence/file/FileSystemAdapter.js +73 -0
- package/dist/esm/persistence/file/FileSystemAdapter.js.map +1 -0
- package/dist/esm/persistence/file/FileSystemAwsIamStore.d.ts +19 -0
- package/dist/esm/persistence/file/FileSystemAwsIamStore.d.ts.map +1 -0
- package/dist/esm/persistence/file/FileSystemAwsIamStore.js +89 -0
- package/dist/esm/persistence/file/FileSystemAwsIamStore.js.map +1 -0
- package/dist/esm/persistence/util.d.ts +28 -0
- package/dist/esm/persistence/util.d.ts.map +1 -0
- package/dist/esm/persistence/util.js +41 -0
- package/dist/esm/persistence/util.js.map +1 -0
- package/dist/esm/regions.d.ts +3 -0
- package/dist/esm/regions.d.ts.map +1 -0
- package/dist/esm/regions.js +12 -0
- package/dist/esm/regions.js.map +1 -0
- package/dist/esm/services.d.ts +3 -0
- package/dist/esm/services.d.ts.map +1 -0
- package/dist/esm/services.js +2 -0
- package/dist/esm/services.js.map +1 -0
- package/dist/esm/syncs/iam/authorizationDetails.d.ts +104 -0
- package/dist/esm/syncs/iam/authorizationDetails.d.ts.map +1 -0
- package/dist/esm/syncs/iam/authorizationDetails.js +478 -0
- package/dist/esm/syncs/iam/authorizationDetails.js.map +1 -0
- package/dist/esm/syncs/lambda/lambda.d.ts +3 -0
- package/dist/esm/syncs/lambda/lambda.d.ts.map +1 -0
- package/dist/esm/syncs/lambda/lambda.js +51 -0
- package/dist/esm/syncs/lambda/lambda.js.map +1 -0
- package/dist/esm/syncs/sync.d.ts +27 -0
- package/dist/esm/syncs/sync.d.ts.map +1 -0
- package/dist/esm/syncs/sync.js +13 -0
- package/dist/esm/syncs/sync.js.map +1 -0
- package/dist/esm/syncs/syncMap.d.ts +17 -0
- package/dist/esm/syncs/syncMap.d.ts.map +1 -0
- package/dist/esm/syncs/syncMap.js +47 -0
- package/dist/esm/syncs/syncMap.js.map +1 -0
- package/dist/esm/utils/arn.d.ts +26 -0
- package/dist/esm/utils/arn.d.ts.map +1 -0
- package/dist/esm/utils/arn.js +56 -0
- package/dist/esm/utils/arn.js.map +1 -0
- package/dist/esm/utils/client-tools.d.ts +15 -0
- package/dist/esm/utils/client-tools.d.ts.map +1 -0
- package/dist/esm/utils/client-tools.js +38 -0
- package/dist/esm/utils/client-tools.js.map +1 -0
- package/dist/esm/utils/strings.d.ts +8 -0
- package/dist/esm/utils/strings.d.ts.map +1 -0
- package/dist/esm/utils/strings.js +16 -0
- package/dist/esm/utils/strings.js.map +1 -0
- package/dist/esm/utils/types.d.ts +2 -0
- package/dist/esm/utils/types.d.ts.map +1 -0
- package/dist/esm/utils/types.js +4 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/package.json +13 -1
- package/dist/cjs/cliUtils.d.ts +0 -13
- package/dist/cjs/cliUtils.d.ts.map +0 -1
- package/dist/cjs/cliUtils.js +0 -43
- package/dist/cjs/cliUtils.js.map +0 -1
- package/dist/esm/cliUtils.d.ts +0 -13
- package/dist/esm/cliUtils.d.ts.map +0 -1
- package/dist/esm/cliUtils.js +0 -40
- package/dist/esm/cliUtils.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LambdaSync = void 0;
|
|
4
|
+
const client_lambda_1 = require("@aws-sdk/client-lambda");
|
|
5
|
+
const ClientPool_js_1 = require("../../aws/ClientPool.js");
|
|
6
|
+
const client_tools_js_1 = require("../../utils/client-tools.js");
|
|
7
|
+
const sync_js_1 = require("../sync.js");
|
|
8
|
+
exports.LambdaSync = {
|
|
9
|
+
awsService: 'lambda',
|
|
10
|
+
name: 'lambda',
|
|
11
|
+
global: false,
|
|
12
|
+
execute: async (accountId, region, credentials, storage, endpoint) => {
|
|
13
|
+
const lambdaClient = ClientPool_js_1.AwsClientPool.defaultInstance.client(client_lambda_1.LambdaClient, credentials, region, endpoint);
|
|
14
|
+
const command = new client_lambda_1.ListFunctionsCommand();
|
|
15
|
+
const functions = [];
|
|
16
|
+
let marker = undefined;
|
|
17
|
+
do {
|
|
18
|
+
const response = await lambdaClient.send(command);
|
|
19
|
+
functions.push(...(response.Functions || []));
|
|
20
|
+
marker = response.NextMarker;
|
|
21
|
+
} while (marker);
|
|
22
|
+
const functionData = [];
|
|
23
|
+
for (const func of functions) {
|
|
24
|
+
const policy = await (0, client_tools_js_1.runAndCatch404)(async () => {
|
|
25
|
+
const policyResult = await lambdaClient.send(new client_lambda_1.GetPolicyCommand({ FunctionName: func.FunctionName }));
|
|
26
|
+
if (policyResult.Policy) {
|
|
27
|
+
return JSON.parse(policyResult.Policy);
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
});
|
|
31
|
+
const tags = await (0, client_tools_js_1.runAndCatch404)(async () => {
|
|
32
|
+
const tagsResult = await lambdaClient.send(new client_lambda_1.ListTagsCommand({ Resource: func.FunctionArn }));
|
|
33
|
+
return tagsResult.Tags;
|
|
34
|
+
});
|
|
35
|
+
functionData.push({
|
|
36
|
+
arn: func.FunctionArn,
|
|
37
|
+
metadata: {
|
|
38
|
+
role: func.Role,
|
|
39
|
+
arn: func.FunctionArn,
|
|
40
|
+
name: func.FunctionName
|
|
41
|
+
},
|
|
42
|
+
policy,
|
|
43
|
+
tags
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
await (0, sync_js_1.syncData)(functionData, storage, accountId, {
|
|
47
|
+
service: 'lambda',
|
|
48
|
+
resourceType: 'function',
|
|
49
|
+
account: accountId,
|
|
50
|
+
region: region
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=lambda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../../src/syncs/lambda/lambda.ts"],"names":[],"mappings":";;;AAAA,0DAM+B;AAE/B,2DAAuD;AAEvD,iEAA4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AAK,IAAI,EAAE;gBAC3C,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,IAAI,CACxC,IAAI,+BAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CACpD,CAAA;gBACD,OAAO,UAAU,CAAC,IAAI,CAAA;YACxB,CAAC,CAAC,CAAA;YAEF,YAAY,CAAC,IAAI,CAAC;gBAChB,GAAG,EAAE,IAAI,CAAC,WAAY;gBACtB,QAAQ,EAAE;oBACR,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,GAAG,EAAE,IAAI,CAAC,WAAW;oBACrB,IAAI,EAAE,IAAI,CAAC,YAAY;iBACxB;gBACD,MAAM;gBACN,IAAI;aACL,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,IAAA,kBAAQ,EAAC,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE;YAC/C,OAAO,EAAE,QAAQ;YACjB,YAAY,EAAE,UAAU;YACxB,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,MAAM;SACf,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AwsCredentialIdentityWithMetaData } from '../aws/auth.js';
|
|
2
|
+
import { AwsIamStore, ResourceTypeParts } from '../persistence/AwsIamStore.js';
|
|
3
|
+
import { AwsService } from '../services.js';
|
|
4
|
+
export interface Sync {
|
|
5
|
+
/**
|
|
6
|
+
* What service the sync is for.
|
|
7
|
+
*/
|
|
8
|
+
awsService: AwsService;
|
|
9
|
+
/**
|
|
10
|
+
* The name of the sync. This should be a unique identifier for the sync.
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Is the sync global. If so, it should only be one in one region per account.
|
|
15
|
+
*/
|
|
16
|
+
global?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Execute the sync for a given account and region.
|
|
19
|
+
*/
|
|
20
|
+
execute(accountId: string, region: string, credentials: AwsCredentialIdentityWithMetaData, storage: AwsIamStore, endpoint: string | undefined): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
type DataRecord = Record<string, any> & {
|
|
23
|
+
arn: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function syncData(records: DataRecord[], storage: AwsIamStore, accountId: string, resourceTypeParts: ResourceTypeParts): Promise<void>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/syncs/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IAEtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;OAEG;IACH,OAAO,CACL,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,iCAAiC,EAC9C,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,OAAO,CAAC,IAAI,CAAC,CAAA;CACjB;AAED,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AACvD,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,UAAU,EAAE,EACrB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,iBAAiB,iBAarC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncData = syncData;
|
|
4
|
+
async function syncData(records, storage, accountId, resourceTypeParts) {
|
|
5
|
+
const allArns = records.map((r) => r.arn);
|
|
6
|
+
await storage.syncResourceList(accountId, resourceTypeParts, allArns);
|
|
7
|
+
for (const record of records) {
|
|
8
|
+
for (const [key, value] of Object.entries(record)) {
|
|
9
|
+
if (key === 'arn') {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
await storage.saveResourceMetadata(accountId, record.arn, key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../src/syncs/sync.ts"],"names":[],"mappings":";;AAiCA,4BAiBC;AAjBM,KAAK,UAAU,QAAQ,CAC5B,OAAqB,EACrB,OAAoB,EACpB,SAAiB,EACjB,iBAAoC;IAEpC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACzC,MAAM,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,iBAAiB,EAAE,OAAO,CAAC,CAAA;IAErE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;gBAClB,SAAQ;YACV,CAAC;YACD,MAAM,OAAO,CAAC,oBAAoB,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QACvE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AwsService } from '../services.js';
|
|
2
|
+
import { Sync } from './sync.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get the global syncs for a given AWS service.
|
|
5
|
+
*
|
|
6
|
+
* @param service The AWS service to get the syncs for
|
|
7
|
+
* @returns An array of syncs that are global for the specified service.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getGlobalSyncsForService(service: AwsService): Sync[];
|
|
10
|
+
/**
|
|
11
|
+
* Get the regional syncs for a given AWS service.
|
|
12
|
+
*
|
|
13
|
+
* @param service The AWS service to get the syncs for
|
|
14
|
+
* @returns An array of syncs that are regional for the specified service.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getRegionalSyncsForService(service: AwsService): Sync[];
|
|
17
|
+
//# sourceMappingURL=syncMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncMap.d.ts","sourceRoot":"","sources":["../../../src/syncs/syncMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAsBhC;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,EAAE,CAMpE;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,EAAE,CAMtE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGlobalSyncsForService = getGlobalSyncsForService;
|
|
4
|
+
exports.getRegionalSyncsForService = getRegionalSyncsForService;
|
|
5
|
+
const authorizationDetails_js_1 = require("./iam/authorizationDetails.js");
|
|
6
|
+
const lambda_js_1 = require("./lambda/lambda.js");
|
|
7
|
+
const allSyncs = [authorizationDetails_js_1.AuthorizationDetailsSync, lambda_js_1.LambdaSync];
|
|
8
|
+
const syncMap = new Map();
|
|
9
|
+
for (const sync of allSyncs) {
|
|
10
|
+
const service = sync.awsService;
|
|
11
|
+
if (!syncMap.has(service)) {
|
|
12
|
+
syncMap.set(service, {
|
|
13
|
+
regional: [],
|
|
14
|
+
global: []
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const syncs = syncMap.get(service);
|
|
18
|
+
if (sync.global) {
|
|
19
|
+
syncs.global.push(sync);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
syncs.regional.push(sync);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the global syncs for a given AWS service.
|
|
27
|
+
*
|
|
28
|
+
* @param service The AWS service to get the syncs for
|
|
29
|
+
* @returns An array of syncs that are global for the specified service.
|
|
30
|
+
*/
|
|
31
|
+
function getGlobalSyncsForService(service) {
|
|
32
|
+
const syncs = syncMap.get(service);
|
|
33
|
+
if (!syncs) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return syncs.global;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the regional syncs for a given AWS service.
|
|
40
|
+
*
|
|
41
|
+
* @param service The AWS service to get the syncs for
|
|
42
|
+
* @returns An array of syncs that are regional for the specified service.
|
|
43
|
+
*/
|
|
44
|
+
function getRegionalSyncsForService(service) {
|
|
45
|
+
const syncs = syncMap.get(service);
|
|
46
|
+
if (!syncs) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
return syncs.regional;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=syncMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncMap.js","sourceRoot":"","sources":["../../../src/syncs/syncMap.ts"],"names":[],"mappings":";;AA+BA,4DAMC;AAQD,gEAMC;AAlDD,2EAAwE;AACxE,kDAA+C;AAG/C,MAAM,QAAQ,GAAG,CAAC,kDAAwB,EAAE,sBAAU,CAAC,CAAA;AAEvD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoD,CAAA;AAE3E,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAA;IAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE;YACnB,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE,EAAE;SACX,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAE,CAAA;IACnC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,OAAmB;IAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAClC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAA;AACrB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,OAAmB;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAClC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,CAAA;AACvB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ArnParts {
|
|
2
|
+
partition: string | undefined;
|
|
3
|
+
service: string | undefined;
|
|
4
|
+
region: string | undefined;
|
|
5
|
+
accountId: string | undefined;
|
|
6
|
+
resource: string | undefined;
|
|
7
|
+
resourceType: string | undefined;
|
|
8
|
+
resourcePath: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Split an ARN into its parts
|
|
12
|
+
*
|
|
13
|
+
* @param arn the arn to split
|
|
14
|
+
* @returns the parts of the ARN
|
|
15
|
+
*/
|
|
16
|
+
export declare function splitArnParts(arn: string): ArnParts;
|
|
17
|
+
/**
|
|
18
|
+
* Get the product/id segments of the resource portion of an ARN.
|
|
19
|
+
* The first segment is the product segment and the second segment is the resource id segment.
|
|
20
|
+
* This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
|
|
21
|
+
*
|
|
22
|
+
* @param resource The resource to get the resource segments. Must be an ARN resource.
|
|
23
|
+
* @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getResourceSegments(service: string, accountId: string, region: string, resourceString: string): [string, string];
|
|
26
|
+
//# sourceMappingURL=arn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.d.ts","sourceRoot":"","sources":["../../../src/utils/arn.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAkBnD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBlB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copied from https://github.com/cloud-copilot/iam-simulate/blob/main/src/util.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.splitArnParts = splitArnParts;
|
|
5
|
+
exports.getResourceSegments = getResourceSegments;
|
|
6
|
+
/**
|
|
7
|
+
* Split an ARN into its parts
|
|
8
|
+
*
|
|
9
|
+
* @param arn the arn to split
|
|
10
|
+
* @returns the parts of the ARN
|
|
11
|
+
*/
|
|
12
|
+
function splitArnParts(arn) {
|
|
13
|
+
const parts = arn.split(':');
|
|
14
|
+
const partition = parts.at(1);
|
|
15
|
+
const service = parts.at(2);
|
|
16
|
+
const region = parts.at(3);
|
|
17
|
+
const accountId = parts.at(4);
|
|
18
|
+
const resource = parts.slice(5).join(':');
|
|
19
|
+
const [resourceType, resourcePath] = getResourceSegments(service, accountId, region, resource);
|
|
20
|
+
return {
|
|
21
|
+
partition,
|
|
22
|
+
service,
|
|
23
|
+
region,
|
|
24
|
+
accountId,
|
|
25
|
+
resource,
|
|
26
|
+
resourceType,
|
|
27
|
+
resourcePath
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the product/id segments of the resource portion of an ARN.
|
|
32
|
+
* The first segment is the product segment and the second segment is the resource id segment.
|
|
33
|
+
* This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
|
|
34
|
+
*
|
|
35
|
+
* @param resource The resource to get the resource segments. Must be an ARN resource.
|
|
36
|
+
* @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
|
|
37
|
+
*/
|
|
38
|
+
function getResourceSegments(service, accountId, region, resourceString) {
|
|
39
|
+
// This is terrible, and I hate it
|
|
40
|
+
if (service === 's3' && accountId === '' && region === '') {
|
|
41
|
+
return ['', resourceString];
|
|
42
|
+
}
|
|
43
|
+
const slashIndex = resourceString.indexOf('/');
|
|
44
|
+
const colonIndex = resourceString.indexOf(':');
|
|
45
|
+
let splitIndex = slashIndex;
|
|
46
|
+
if (slashIndex != -1 && colonIndex != -1) {
|
|
47
|
+
splitIndex = Math.min(slashIndex, colonIndex) + 1;
|
|
48
|
+
}
|
|
49
|
+
else if (colonIndex == -1) {
|
|
50
|
+
splitIndex = slashIndex + 1;
|
|
51
|
+
}
|
|
52
|
+
else if (slashIndex == -1) {
|
|
53
|
+
splitIndex = colonIndex + 1;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error(`Unable to split resource ${resourceString}`);
|
|
57
|
+
}
|
|
58
|
+
return [resourceString.slice(0, splitIndex - 1), resourceString.slice(splitIndex)];
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=arn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.js","sourceRoot":"","sources":["../../../src/utils/arn.ts"],"names":[],"mappings":";AAAA,kFAAkF;;AAkBlF,sCAkBC;AAUD,kDA0BC;AA5DD;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC3B,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC9B,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE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|
|
3
|
+
* @param operation The operation to run.
|
|
4
|
+
* @returns If successful, returns the result of operation. If operation returns a 404, returns undefined.
|
|
5
|
+
* @throws If operation returns a non 404 error, rethrows that error.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runAndCatch404<T>(operation: () => Promise<T | undefined>): Promise<T | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param operation The operation to run.
|
|
11
|
+
* @returns If successful, returns the result of operation. If operation returns a 404, returns undefined.
|
|
12
|
+
* @throws If operation returns a non 400 error, rethrows that error.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runAndCatchAccessDenied<T>(operation: () => Promise<T | undefined>): Promise<T | undefined>;
|
|
15
|
+
//# sourceMappingURL=client-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-tools.d.ts","sourceRoot":"","sources":["../../../src/utils/client-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,GACtC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAUxB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,EAC7C,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,GACtC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAYxB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAndCatch404 = runAndCatch404;
|
|
4
|
+
exports.runAndCatchAccessDenied = runAndCatchAccessDenied;
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param operation The operation to run.
|
|
8
|
+
* @returns If successful, returns the result of operation. If operation returns a 404, returns undefined.
|
|
9
|
+
* @throws If operation returns a non 404 error, rethrows that error.
|
|
10
|
+
*/
|
|
11
|
+
async function runAndCatch404(operation) {
|
|
12
|
+
try {
|
|
13
|
+
const result = await operation();
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
if (e['$metadata']?.httpStatusCode == 404) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param operation The operation to run.
|
|
26
|
+
* @returns If successful, returns the result of operation. If operation returns a 404, returns undefined.
|
|
27
|
+
* @throws If operation returns a non 400 error, rethrows that error.
|
|
28
|
+
*/
|
|
29
|
+
async function runAndCatchAccessDenied(operation) {
|
|
30
|
+
try {
|
|
31
|
+
const result = await operation();
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
const errorName = e.name;
|
|
36
|
+
if (errorName == 'AccessDeniedException' || errorName == 'AccessDenied') {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=client-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-tools.js","sourceRoot":"","sources":["../../../src/utils/client-tools.ts"],"names":[],"mappings":";;AAMA,wCAYC;AAQD,0DAcC;AAxCD;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAClC,SAAuC;IAEvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAA;QAChC,OAAO,MAAM,CAAA;IACf,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,WAAW,CAAC,EAAE,cAAc,IAAI,GAAG,EAAE,CAAC;YAC1C,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,MAAM,CAAC,CAAA;IACT,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,uBAAuB,CAC3C,SAAuC;IAEvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAA;QAChC,OAAO,MAAM,CAAA;IACf,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAA;QAExB,IAAI,SAAS,IAAI,uBAAuB,IAAI,SAAS,IAAI,cAAc,EAAE,CAAC;YACxE,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,MAAM,CAAC,CAAA;IACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../../src/utils/strings.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,MAAU,GAAG,MAAM,CAQ3D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomCharacters = randomCharacters;
|
|
4
|
+
const characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
5
|
+
/**
|
|
6
|
+
* Generates a random string of a given length
|
|
7
|
+
*
|
|
8
|
+
* @param length The length of the string you would like to generate
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
function randomCharacters(length = 5) {
|
|
12
|
+
let result = '';
|
|
13
|
+
for (let i = 0; i < length; i++) {
|
|
14
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
15
|
+
result += characters[randomIndex];
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=strings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../../src/utils/strings.ts"],"names":[],"mappings":";;AAOA,4CAQC;AAfD,MAAM,UAAU,GAAG,sCAAsC,CAAA;AACzD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,SAAiB,CAAC;IACjD,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;QACjE,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;IACnC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,KAAK,IAAI,CAAC,CAE7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":";;AAAA,8BAEC;AAFD,SAAgB,SAAS,CAAI,KAAoB;IAC/C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Client } from '@smithy/smithy-client';
|
|
2
|
+
import { AwsCredentialIdentityWithMetaData } from './auth.js';
|
|
3
|
+
type ClientConstructor<T> = new (args: any) => T;
|
|
4
|
+
type AnyClient = Client<any, any, any, any>;
|
|
5
|
+
export declare class AwsClientPool {
|
|
6
|
+
static defaultInstance: AwsClientPool;
|
|
7
|
+
private clientCache;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a client of the specified type with the specified credentials and region.
|
|
10
|
+
* Will create a new client if one does not already exist in the cache.
|
|
11
|
+
*
|
|
12
|
+
* @param ClientType The client constructor to create an instance of.
|
|
13
|
+
* @param credentials The credentials to use for the client.
|
|
14
|
+
* @param region The region to use for the client.
|
|
15
|
+
* @returns A client of the specified type with the specified credentials and region.
|
|
16
|
+
*/
|
|
17
|
+
client<T extends AnyClient>(ClientType: ClientConstructor<T>, credentials: AwsCredentialIdentityWithMetaData, region: string | undefined, endpoint: string | undefined): T;
|
|
18
|
+
private getCacheKey;
|
|
19
|
+
/**
|
|
20
|
+
* Destroys all clients in the pool and empties the cache.
|
|
21
|
+
*
|
|
22
|
+
* NOT THREAD SAFE, this should only be called when all other operations are complete.
|
|
23
|
+
*/
|
|
24
|
+
clear(): void;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=ClientPool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientPool.d.ts","sourceRoot":"","sources":["../../../src/aws/ClientPool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAA;AAE7D,KAAK,iBAAiB,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,CAAC,CAAA;AAChD,KAAK,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAE3C,qBAAa,aAAa;IACxB,OAAc,eAAe,gBAAsB;IAEnD,OAAO,CAAC,WAAW,CAA+B;IAElD;;;;;;;;OAQG;IACI,MAAM,CAAC,CAAC,SAAS,SAAS,EAC/B,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAChC,WAAW,EAAE,iCAAiC,EAC9C,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,CAAC;IAmBJ,OAAO,CAAC,WAAW;IASnB;;;;OAIG;IACI,KAAK,IAAI,IAAI;CAQrB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { RETRY_MODES } from '@smithy/util-retry';
|
|
2
|
+
export class AwsClientPool {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.clientCache = new Map();
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Returns a client of the specified type with the specified credentials and region.
|
|
8
|
+
* Will create a new client if one does not already exist in the cache.
|
|
9
|
+
*
|
|
10
|
+
* @param ClientType The client constructor to create an instance of.
|
|
11
|
+
* @param credentials The credentials to use for the client.
|
|
12
|
+
* @param region The region to use for the client.
|
|
13
|
+
* @returns A client of the specified type with the specified credentials and region.
|
|
14
|
+
*/
|
|
15
|
+
client(ClientType, credentials, region, endpoint) {
|
|
16
|
+
const cacheKey = this.getCacheKey(ClientType, credentials, region, endpoint);
|
|
17
|
+
if (!this.clientCache.has(cacheKey)) {
|
|
18
|
+
// logInfo('CreatingNewAwsClient', undefined, { cacheKey })
|
|
19
|
+
const client = new ClientType({
|
|
20
|
+
credentials,
|
|
21
|
+
region,
|
|
22
|
+
maxAttempts: 10,
|
|
23
|
+
retryMode: RETRY_MODES.ADAPTIVE
|
|
24
|
+
});
|
|
25
|
+
this.clientCache.set(cacheKey, client);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// logInfo('ReusingAwsClient', undefined, { cacheKey })
|
|
29
|
+
}
|
|
30
|
+
return this.clientCache.get(cacheKey);
|
|
31
|
+
}
|
|
32
|
+
getCacheKey(ClientType, credentials, region, endpoint) {
|
|
33
|
+
return `${ClientType.name}:${credentials.accountId}:${region}:${endpoint}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Destroys all clients in the pool and empties the cache.
|
|
37
|
+
*
|
|
38
|
+
* NOT THREAD SAFE, this should only be called when all other operations are complete.
|
|
39
|
+
*/
|
|
40
|
+
clear() {
|
|
41
|
+
this.clientCache.forEach((client) => {
|
|
42
|
+
if (typeof client.destroy === 'function') {
|
|
43
|
+
client.destroy();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.clientCache.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
AwsClientPool.defaultInstance = new AwsClientPool();
|
|
50
|
+
//# sourceMappingURL=ClientPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientPool.js","sourceRoot":"","sources":["../../../src/aws/ClientPool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAMhD,MAAM,OAAO,aAAa;IAA1B;QAGU,gBAAW,GAAG,IAAI,GAAG,EAAqB,CAAA;IAyDpD,CAAC;IAvDC;;;;;;;;OAQG;IACI,MAAM,CACX,UAAgC,EAChC,WAA8C,EAC9C,MAA0B,EAC1B,QAA4B;QAE5B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;QAE5E,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpC,2DAA2D;YAC3D,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC;gBAC5B,WAAW;gBACX,MAAM;gBACN,WAAW,EAAE,EAAE;gBACf,SAAS,EAAE,WAAW,CAAC,QAAQ;aAChC,CAAC,CAAA;YACF,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QACxC,CAAC;aAAM,CAAC;YACN,uDAAuD;QACzD,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAM,CAAA;IAC5C,CAAC;IAEO,WAAW,CACjB,UAAgC,EAChC,WAA8C,EAC9C,MAA0B,EAC1B,QAA4B;QAE5B,OAAO,GAAG,UAAU,CAAC,IAAI,IAAI,WAAW,CAAC,SAAS,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAA;IAC5E,CAAC;IAED;;;;OAIG;IACI,KAAK;QACV,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAClC,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;gBACzC,MAAM,CAAC,OAAO,EAAE,CAAA;YAClB,CAAC;QACH,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;;AA1Da,6BAAe,GAAG,IAAI,aAAa,EAAE,AAAtB,CAAsB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AwsCredentialIdentity } from '@aws-sdk/types';
|
|
2
|
+
import { AuthConfig } from '../config/config.js';
|
|
3
|
+
export interface AwsCredentialIdentityWithMetaData extends AwsCredentialIdentity {
|
|
4
|
+
partition: string;
|
|
5
|
+
accountId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CollectIdentityProvider {
|
|
8
|
+
getCredentials: () => Promise<AwsCredentialIdentityWithMetaData>;
|
|
9
|
+
}
|
|
10
|
+
export declare function getDefaultCredentials(): Promise<AwsCredentialIdentity>;
|
|
11
|
+
export declare function getCredentials(accountId: string, authConfig: AuthConfig | undefined): Promise<AwsCredentialIdentityWithMetaData>;
|
|
12
|
+
export declare function getTokenInfo(credentials: AwsCredentialIdentity): Promise<{
|
|
13
|
+
accountId: string;
|
|
14
|
+
partition: string;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/aws/auth.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAGhD,MAAM,WAAW,iCAAkC,SAAQ,qBAAqB;IAC9E,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,uBAAuB;IACtC,cAAc,EAAE,MAAM,OAAO,CAAC,iCAAiC,CAAC,CAAA;CACjE;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAG5E;AAED,wBAAsB,cAAc,CAClC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,OAAO,CAAC,iCAAiC,CAAC,CAyD5C;AAED,wBAAsB,YAAY,CAAC,WAAW,EAAE,qBAAqB,GAAG,OAAO,CAAC;IAC9E,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAC,CAYD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
|
|
2
|
+
import { fromIni, fromNodeProviderChain, fromTemporaryCredentials } from '@aws-sdk/credential-providers';
|
|
3
|
+
import { randomCharacters } from '../utils/strings.js';
|
|
4
|
+
export async function getDefaultCredentials() {
|
|
5
|
+
const provider = fromNodeProviderChain();
|
|
6
|
+
return provider();
|
|
7
|
+
}
|
|
8
|
+
export async function getCredentials(accountId, authConfig) {
|
|
9
|
+
//If there is no auth config specific to that account, use the default auth config
|
|
10
|
+
if (!authConfig) {
|
|
11
|
+
const provider = fromNodeProviderChain();
|
|
12
|
+
const credentials = await provider();
|
|
13
|
+
const tokenInfo = await getTokenInfo(credentials);
|
|
14
|
+
if (tokenInfo.accountId !== accountId) {
|
|
15
|
+
throw new Error(`No auth config found for account ${accountId} and no default auth config found. The account ID of the current credentials does not match.`);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...credentials,
|
|
19
|
+
accountId: tokenInfo.accountId,
|
|
20
|
+
partition: tokenInfo.partition
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
let credentials = undefined;
|
|
24
|
+
if (authConfig.profile) {
|
|
25
|
+
const provider = fromIni({ profile: authConfig.profile });
|
|
26
|
+
credentials = await provider();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const provider = fromNodeProviderChain();
|
|
30
|
+
credentials = await provider();
|
|
31
|
+
}
|
|
32
|
+
const sessionInfo = await getTokenInfo(credentials);
|
|
33
|
+
if (authConfig.role) {
|
|
34
|
+
const roleProvider = fromTemporaryCredentials({
|
|
35
|
+
// Optional. The master credentials used to get and refresh temporary credentials from AWS STS.
|
|
36
|
+
// If skipped, it uses the default credential resolved by internal STS client.
|
|
37
|
+
masterCredentials: credentials,
|
|
38
|
+
// Required. Options passed to STS AssumeRole operation.
|
|
39
|
+
params: {
|
|
40
|
+
// Required. ARN of role to assume.
|
|
41
|
+
RoleArn: `arn:${sessionInfo.partition}:iam::${accountId}:role/${authConfig.role.pathAndName}`,
|
|
42
|
+
ExternalId: authConfig.role.externalId,
|
|
43
|
+
// Optional. An identifier for the assumed role session. If skipped, it generates a random
|
|
44
|
+
// session name with prefix of 'aws-sdk-js-'.
|
|
45
|
+
RoleSessionName: authConfig.role.sessionName || `iam-collect-${randomCharacters()}`
|
|
46
|
+
// Optional. The duration, in seconds, of the role session.
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
credentials = await roleProvider();
|
|
50
|
+
}
|
|
51
|
+
else if (sessionInfo.accountId != accountId) {
|
|
52
|
+
// If the account ID from the credentials doesn't match the expected account ID and no role is specified
|
|
53
|
+
// throw an error to indicate that the credentials do not match the expected account
|
|
54
|
+
throw new Error(`The credentials provided do not match the expected account ID ${accountId}. Found ${sessionInfo.accountId}. Please check your auth configuration.`);
|
|
55
|
+
}
|
|
56
|
+
return { ...credentials, accountId, partition: sessionInfo.partition };
|
|
57
|
+
}
|
|
58
|
+
export async function getTokenInfo(credentials) {
|
|
59
|
+
const stsClient = new STSClient({ credentials });
|
|
60
|
+
const command = new GetCallerIdentityCommand({});
|
|
61
|
+
const response = await stsClient.send(command);
|
|
62
|
+
const accountId = response.Account;
|
|
63
|
+
const arn = response.Arn;
|
|
64
|
+
const arnParts = arn.split(':');
|
|
65
|
+
const partition = arnParts[1];
|
|
66
|
+
return {
|
|
67
|
+
accountId: accountId,
|
|
68
|
+
partition: partition
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/aws/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,EACL,OAAO,EACP,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,+BAA+B,CAAA;AAGtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAWtD,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA;IACxC,OAAO,QAAQ,EAAE,CAAA;AACnB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,SAAiB,EACjB,UAAkC;IAElC,kFAAkF;IAClF,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAA;QACxC,MAAM,WAAW,GAAG,MAAM,QAAQ,EAAE,CAAA;QACpC,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,CAAA;QACjD,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CACb,oCAAoC,SAAS,8FAA8F,CAC5I,CAAA;QACH,CAAC;QAED,OAAO;YACL,GAAG,WAAW;YACd,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B,CAAA;IACH,CAAC;IAED,IAAI,WAAW,GAAsC,SAAS,CAAA;IAC9D,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,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