@csermet/multiprovider
Version:
cloud-graph provider plugin for AWS used to fetch AWS cloud data.
72 lines (71 loc) • 2.74 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
const services_1 = __importDefault(require("../../enums/services"));
/**
* WAF
*/
exports.default = ({ service: waf, data, region, }) => {
const connections = [];
const { Id: id, wafResources } = waf;
/**
* Find ALBs
* related to this WAF
*/
const albs = data.find(({ name }) => name === services_1.default.alb);
if (albs?.data?.[region] && wafResources?.elasticloadbalancing?.length > 0) {
const associatedALBs = albs.data[region].filter(({ LoadBalancerArn }) => wafResources?.elasticloadbalancing?.find(arn => arn === LoadBalancerArn));
if (!isEmpty_1.default(associatedALBs)) {
for (const { LoadBalancerArn } of associatedALBs) {
connections.push({
id: LoadBalancerArn,
resourceType: services_1.default.alb,
relation: 'child',
field: 'albs',
});
}
}
}
/**
* Find Rest API Stages
* related to this WAF
*/
const stages = data.find(({ name }) => name === services_1.default.apiGatewayStage);
if (stages?.data?.[region] && wafResources?.apigateway?.length > 0) {
const associatedStages = stages.data[region].filter(({ arn: stageArn }) => wafResources?.apigateway?.find(arn => arn === stageArn));
if (!isEmpty_1.default(associatedStages)) {
for (const { arn } of associatedStages) {
connections.push({
id: arn,
resourceType: services_1.default.apiGatewayStage,
relation: 'child',
field: 'apiGatewayStages',
});
}
}
}
/**
* Find Apps Sync
* related to this WAF
*/
const apps = data.find(({ name }) => name === services_1.default.appSync);
if (apps?.data?.[region] && wafResources?.appsync?.length > 0) {
const associatedApps = apps.data[region].filter(({ arn: apiArn }) => wafResources?.appsync?.find(arn => arn === apiArn));
if (!isEmpty_1.default(associatedApps)) {
for (const { apiId } of associatedApps) {
connections.push({
id: apiId,
resourceType: services_1.default.appSync,
relation: 'child',
field: 'appSync',
});
}
}
}
return {
[id]: connections,
};
};