UNPKG

@csermet/multiprovider

Version:

cloud-graph provider plugin for AWS used to fetch AWS cloud data.

155 lines (154 loc) 7.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const sdk_1 = require("@cloudgraph/sdk"); const translations_1 = __importDefault(require("../../properties/translations")); const format_1 = require("../../utils/format"); /** * CloudFront */ exports.default = ({ service, account, }) => { const { config: { CallerReference: callerReference, DefaultRootObject: defaultRootObject, HttpVersion: httpVersion, Restrictions: { GeoRestriction: { Items: locations = [], RestrictionType: restrictionType = '', }, } = { GeoRestriction: { RestrictionType: '', Items: [], Quantity: 0 }, }, Logging: logging, }, etag, summary: { ARN: arn, CacheBehaviors: { Items: orderedCacheBehavior = [] } = { Quantity: 0 }, CustomErrorResponses: { Items: cer = [] } = { Quantity: 0 }, DefaultCacheBehavior: defaultCacheBehavior, DomainName: domainName, Enabled: enabled, Id: id, IsIPV6Enabled: isIpv6Enabled, LastModifiedTime: lastModified, Origins: { Items: originData = [] } = { Quantity: 0, Items: [] }, PriceClass: priceClass, Status: status, ViewerCertificate: { ACMCertificateArn: acmCertificateArn, CloudFrontDefaultCertificate: cloudfrontDefaultCertificate, IAMCertificateId: iamCertificateId, MinimumProtocolVersion: minimumProtocolVersion, SSLSupportMethod: sslSupportMethod, } = {}, WebACLId: webAclId, }, Tags = {}, } = service; const createCacheBehavior = (cache) => { const { AllowedMethods: { Items: allowedMethods = [], CachedMethods: { Items: cachedMethods = [] } = { Items: [] }, } = {}, Compress: compress, DefaultTTL: defaultTtl, ForwardedValues: { Headers: { Items: headers } = {}, QueryString: queryString, } = {}, MaxTTL: maxTtl, MinTTL: minTtl, PathPattern: patternPath, SmoothStreaming: smoothStreaming, TargetOriginId: targetOriginId, ViewerProtocolPolicy: viewerProtocolPolicy, } = cache; const forwardedValues = { headers, queryString: queryString ? translations_1.default.yes : translations_1.default.no, }; return { id: sdk_1.generateUniqueId({ arn, ...cache, }), allowedMethods, cachedMethods, compress: compress ? translations_1.default.yes : translations_1.default.no, defaultTtl: defaultTtl ? `${defaultTtl} ${translations_1.default.seconds}` : null, forwardedValues, maxTtl: maxTtl ? `${maxTtl} ${translations_1.default.seconds}` : null, minTtl: minTtl ? `${minTtl} ${translations_1.default.seconds}` : null, patternPath, smoothStreaming: smoothStreaming ? translations_1.default.yes : translations_1.default.no, targetOriginId, viewerProtocolPolicy, }; }; const createDefaultCacheBehavior = (cache) => { const { AllowedMethods: { Items: allowedMethods = [], CachedMethods: { Items: cachedMethods = [] } = { Items: [] }, } = {}, Compress: compress, DefaultTTL: defaultTtl, ForwardedValues: { Headers: { Items: headers } = {}, QueryString: queryString, } = {}, MaxTTL: maxTtl, MinTTL: minTtl, SmoothStreaming: smoothStreaming, TargetOriginId: targetOriginId, ViewerProtocolPolicy: viewerProtocolPolicy, } = cache; const forwardedValues = { headers, queryString: queryString ? translations_1.default.yes : translations_1.default.no, }; return { id: sdk_1.generateUniqueId({ arn, ...cache, }), allowedMethods, cachedMethods, compress: compress ? translations_1.default.yes : translations_1.default.no, defaultTtl: defaultTtl ? `${defaultTtl} ${translations_1.default.seconds}` : null, forwardedValues, maxTtl: maxTtl ? `${maxTtl} ${translations_1.default.seconds}` : null, minTtl: minTtl ? `${minTtl} ${translations_1.default.seconds}` : null, smoothStreaming: smoothStreaming ? translations_1.default.yes : translations_1.default.no, targetOriginId, viewerProtocolPolicy, }; }; const customErrorResponses = cer.map(({ ErrorCachingMinTTL: errorCachingMinTtl, ErrorCode: errorCode, ResponseCode: responseCode, ResponsePagePath: responsePagePath, }) => ({ id: sdk_1.generateUniqueId({ arn, errorCachingMinTtl, errorCode, responseCode, responsePagePath, }), errorCachingMinTtl: `${errorCachingMinTtl} ${translations_1.default.seconds}`, errorCode, responseCode, responsePagePath, })); const viewerCertificate = { acmCertificateArn, cloudfrontDefaultCertificate: cloudfrontDefaultCertificate ? translations_1.default.yes : translations_1.default.no, iamCertificateId, minimumProtocolVersion, sslSupportMethod, }; const origins = originData.map((origin) => { const { CustomHeaders: { Items: customHeader = [] }, CustomOriginConfig: { HTTPPort: httpPort, HTTPSPort: httpsPort, OriginProtocolPolicy: originProtocolPolicy, OriginSslProtocols: { Quantity: quantity, Items: items }, OriginReadTimeout: originReadTimeout, OriginKeepaliveTimeout: originKeepaliveTimeout, } = { HTTPPort: null, HTTPSPort: null, OriginProtocolPolicy: null, OriginSslProtocols: { Quantity: 0, Items: [] }, OriginReadTimeout: null, OriginKeepaliveTimeout: null, }, DomainName: domainName, Id: originId, OriginPath: originPath, } = origin; return { id: sdk_1.generateUniqueId({ arn, ...origin, }), customHeaders: customHeader.map(({ HeaderName, HeaderValue }) => ({ id: sdk_1.generateUniqueId({ arn, HeaderName, HeaderValue, }), name: HeaderName, value: HeaderValue, })), customOriginConfig: { httpPort, httpsPort, originProtocolPolicy, originSslProtocols: { quantity, items }, originReadTimeout, originKeepaliveTimeout, }, domainName, originId, originPath, }; }); const loggingConfig = logging ? { enabled: logging.Enabled, includeCookies: logging.IncludeCookies, bucket: logging.Bucket, prefix: logging.Prefix, } : {}; return { id, accountId: account, arn, callerReference, customErrorResponses, orderedCacheBehaviors: orderedCacheBehavior.map(item => createCacheBehavior(item)), defaultCacheBehavior: createDefaultCacheBehavior(defaultCacheBehavior), defaultRootObject, domainName, enabled: enabled ? translations_1.default.yes : translations_1.default.no, etag, geoRestriction: { restrictionType, locations, }, httpVersion, ipv6Enabled: isIpv6Enabled ? translations_1.default.yes : translations_1.default.no, lastModified: lastModified.toISOString(), origins, priceClass, status, tags: format_1.formatTagsFromMap(Tags), viewerCertificate, webAclId, logging: loggingConfig, }; };