"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCloudProductTier = exports.cloudSecurityMetringCallback = exports.CLOUD_SECURITY_TASK_TYPE = exports.AGGREGATION_PRECISION_THRESHOLD = void 0; var _constants = require("@kbn/cloud-security-posture-plugin/common/constants"); var _product = require("../../common/product"); var _cloud_security_metering_task = require("./cloud_security_metering_task"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ const CLOUD_SECURITY_TASK_TYPE = 'cloud_security'; exports.CLOUD_SECURITY_TASK_TYPE = CLOUD_SECURITY_TASK_TYPE; const AGGREGATION_PRECISION_THRESHOLD = 40000; exports.AGGREGATION_PRECISION_THRESHOLD = AGGREGATION_PRECISION_THRESHOLD; const cloudSecurityMetringCallback = async ({ esClient, cloudSetup, logger, taskId, lastSuccessfulReport, config }) => { var _cloudSetup$serverles, _cloudSetup$serverles2; const projectId = (cloudSetup === null || cloudSetup === void 0 ? void 0 : (_cloudSetup$serverles = cloudSetup.serverless) === null || _cloudSetup$serverles === void 0 ? void 0 : _cloudSetup$serverles.projectId) || 'missing_project_id'; if (!(cloudSetup !== null && cloudSetup !== void 0 && (_cloudSetup$serverles2 = cloudSetup.serverless) !== null && _cloudSetup$serverles2 !== void 0 && _cloudSetup$serverles2.projectId)) { logger.error('no project id found'); } const tier = getCloudProductTier(config); try { const postureTypes = [_constants.CSPM_POLICY_TEMPLATE, _constants.KSPM_POLICY_TEMPLATE, _constants.CNVM_POLICY_TEMPLATE]; const cloudSecurityUsageRecords = await Promise.all(postureTypes.map(postureType => (0, _cloud_security_metering_task.getCloudSecurityUsageRecord)({ esClient, projectId, logger, taskId, lastSuccessfulReport, postureType, tier }))); // remove any potential undefined values from the array, return cloudSecurityUsageRecords.filter(Boolean); } catch (err) { logger.error(`Failed to fetch Cloud Security metering data ${err}`); return []; } }; exports.cloudSecurityMetringCallback = cloudSecurityMetringCallback; const getCloudProductTier = config => { const cloud = config.productTypes.find(productType => productType.product_line === _product.ProductLine.cloud); const tier = cloud ? cloud.product_tier : 'none'; return tier; }; exports.getCloudProductTier = getCloudProductTier;