UNPKG

@csermet/multiprovider

Version:

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

206 lines (205 loc) 8.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sdk_1 = require("@cloudgraph/sdk"); const lodash_1 = require("lodash"); const format_1 = require("../../utils/format"); const formatKeySchema = (KeySchema) => KeySchema.map(({ AttributeName: attributeName, KeyType: keyType }) => ({ id: sdk_1.generateUniqueId({ attributeName, keyType, }), attributeName, keyType, })); const formatProvisionedThroughput = (provisionedThroughput = {}) => { const { LastIncreaseDateTime: lastIncreaseDateTime, LastDecreaseDateTime: lastDecreaseDateTime, NumberOfDecreasesToday: numberOfDecreasesToday, ReadCapacityUnits: readCapacityUnits, WriteCapacityUnits: writeCapacityUnits, } = provisionedThroughput; return { ...(lastIncreaseDateTime ? { lastIncreaseDateTime: lastIncreaseDateTime.toString(), } : {}), ...(lastDecreaseDateTime ? { lastDecreaseDateTime: lastDecreaseDateTime.toString(), } : {}), numberOfDecreasesToday, readCapacityUnits, writeCapacityUnits, }; }; const formatProjection = (projection = {}) => { const { ProjectionType: type, NonKeyAttributes: nonKeyAttributes = [] } = projection; return { type, nonKeyAttributes, }; }; const formatAutoScalingSettingsDescription = (setting = {}) => { if (lodash_1.isEmpty(setting)) { return {}; } const { MinimumUnits: minimumUnits, MaximumUnits: maximumUnits, AutoScalingDisabled: autoScalingDisabled, AutoScalingRoleArn: autoScalingRoleArn, ScalingPolicies: scalingPolicies = [], } = setting; return { minimumUnits, maximumUnits, autoScalingDisabled, autoScalingRoleArn, scalingPolicies: scalingPolicies?.map(({ PolicyName: policyName, TargetTrackingScalingPolicyConfiguration: config, }) => ({ id: sdk_1.generateUniqueId({ setting, policyName, config, }), policyName, disableScaleIn: config?.DisableScaleIn, scaleInCooldown: config?.ScaleInCooldown, scaleOutCooldown: config?.ScaleOutCooldown, targetValue: config?.TargetValue, })), }; }; /** * DynamoDB */ exports.default = ({ service: dynamoDbTable, account, region, }) => { const { TableId: id, TableName: name, TableArn: arn, CreationDateTime: creationDate, AttributeDefinitions = [], BillingModeSummary: { BillingMode: billingMode, LastUpdateToPayPerRequestDateTime: lastUpdateToPayPerRequestDateTime, } = {}, GlobalSecondaryIndexes = [], GlobalTableVersion: globalTableVersion, LatestStreamArn: latestStreamArn, LatestStreamLabel: latestStreamLabel, LocalSecondaryIndexes = [], ItemCount: itemCount, KeySchema: TableKeySchema = [], ProvisionedThroughput: TableProvisionedThroughput = {}, ttlEnabled, pointInTimeRecoveryEnabled, Replicas = [], RestoreSummary: { SourceBackupArn: sourceBackupArn, SourceTableArn: sourceTableArn, RestoreDateTime: restoreDateTime, RestoreInProgress: restoreInProgress, } = {}, SSEDescription: { Status: sseStatus, SSEType: sseType, KMSMasterKeyArn: sseKmsMasterKeyArn, InaccessibleEncryptionDateTime: sseInaccessibleEncryptionDateTime, } = {}, StreamSpecification: { StreamEnabled: streamsEnabled, StreamViewType: streamViewType, } = {}, TableStatus, TableSizeBytes, Tags = {}, } = dynamoDbTable; const attributes = AttributeDefinitions.map(({ AttributeName, AttributeType: type }) => ({ id: sdk_1.generateUniqueId({ arn, AttributeName, type, }), name: AttributeName, type, })); const billingModeSummary = { billingMode, ...(lastUpdateToPayPerRequestDateTime ? { lastUpdateToPayPerRequestDateTime: lastUpdateToPayPerRequestDateTime.toString(), } : {}), }; const globalIndexes = GlobalSecondaryIndexes.map(({ IndexName, KeySchema, ItemCount, Projection: globalIndexProjection = {}, IndexSizeBytes: sizeInBytes, IndexStatus: status, Backfilling: backfilling, ProvisionedThroughput: globalIndexProvisionedThroughput = {}, }) => ({ id: sdk_1.generateUniqueId({ arn, IndexName, KeySchema, ItemCount, globalIndexProjection, sizeInBytes, status, backfilling, globalIndexProvisionedThroughput, }), name: IndexName, arn, itemCount: ItemCount, keySchema: formatKeySchema(KeySchema), projection: formatProjection(globalIndexProjection), sizeInBytes, status, backfilling, provisionedThroughput: formatProvisionedThroughput(globalIndexProvisionedThroughput), })); const localIndexes = LocalSecondaryIndexes.map(({ IndexName, KeySchema, ItemCount, Projection: localndexProjection = {}, IndexSizeBytes: sizeInBytes, }) => ({ id: sdk_1.generateUniqueId({ arn, IndexName, KeySchema, ItemCount, localndexProjection, sizeInBytes, }), name: IndexName, arn, itemCount: ItemCount, keySchema: formatKeySchema(KeySchema), projection: formatProjection(localndexProjection), sizeInBytes, })); const replicas = Replicas.map(replica => { const { RegionName: regionName, ReplicaStatus, ReplicaStatusDescription, ReplicaStatusPercentProgress, KMSMasterKeyId, ProvisionedThroughputOverride, GlobalSecondaryIndexes: ReplicasGlobalSecondaryIndexes = [], ReplicaInaccessibleDateTime, AutoScaling: { ReplicaProvisionedReadCapacityAutoScalingSettings: readCapacityAutoScalingSettings = {}, ReplicaProvisionedWriteCapacityAutoScalingSettings: writeCapacityAutoScalingSettings = {}, } = {}, } = replica; return { id: sdk_1.generateUniqueId({ arn, ...replica, }), regionName, status: ReplicaStatus, statusDescription: ReplicaStatusDescription, statusPercentProgress: ReplicaStatusPercentProgress, kmsMasterKeyId: KMSMasterKeyId, provisionedThroughput: ProvisionedThroughputOverride, globalSecondaryIndexes: ReplicasGlobalSecondaryIndexes.map(({ IndexName, ProvisionedThroughputOverride: { ReadCapacityUnits: readCapacityUnits, }, }) => ({ id: sdk_1.generateUniqueId({ arn, IndexName, ProvisionedThroughputOverride, }), name: IndexName, readCapacityUnits, })), ...(ReplicaInaccessibleDateTime ? { replicaInaccessibleDateTime: ReplicaInaccessibleDateTime.toString(), } : {}), provisionedReadCapacityAutoScalingSettings: formatAutoScalingSettingsDescription(readCapacityAutoScalingSettings), provisionedWriteCapacityAutoScalingSettings: formatAutoScalingSettingsDescription(writeCapacityAutoScalingSettings), }; }); const restoreSummary = { sourceBackupArn, sourceTableArn, ...(restoreDateTime ? { restoreDateTime: restoreDateTime.toString() } : {}), ...(restoreInProgress ? { restoreInProgress: restoreInProgress.toString(), } : {}), }; const sseDescription = { status: sseStatus, sseType, kmsMasterKeyArn: sseKmsMasterKeyArn, ...(sseInaccessibleEncryptionDateTime ? { inaccessibleEncryptionDateTime: sseInaccessibleEncryptionDateTime.toString(), } : {}), }; const streamSpecification = { streamsEnabled, streamViewType, }; return { id, arn, region, accountId: account, attributes, billingModeSummary, creationDate: creationDate.toString(), globalIndexes, globalTableVersion, itemCount, keySchema: formatKeySchema(TableKeySchema), latestStreamArn, latestStreamLabel, localIndexes, name, pointInTimeRecoveryEnabled, provisionedThroughput: formatProvisionedThroughput(TableProvisionedThroughput), replicas, restoreSummary, sizeInBytes: TableSizeBytes, sseDescription, status: TableStatus, streamSpecification, tags: format_1.formatTagsFromMap(Tags), ttlEnabled, }; };