@terra-graph/conventions-aws 1.0.0-rc.1
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/CHANGELOG.md +35 -0
- package/README.md +25 -0
- package/dist/cjs/conventions/dataflow/profiles/base.js +89 -0
- package/dist/cjs/conventions/dataflow/profiles/dot.js +44 -0
- package/dist/cjs/conventions/dataflow/profiles/dot.test.js +147 -0
- package/dist/cjs/conventions/dataflow/rules.js +4 -0
- package/dist/cjs/conventions/dataflow/rules.test.js +11 -0
- package/dist/cjs/conventions/dataflow/rulesets.js +751 -0
- package/dist/cjs/conventions/dataflow/rulesets.test.js +27 -0
- package/dist/cjs/conventions/index.js +7 -0
- package/dist/cjs/conventions/index.test.js +8 -0
- package/dist/cjs/index.js +70 -0
- package/dist/cjs/index.test.js +58 -0
- package/dist/cjs/namespaces.js +14 -0
- package/dist/cjs/namespaces.test.js +17 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugins/AwsApiGateway.js +218 -0
- package/dist/cjs/plugins/AwsApiGateway.test.js +427 -0
- package/dist/cjs/plugins/AwsIam.js +432 -0
- package/dist/cjs/plugins/AwsIam.test.js +468 -0
- package/dist/cjs/plugins/AwsS3.js +107 -0
- package/dist/cjs/plugins/AwsS3.test.js +102 -0
- package/dist/cjs/plugins/AwsSns.js +52 -0
- package/dist/cjs/plugins/AwsSns.test.js +55 -0
- package/dist/cjs/plugins/AwsTransferFamily.js +105 -0
- package/dist/cjs/plugins/AwsTransferFamily.test.js +279 -0
- package/dist/cjs/rules/dot.js +36 -0
- package/dist/cjs/rules/dot.test.js +42 -0
- package/dist/cjs/rules/general.js +69 -0
- package/dist/cjs/rules/general.test.js +47 -0
- package/dist/cjs/rulesets/dot.js +25 -0
- package/dist/cjs/rulesets/dot.test.js +48 -0
- package/dist/esm/conventions/dataflow/profiles/base.d.ts +4 -0
- package/dist/esm/conventions/dataflow/profiles/base.js +86 -0
- package/dist/esm/conventions/dataflow/profiles/dot.d.ts +4 -0
- package/dist/esm/conventions/dataflow/profiles/dot.js +38 -0
- package/dist/esm/conventions/dataflow/profiles/dot.test.d.ts +1 -0
- package/dist/esm/conventions/dataflow/profiles/dot.test.js +109 -0
- package/dist/esm/conventions/dataflow/rules.d.ts +3 -0
- package/dist/esm/conventions/dataflow/rules.js +2 -0
- package/dist/esm/conventions/dataflow/rules.test.d.ts +1 -0
- package/dist/esm/conventions/dataflow/rules.test.js +6 -0
- package/dist/esm/conventions/dataflow/rulesets.d.ts +3 -0
- package/dist/esm/conventions/dataflow/rulesets.js +749 -0
- package/dist/esm/conventions/dataflow/rulesets.test.d.ts +1 -0
- package/dist/esm/conventions/dataflow/rulesets.test.js +22 -0
- package/dist/esm/conventions/index.d.ts +3 -0
- package/dist/esm/conventions/index.js +4 -0
- package/dist/esm/conventions/index.test.d.ts +1 -0
- package/dist/esm/conventions/index.test.js +6 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.test.d.ts +1 -0
- package/dist/esm/index.test.js +53 -0
- package/dist/esm/namespaces.d.ts +7 -0
- package/dist/esm/namespaces.js +6 -0
- package/dist/esm/namespaces.test.d.ts +1 -0
- package/dist/esm/namespaces.test.js +15 -0
- package/dist/esm/plugins/AwsApiGateway.d.ts +6 -0
- package/dist/esm/plugins/AwsApiGateway.js +214 -0
- package/dist/esm/plugins/AwsApiGateway.test.d.ts +1 -0
- package/dist/esm/plugins/AwsApiGateway.test.js +425 -0
- package/dist/esm/plugins/AwsIam.d.ts +32 -0
- package/dist/esm/plugins/AwsIam.js +428 -0
- package/dist/esm/plugins/AwsIam.test.d.ts +1 -0
- package/dist/esm/plugins/AwsIam.test.js +466 -0
- package/dist/esm/plugins/AwsS3.d.ts +12 -0
- package/dist/esm/plugins/AwsS3.js +103 -0
- package/dist/esm/plugins/AwsS3.test.d.ts +1 -0
- package/dist/esm/plugins/AwsS3.test.js +100 -0
- package/dist/esm/plugins/AwsSns.d.ts +6 -0
- package/dist/esm/plugins/AwsSns.js +48 -0
- package/dist/esm/plugins/AwsSns.test.d.ts +1 -0
- package/dist/esm/plugins/AwsSns.test.js +53 -0
- package/dist/esm/plugins/AwsTransferFamily.d.ts +6 -0
- package/dist/esm/plugins/AwsTransferFamily.js +101 -0
- package/dist/esm/plugins/AwsTransferFamily.test.d.ts +1 -0
- package/dist/esm/plugins/AwsTransferFamily.test.js +277 -0
- package/dist/esm/rules/dot.d.ts +3 -0
- package/dist/esm/rules/dot.js +34 -0
- package/dist/esm/rules/dot.test.d.ts +1 -0
- package/dist/esm/rules/dot.test.js +37 -0
- package/dist/esm/rules/general.d.ts +3 -0
- package/dist/esm/rules/general.js +67 -0
- package/dist/esm/rules/general.test.d.ts +1 -0
- package/dist/esm/rules/general.test.js +42 -0
- package/dist/esm/rulesets/dot.d.ts +3 -0
- package/dist/esm/rulesets/dot.js +23 -0
- package/dist/esm/rulesets/dot.test.d.ts +1 -0
- package/dist/esm/rulesets/dot.test.js +43 -0
- package/package.json +45 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const namespaces_js_1 = require("../../namespaces.js");
|
|
7
|
+
const index_js_1 = require("../index.js");
|
|
8
|
+
const rules_js_1 = __importDefault(require("./rules.js"));
|
|
9
|
+
const rulesets_js_1 = __importDefault(require("./rulesets.js"));
|
|
10
|
+
describe('dataflow convention rule sets', () => {
|
|
11
|
+
it('shoud register the dataflow semantics ruleset', () => {
|
|
12
|
+
const names = rulesets_js_1.default.names();
|
|
13
|
+
expect(names).toHaveLength(2);
|
|
14
|
+
expect(names).toEqual(expect.arrayContaining([
|
|
15
|
+
(0, namespaces_js_1.conventionName)(index_js_1.Convention.DataFlow, (0, namespaces_js_1.ruleSetName)('cleanup')),
|
|
16
|
+
(0, namespaces_js_1.conventionName)(index_js_1.Convention.DataFlow, (0, namespaces_js_1.ruleSetName)('semantics')),
|
|
17
|
+
]));
|
|
18
|
+
});
|
|
19
|
+
it('shoud expand all semantic rules from the semantics rule set', () => {
|
|
20
|
+
const ruleSet = rulesets_js_1.default.resolve((0, namespaces_js_1.conventionName)(index_js_1.Convention.DataFlow, (0, namespaces_js_1.ruleSetName)('semantics')));
|
|
21
|
+
const phases = ruleSet.resolvePhases(rules_js_1.default);
|
|
22
|
+
expect(phases).toHaveLength(1);
|
|
23
|
+
const phaseRuleIds = phases[0].map((rule) => rule.serialize().id);
|
|
24
|
+
expect(phaseRuleIds).toContain('EdgeSemanticLegend');
|
|
25
|
+
expect(phaseRuleIds.filter((id) => id === 'EdgeDirectionSemantic').length).toBeGreaterThan(13);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_js_1 = require("./index.js");
|
|
4
|
+
describe('Convention enum', () => {
|
|
5
|
+
it('shoud expose the dataflow convention namespace', () => {
|
|
6
|
+
expect(index_js_1.Convention.DataFlow).toBe('dataflow');
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const core_1 = require("@terra-graph/core");
|
|
40
|
+
const base_js_1 = __importStar(require("./conventions/dataflow/profiles/base.js"));
|
|
41
|
+
const dot_js_1 = __importStar(require("./conventions/dataflow/profiles/dot.js"));
|
|
42
|
+
const rules_js_1 = __importDefault(require("./conventions/dataflow/rules.js"));
|
|
43
|
+
const rulesets_js_1 = __importDefault(require("./conventions/dataflow/rulesets.js"));
|
|
44
|
+
const AwsApiGateway_js_1 = require("./plugins/AwsApiGateway.js");
|
|
45
|
+
const AwsIam_js_1 = require("./plugins/AwsIam.js");
|
|
46
|
+
const AwsS3_js_1 = require("./plugins/AwsS3.js");
|
|
47
|
+
const AwsSns_js_1 = require("./plugins/AwsSns.js");
|
|
48
|
+
const AwsTransferFamily_js_1 = require("./plugins/AwsTransferFamily.js");
|
|
49
|
+
const dot_js_2 = __importDefault(require("./rules/dot.js"));
|
|
50
|
+
const general_js_1 = __importDefault(require("./rules/general.js"));
|
|
51
|
+
const dot_js_3 = __importDefault(require("./rulesets/dot.js"));
|
|
52
|
+
exports.default = () => ({
|
|
53
|
+
namedRules: core_1.NamedRuleRegistry.from([general_js_1.default, dot_js_2.default, rules_js_1.default]),
|
|
54
|
+
namedRuleSets: core_1.NamedRuleSetRegistry.from([dot_js_3.default, rulesets_js_1.default]),
|
|
55
|
+
profiles: new core_1.ProfileRegistry({
|
|
56
|
+
[dot_js_1.conventionDataFlowDotProfileName]: dot_js_1.default,
|
|
57
|
+
[base_js_1.conventionDataFlowBaseProfileName]: base_js_1.default,
|
|
58
|
+
}),
|
|
59
|
+
plugins: new core_1.GraphPluginRegistry({
|
|
60
|
+
[AwsApiGateway_js_1.AwsApiGateway.id]: new AwsApiGateway_js_1.AwsApiGateway(),
|
|
61
|
+
[AwsIam_js_1.AwsIamGraphPlugin.id]: new AwsIam_js_1.AwsIamGraphPlugin(),
|
|
62
|
+
[AwsS3_js_1.AwsS3.id]: new AwsS3_js_1.AwsS3(),
|
|
63
|
+
[AwsSns_js_1.AwsSns.id]: new AwsSns_js_1.AwsSns(),
|
|
64
|
+
[AwsTransferFamily_js_1.AwsTransferFamily.id]: new AwsTransferFamily_js_1.AwsTransferFamily(),
|
|
65
|
+
}),
|
|
66
|
+
supportedAdapterOperationsRegistry: {
|
|
67
|
+
DotAdapter: core_1.DotAdapter,
|
|
68
|
+
// GraphologyAdapter,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@terra-graph/core");
|
|
7
|
+
const base_js_1 = require("./conventions/dataflow/profiles/base.js");
|
|
8
|
+
const dot_js_1 = require("./conventions/dataflow/profiles/dot.js");
|
|
9
|
+
const rules_js_1 = __importDefault(require("./conventions/dataflow/rules.js"));
|
|
10
|
+
const index_js_1 = require("./conventions/index.js");
|
|
11
|
+
const index_js_2 = __importDefault(require("./index.js"));
|
|
12
|
+
const namespaces_js_1 = require("./namespaces.js");
|
|
13
|
+
const AwsApiGateway_js_1 = require("./plugins/AwsApiGateway.js");
|
|
14
|
+
const AwsIam_js_1 = require("./plugins/AwsIam.js");
|
|
15
|
+
const AwsS3_js_1 = require("./plugins/AwsS3.js");
|
|
16
|
+
const AwsSns_js_1 = require("./plugins/AwsSns.js");
|
|
17
|
+
const AwsTransferFamily_js_1 = require("./plugins/AwsTransferFamily.js");
|
|
18
|
+
const assertRuntime = (runtime) => {
|
|
19
|
+
const { supportedAdapterOperationsRegistry, plugins, namedRules, namedRuleSets, profiles } = runtime;
|
|
20
|
+
if (!supportedAdapterOperationsRegistry ||
|
|
21
|
+
!plugins ||
|
|
22
|
+
!namedRules ||
|
|
23
|
+
!namedRuleSets ||
|
|
24
|
+
!profiles) {
|
|
25
|
+
throw new Error('Runtime provider missing expected registries');
|
|
26
|
+
}
|
|
27
|
+
return { supportedAdapterOperationsRegistry, plugins, namedRules, namedRuleSets, profiles };
|
|
28
|
+
};
|
|
29
|
+
describe('aws provider', () => {
|
|
30
|
+
it('shoud expose a complete runtime provider with all registrations', () => {
|
|
31
|
+
const runtime = (0, index_js_2.default)();
|
|
32
|
+
const { supportedAdapterOperationsRegistry, plugins, namedRules, namedRuleSets, profiles } = assertRuntime(runtime);
|
|
33
|
+
expect(supportedAdapterOperationsRegistry.DotAdapter).toBe(core_1.DotAdapter);
|
|
34
|
+
expect(plugins.names().sort()).toStrictEqual([AwsApiGateway_js_1.AwsApiGateway.id, AwsIam_js_1.AwsIamGraphPlugin.id, AwsS3_js_1.AwsS3.id, AwsSns_js_1.AwsSns.id, AwsTransferFamily_js_1.AwsTransferFamily.id].sort());
|
|
35
|
+
expect(namedRules.names().sort()).toEqual([
|
|
36
|
+
(0, namespaces_js_1.ruleName)('data.remove'),
|
|
37
|
+
(0, namespaces_js_1.ruleName)('log_groups.only_event_bridge'),
|
|
38
|
+
(0, namespaces_js_1.ruleName)('lambda.only_event_source_mapping'),
|
|
39
|
+
(0, namespaces_js_1.ruleName)('dot.sqs.dlq.align'),
|
|
40
|
+
(0, namespaces_js_1.ruleName)('dot.schedule.align'),
|
|
41
|
+
(0, namespaces_js_1.ruleName)('dot.iam_role.align'),
|
|
42
|
+
...rules_js_1.default.names(),
|
|
43
|
+
].sort());
|
|
44
|
+
expect(namedRuleSets.names().sort()).toEqual([
|
|
45
|
+
(0, namespaces_js_1.ruleSetName)('dot.sqs.dlq'),
|
|
46
|
+
(0, namespaces_js_1.conventionName)(index_js_1.Convention.DataFlow, (0, namespaces_js_1.ruleSetName)('cleanup')),
|
|
47
|
+
(0, namespaces_js_1.conventionName)(index_js_1.Convention.DataFlow, (0, namespaces_js_1.ruleSetName)('semantics')),
|
|
48
|
+
].sort());
|
|
49
|
+
expect(profiles.names().sort()).toEqual([base_js_1.conventionDataFlowBaseProfileName, dot_js_1.conventionDataFlowDotProfileName].sort());
|
|
50
|
+
});
|
|
51
|
+
it('shoud aggregate rule registries without losing named registration count', () => {
|
|
52
|
+
const runtime = (0, index_js_2.default)();
|
|
53
|
+
const { namedRules, namedRuleSets, profiles } = assertRuntime(runtime);
|
|
54
|
+
expect(namedRules.names().length).toBe(6);
|
|
55
|
+
expect(namedRuleSets.names().length).toBe(3);
|
|
56
|
+
expect(profiles.names().length).toBe(2);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.conventionName = exports.profileName = exports.ruleSetName = exports.ruleName = exports.pluginId = exports.PACKAGE_NAMESPACE = void 0;
|
|
4
|
+
exports.PACKAGE_NAMESPACE = '@terra-graph/conventions-aws';
|
|
5
|
+
const pluginId = (pluginName) => `${exports.PACKAGE_NAMESPACE}:plugin:${pluginName}`;
|
|
6
|
+
exports.pluginId = pluginId;
|
|
7
|
+
const ruleName = (ruleName) => `${exports.PACKAGE_NAMESPACE}:rule:${ruleName}`;
|
|
8
|
+
exports.ruleName = ruleName;
|
|
9
|
+
const ruleSetName = (ruleSetName) => `${exports.PACKAGE_NAMESPACE}:ruleset:${ruleSetName}`;
|
|
10
|
+
exports.ruleSetName = ruleSetName;
|
|
11
|
+
const profileName = (profileName) => `${exports.PACKAGE_NAMESPACE}:profile:${profileName}`;
|
|
12
|
+
exports.profileName = profileName;
|
|
13
|
+
const conventionName = (conventionName, thing) => `convention:${conventionName.toString()}:${thing}`;
|
|
14
|
+
exports.conventionName = conventionName;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_js_1 = require("./conventions/index.js");
|
|
4
|
+
const namespaces_js_1 = require("./namespaces.js");
|
|
5
|
+
describe('namespaces helpers', () => {
|
|
6
|
+
it('shoud prefix identifiers with the package namespace', () => {
|
|
7
|
+
expect(namespaces_js_1.PACKAGE_NAMESPACE).toBe('@terra-graph/conventions-aws');
|
|
8
|
+
expect((0, namespaces_js_1.pluginId)('aws.AwsS3')).toBe('@terra-graph/conventions-aws:plugin:aws.AwsS3');
|
|
9
|
+
expect((0, namespaces_js_1.ruleName)('data.remove')).toBe('@terra-graph/conventions-aws:rule:data.remove');
|
|
10
|
+
expect((0, namespaces_js_1.ruleSetName)('dot.sqs.dlq')).toBe('@terra-graph/conventions-aws:ruleset:dot.sqs.dlq');
|
|
11
|
+
expect((0, namespaces_js_1.profileName)('core')).toBe('@terra-graph/conventions-aws:profile:core');
|
|
12
|
+
});
|
|
13
|
+
it('shoud compose convention-aware names', () => {
|
|
14
|
+
expect((0, namespaces_js_1.conventionName)(index_js_1.Convention.DataFlow, 'dot')).toBe('convention:dataflow:dot');
|
|
15
|
+
expect((0, namespaces_js_1.conventionName)(index_js_1.Convention.DataFlow, (0, namespaces_js_1.ruleName)('legend'))).toBe('convention:dataflow:@terra-graph/conventions-aws:rule:legend');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AwsApiGateway = void 0;
|
|
4
|
+
const core_1 = require("@terra-graph/core");
|
|
5
|
+
const namespaces_js_1 = require("../namespaces.js");
|
|
6
|
+
class CompressApiGatewayResourcePath extends core_1.NodeRule {
|
|
7
|
+
constructor() {
|
|
8
|
+
super({
|
|
9
|
+
node: {
|
|
10
|
+
attr: {
|
|
11
|
+
key: 'terraform.resource',
|
|
12
|
+
eq: 'aws_api_gateway_rest_api',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
apply(nodeId, _node, graph) {
|
|
18
|
+
if (!this.wasMatched(nodeId)) {
|
|
19
|
+
return graph;
|
|
20
|
+
}
|
|
21
|
+
const toRemove = [];
|
|
22
|
+
const collect = (currentNodeId) => {
|
|
23
|
+
const previous = graph.predecessors(currentNodeId);
|
|
24
|
+
if (previous.length !== 1) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const previousNodeId = previous[0];
|
|
28
|
+
const previousNode = graph.getNodeAttributes(previousNodeId);
|
|
29
|
+
if (previousNode?.terraform?.resource !== 'aws_api_gateway_resource') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
toRemove.push(previousNodeId);
|
|
33
|
+
collect(previousNodeId);
|
|
34
|
+
};
|
|
35
|
+
collect(nodeId);
|
|
36
|
+
if (toRemove.length === 0) {
|
|
37
|
+
return graph;
|
|
38
|
+
}
|
|
39
|
+
const closestResourceNodeId = toRemove[0];
|
|
40
|
+
const furthestResourceNodeId = toRemove[toRemove.length - 1];
|
|
41
|
+
const closestResourceNode = graph.getNodeAttributes(closestResourceNodeId);
|
|
42
|
+
if (!closestResourceNode) {
|
|
43
|
+
return graph;
|
|
44
|
+
}
|
|
45
|
+
const resourcePath = toRemove
|
|
46
|
+
.map((resourceNodeId) => {
|
|
47
|
+
const resourceNode = graph.getNodeAttributes(resourceNodeId);
|
|
48
|
+
return resourceNode?.terraform?.name ?? String(resourceNodeId);
|
|
49
|
+
})
|
|
50
|
+
.join('/');
|
|
51
|
+
const resourceAddress = `aws_api_gateway_resource.${resourcePath}`;
|
|
52
|
+
const compressedNodeId = (0, core_1.tgNodeIdFrom)('resource', resourceAddress);
|
|
53
|
+
let updated = graph.setNodeAttributes(compressedNodeId, {
|
|
54
|
+
...closestResourceNode,
|
|
55
|
+
terraform: {
|
|
56
|
+
...closestResourceNode.terraform,
|
|
57
|
+
kind: 'resource',
|
|
58
|
+
address: resourceAddress,
|
|
59
|
+
resource: 'aws_api_gateway_resource',
|
|
60
|
+
name: resourcePath,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const outEdges = graph.outEdges(closestResourceNodeId);
|
|
64
|
+
for (const outEdgeId of outEdges) {
|
|
65
|
+
const targetId = graph.edgeTarget(outEdgeId);
|
|
66
|
+
const edgeAttributes = graph.getEdgeAttributes(outEdgeId);
|
|
67
|
+
const redirectedEdgeId = (0, core_1.edgeIdFrom)(compressedNodeId, targetId, `apigateway:compress:out:${outEdgeId}`);
|
|
68
|
+
updated = updated.setEdge(redirectedEdgeId, compressedNodeId, targetId, edgeAttributes);
|
|
69
|
+
}
|
|
70
|
+
const inEdges = graph.inEdges(furthestResourceNodeId);
|
|
71
|
+
for (const inEdgeId of inEdges) {
|
|
72
|
+
const sourceId = graph.edgeSource(inEdgeId);
|
|
73
|
+
const edgeAttributes = graph.getEdgeAttributes(inEdgeId);
|
|
74
|
+
const redirectedEdgeId = (0, core_1.edgeIdFrom)(sourceId, compressedNodeId, `apigateway:compress:in:${inEdgeId}`);
|
|
75
|
+
updated = updated.setEdge(redirectedEdgeId, sourceId, compressedNodeId, edgeAttributes);
|
|
76
|
+
}
|
|
77
|
+
for (const resourceNodeId of toRemove) {
|
|
78
|
+
updated = updated.removeNode(resourceNodeId);
|
|
79
|
+
}
|
|
80
|
+
return updated;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class AwsApiGateway extends core_1.GraphPlugin {
|
|
84
|
+
static id = (0, namespaces_js_1.pluginId)(`aws.${AwsApiGateway.name}`);
|
|
85
|
+
constructor() {
|
|
86
|
+
super(AwsApiGateway.id);
|
|
87
|
+
}
|
|
88
|
+
build(_input) {
|
|
89
|
+
return {
|
|
90
|
+
phases: [
|
|
91
|
+
{
|
|
92
|
+
phase: 'main',
|
|
93
|
+
rules: [
|
|
94
|
+
new core_1.RemoveNode({
|
|
95
|
+
node: {
|
|
96
|
+
attr: {
|
|
97
|
+
key: 'terraform.resource',
|
|
98
|
+
in: [
|
|
99
|
+
'aws_api_gateway_integration_response',
|
|
100
|
+
'aws_api_gateway_method_response',
|
|
101
|
+
'aws_api_gateway_method_settings',
|
|
102
|
+
'aws_api_gateway_account',
|
|
103
|
+
'aws_api_gateway_model',
|
|
104
|
+
'aws_wafv2_web_acl_logging_configuration',
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
{ phase: 'main', rules: [new CompressApiGatewayResourcePath()] },
|
|
112
|
+
{
|
|
113
|
+
phase: 'main',
|
|
114
|
+
rules: [
|
|
115
|
+
new core_1.EdgeReverse({
|
|
116
|
+
edge: {
|
|
117
|
+
from: {
|
|
118
|
+
attr: {
|
|
119
|
+
key: 'terraform.resource',
|
|
120
|
+
eq: 'aws_api_gateway_rest_api',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
to: {
|
|
124
|
+
attr: {
|
|
125
|
+
key: 'terraform.resource',
|
|
126
|
+
eq: 'aws_api_gateway_resource',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
new core_1.EdgeReverse({
|
|
132
|
+
edge: {
|
|
133
|
+
from: {
|
|
134
|
+
attr: {
|
|
135
|
+
key: 'terraform.resource',
|
|
136
|
+
eq: 'aws_api_gateway_method',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
to: {
|
|
140
|
+
attr: {
|
|
141
|
+
key: 'terraform.resource',
|
|
142
|
+
eq: 'aws_api_gateway_integration',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
new core_1.EdgeReverse({
|
|
148
|
+
edge: {
|
|
149
|
+
from: {
|
|
150
|
+
attr: {
|
|
151
|
+
key: 'terraform.resource',
|
|
152
|
+
eq: 'aws_api_gateway_resource',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
to: {
|
|
156
|
+
attr: {
|
|
157
|
+
key: 'terraform.resource',
|
|
158
|
+
eq: 'aws_api_gateway_method',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
163
|
+
new core_1.EdgeReverse({
|
|
164
|
+
edge: {
|
|
165
|
+
from: {
|
|
166
|
+
attr: {
|
|
167
|
+
key: 'terraform.resource',
|
|
168
|
+
eq: 'aws_wafv2_web_acl',
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
to: {
|
|
172
|
+
attr: {
|
|
173
|
+
key: 'terraform.resource',
|
|
174
|
+
eq: 'aws_wafv2_web_acl_association',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
new core_1.EdgeReverse({
|
|
180
|
+
edge: {
|
|
181
|
+
from: {
|
|
182
|
+
attr: {
|
|
183
|
+
key: 'terraform.resource',
|
|
184
|
+
eq: 'aws_wafv2_ip_set',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
to: {
|
|
188
|
+
attr: {
|
|
189
|
+
key: 'terraform.resource',
|
|
190
|
+
eq: 'aws_wafv2_web_acl',
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
phase: 'main',
|
|
199
|
+
rules: [
|
|
200
|
+
new core_1.ConvertNodeToEdge({
|
|
201
|
+
node: {
|
|
202
|
+
attr: {
|
|
203
|
+
key: 'terraform.resource',
|
|
204
|
+
in: [
|
|
205
|
+
'aws_api_gateway_deployment',
|
|
206
|
+
'aws_api_gateway_method',
|
|
207
|
+
'aws_wafv2_web_acl_association',
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
}),
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.AwsApiGateway = AwsApiGateway;
|