@cloud-copilot/iam-collect 0.1.92 → 0.1.93

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.
@@ -1,3 +1,13 @@
1
1
  import { Sync } from '../sync.js';
2
2
  export declare const RestApisSync: Sync;
3
+ /**
4
+ * Parse the API Gateway policy string into a JSON object.
5
+ * For some reason API Gateway policies can have \\\ at the start of every string
6
+ * and any forward slash is escaped with a double backslash (\\/)
7
+ *
8
+ * @param apiId the ID of the API Gateway
9
+ * @param policy the policy string to parse
10
+ * @returns the parsed policy object or undefined if the policy is not provided
11
+ */
12
+ export declare function parseApiGatewayPolicy(apiId: string, policy: string | undefined): Record<string, any> | undefined;
3
13
  //# sourceMappingURL=gateways.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gateways.d.ts","sourceRoot":"","sources":["../../../../src/syncs/apigateway/gateways.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,eAAO,MAAM,YAAY,EAAE,IA2B1B,CAAA"}
1
+ {"version":3,"file":"gateways.d.ts","sourceRoot":"","sources":["../../../../src/syncs/apigateway/gateways.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,eAAO,MAAM,YAAY,EAAE,IA2B1B,CAAA;AAcD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAYjC"}
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RestApisSync = void 0;
4
+ exports.parseApiGatewayPolicy = parseApiGatewayPolicy;
4
5
  const client_api_gateway_1 = require("@aws-sdk/client-api-gateway");
5
- const json_js_1 = require("../../utils/json.js");
6
+ const log_js_1 = require("../../utils/log.js");
6
7
  const typedSync_js_1 = require("../typedSync.js");
7
8
  exports.RestApisSync = (0, typedSync_js_1.createTypedSyncOperation)('apigateway', 'gateways', (0, typedSync_js_1.createResourceSyncType)({
8
9
  client: client_api_gateway_1.APIGatewayClient,
@@ -12,7 +13,7 @@ exports.RestApisSync = (0, typedSync_js_1.createTypedSyncOperation)('apigateway'
12
13
  inputKey: 'position',
13
14
  outputKey: 'position'
14
15
  },
15
- arn: (api, region, account, partition) => restApiArn(api.id, region, account, partition),
16
+ arn: (api, region, account, partition) => restApiArn(api.id, region, partition),
16
17
  tags: (api) => api.tags,
17
18
  resourceTypeParts: (account, region) => ({
18
19
  account,
@@ -25,10 +26,40 @@ exports.RestApisSync = (0, typedSync_js_1.createTypedSyncOperation)('apigateway'
25
26
  id: api.id,
26
27
  name: api.name
27
28
  },
28
- policy: (0, json_js_1.parseIfPresent)(api.policy)
29
+ policy: parseApiGatewayPolicy(api.id, api.policy)
29
30
  })
30
31
  }));
31
- function restApiArn(apiId, region, account, partition) {
32
+ /**
33
+ * Get the ARN for an API Gateway REST API.
34
+ *
35
+ * @param apiId the ID of the API Gateway REST API
36
+ * @param region the AWS region of the API Gateway
37
+ * @param partition the AWS partition (aws, aws-cn, aws-us-gov)
38
+ * @returns the ARN of the API Gateway REST API
39
+ */
40
+ function restApiArn(apiId, region, partition) {
32
41
  return `arn:${partition}:apigateway:${region}::/restapis/${apiId}`;
33
42
  }
43
+ /**
44
+ * Parse the API Gateway policy string into a JSON object.
45
+ * For some reason API Gateway policies can have \\\ at the start of every string
46
+ * and any forward slash is escaped with a double backslash (\\/)
47
+ *
48
+ * @param apiId the ID of the API Gateway
49
+ * @param policy the policy string to parse
50
+ * @returns the parsed policy object or undefined if the policy is not provided
51
+ */
52
+ function parseApiGatewayPolicy(apiId, policy) {
53
+ if (!policy) {
54
+ return undefined;
55
+ }
56
+ policy = policy.replace(/\\"/g, '"').replace(/\\\//g, '/');
57
+ try {
58
+ return JSON.parse(policy);
59
+ }
60
+ catch (error) {
61
+ log_js_1.log.error('Failed to parse API Gateway policy', { apiId }, error);
62
+ throw new Error(`Unable to parse policy for API Gateway ${apiId}`);
63
+ }
64
+ }
34
65
  //# sourceMappingURL=gateways.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gateways.js","sourceRoot":"","sources":["../../../../src/syncs/apigateway/gateways.ts"],"names":[],"mappings":";;;AAAA,oEAAkF;AAClF,iDAAoD;AAEpD,kDAAkF;AAErE,QAAA,YAAY,GAAS,IAAA,uCAAwB,EACxD,YAAY,EACZ,UAAU,EACV,IAAA,qCAAsB,EAAC;IACrB,MAAM,EAAE,qCAAgB;IACxB,OAAO,EAAE,uCAAkB;IAC3B,GAAG,EAAE,OAAO;IACZ,gBAAgB,EAAE;QAChB,QAAQ,EAAE,UAAU;QACpB,SAAS,EAAE,UAAU;KACtB;IACD,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAG,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC;IACzF,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI;IACvB,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACvC,OAAO;QACP,OAAO,EAAE,YAAY;QACrB,MAAM;QACN,YAAY,EAAE,UAAU;KACzB,CAAC;IACF,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACjB,QAAQ,EAAE;YACR,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,GAAG,CAAC,IAAI;SACf;QACD,MAAM,EAAE,IAAA,wBAAc,EAAC,GAAG,CAAC,MAAM,CAAC;KACnC,CAAC;CACH,CAAC,CACH,CAAA;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,MAAc,EAAE,OAAe,EAAE,SAAiB;IACnF,OAAO,OAAO,SAAS,eAAe,MAAM,eAAe,KAAK,EAAE,CAAA;AACpE,CAAC"}
1
+ {"version":3,"file":"gateways.js","sourceRoot":"","sources":["../../../../src/syncs/apigateway/gateways.ts"],"names":[],"mappings":";;;AAuDA,sDAeC;AAtED,oEAAkF;AAClF,+CAAwC;AAExC,kDAAkF;AAErE,QAAA,YAAY,GAAS,IAAA,uCAAwB,EACxD,YAAY,EACZ,UAAU,EACV,IAAA,qCAAsB,EAAC;IACrB,MAAM,EAAE,qCAAgB;IACxB,OAAO,EAAE,uCAAkB;IAC3B,GAAG,EAAE,OAAO;IACZ,gBAAgB,EAAE;QAChB,QAAQ,EAAE,UAAU;QACpB,SAAS,EAAE,UAAU;KACtB;IACD,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAG,EAAE,MAAM,EAAE,SAAS,CAAC;IAChF,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI;IACvB,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACvC,OAAO;QACP,OAAO,EAAE,YAAY;QACrB,MAAM;QACN,YAAY,EAAE,UAAU;KACzB,CAAC;IACF,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACjB,QAAQ,EAAE;YACR,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,GAAG,CAAC,IAAI;SACf;QACD,MAAM,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAAG,EAAE,GAAG,CAAC,MAAM,CAAC;KACnD,CAAC;CACH,CAAC,CACH,CAAA;AAED;;;;;;;GAOG;AACH,SAAS,UAAU,CAAC,KAAa,EAAE,MAAc,EAAE,SAAiB;IAClE,OAAO,OAAO,SAAS,eAAe,MAAM,eAAe,KAAK,EAAE,CAAA;AACpE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACnC,KAAa,EACb,MAA0B;IAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAE1D,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,YAAG,CAAC,KAAK,CAAC,oCAAoC,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,CAAA;QACjE,MAAM,IAAI,KAAK,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAA;IACpE,CAAC;AACH,CAAC"}
@@ -1,3 +1,13 @@
1
1
  import { Sync } from '../sync.js';
2
2
  export declare const RestApisSync: Sync;
3
+ /**
4
+ * Parse the API Gateway policy string into a JSON object.
5
+ * For some reason API Gateway policies can have \\\ at the start of every string
6
+ * and any forward slash is escaped with a double backslash (\\/)
7
+ *
8
+ * @param apiId the ID of the API Gateway
9
+ * @param policy the policy string to parse
10
+ * @returns the parsed policy object or undefined if the policy is not provided
11
+ */
12
+ export declare function parseApiGatewayPolicy(apiId: string, policy: string | undefined): Record<string, any> | undefined;
3
13
  //# sourceMappingURL=gateways.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gateways.d.ts","sourceRoot":"","sources":["../../../../src/syncs/apigateway/gateways.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,eAAO,MAAM,YAAY,EAAE,IA2B1B,CAAA"}
1
+ {"version":3,"file":"gateways.d.ts","sourceRoot":"","sources":["../../../../src/syncs/apigateway/gateways.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,eAAO,MAAM,YAAY,EAAE,IA2B1B,CAAA;AAcD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAYjC"}
@@ -1,5 +1,5 @@
1
1
  import { APIGatewayClient, GetRestApisCommand } from '@aws-sdk/client-api-gateway';
2
- import { parseIfPresent } from '../../utils/json.js';
2
+ import { log } from '../../utils/log.js';
3
3
  import { createResourceSyncType, createTypedSyncOperation } from '../typedSync.js';
4
4
  export const RestApisSync = createTypedSyncOperation('apigateway', 'gateways', createResourceSyncType({
5
5
  client: APIGatewayClient,
@@ -9,7 +9,7 @@ export const RestApisSync = createTypedSyncOperation('apigateway', 'gateways', c
9
9
  inputKey: 'position',
10
10
  outputKey: 'position'
11
11
  },
12
- arn: (api, region, account, partition) => restApiArn(api.id, region, account, partition),
12
+ arn: (api, region, account, partition) => restApiArn(api.id, region, partition),
13
13
  tags: (api) => api.tags,
14
14
  resourceTypeParts: (account, region) => ({
15
15
  account,
@@ -22,10 +22,40 @@ export const RestApisSync = createTypedSyncOperation('apigateway', 'gateways', c
22
22
  id: api.id,
23
23
  name: api.name
24
24
  },
25
- policy: parseIfPresent(api.policy)
25
+ policy: parseApiGatewayPolicy(api.id, api.policy)
26
26
  })
27
27
  }));
28
- function restApiArn(apiId, region, account, partition) {
28
+ /**
29
+ * Get the ARN for an API Gateway REST API.
30
+ *
31
+ * @param apiId the ID of the API Gateway REST API
32
+ * @param region the AWS region of the API Gateway
33
+ * @param partition the AWS partition (aws, aws-cn, aws-us-gov)
34
+ * @returns the ARN of the API Gateway REST API
35
+ */
36
+ function restApiArn(apiId, region, partition) {
29
37
  return `arn:${partition}:apigateway:${region}::/restapis/${apiId}`;
30
38
  }
39
+ /**
40
+ * Parse the API Gateway policy string into a JSON object.
41
+ * For some reason API Gateway policies can have \\\ at the start of every string
42
+ * and any forward slash is escaped with a double backslash (\\/)
43
+ *
44
+ * @param apiId the ID of the API Gateway
45
+ * @param policy the policy string to parse
46
+ * @returns the parsed policy object or undefined if the policy is not provided
47
+ */
48
+ export function parseApiGatewayPolicy(apiId, policy) {
49
+ if (!policy) {
50
+ return undefined;
51
+ }
52
+ policy = policy.replace(/\\"/g, '"').replace(/\\\//g, '/');
53
+ try {
54
+ return JSON.parse(policy);
55
+ }
56
+ catch (error) {
57
+ log.error('Failed to parse API Gateway policy', { apiId }, error);
58
+ throw new Error(`Unable to parse policy for API Gateway ${apiId}`);
59
+ }
60
+ }
31
61
  //# sourceMappingURL=gateways.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gateways.js","sourceRoot":"","sources":["../../../../src/syncs/apigateway/gateways.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAElF,MAAM,CAAC,MAAM,YAAY,GAAS,wBAAwB,CACxD,YAAY,EACZ,UAAU,EACV,sBAAsB,CAAC;IACrB,MAAM,EAAE,gBAAgB;IACxB,OAAO,EAAE,kBAAkB;IAC3B,GAAG,EAAE,OAAO;IACZ,gBAAgB,EAAE;QAChB,QAAQ,EAAE,UAAU;QACpB,SAAS,EAAE,UAAU;KACtB;IACD,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAG,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC;IACzF,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI;IACvB,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACvC,OAAO;QACP,OAAO,EAAE,YAAY;QACrB,MAAM;QACN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MAAM;QACN,YAAY,EAAE,UAAU;KACzB,CAAC;IACF,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACjB,QAAQ,EAAE;YACR,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,GAAG,CAAC,IAAI;SACf;QACD,MAAM,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAAG,EAAE,GAAG,CAAC,MAAM,CAAC;KACnD,CAAC;CACH,CAAC,CACH,CAAA;AAED;;;;;;;GAOG;AACH,SAAS,UAAU,CAAC,KAAa,EAAE,MAAc,EAAE,SAAiB;IAClE,OAAO,OAAO,SAAS,eAAe,MAAM,eAAe,KAAK,EAAE,CAAA;AACpE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,MAA0B;IAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAE1D,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,oCAAoC,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,CAAA;QACjE,MAAM,IAAI,KAAK,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAA;IACpE,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-copilot/iam-collect",
3
- "version": "0.1.92",
3
+ "version": "0.1.93",
4
4
  "description": "Collect IAM information from AWS Accounts",
5
5
  "repository": {
6
6
  "type": "git",