UNPKG

@dsmrt/axiom-aws-sdk

Version:

AWS sdk library for working with axiom cli

129 lines (125 loc) 3.81 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { ParameterCollection: () => ParameterCollection, extractParamValue: () => extractParamValue, getParameters: () => getParameters, getParametersByPath: () => getParametersByPath, ssmClient: () => ssmClient }); module.exports = __toCommonJS(index_exports); // src/ssm-parameters.ts var import_client_ssm = require("@aws-sdk/client-ssm"); var ssmClient = new import_client_ssm.SSMClient({}); var getParametersByPath = async (path, parameters, nextToken, client) => { client ??= ssmClient; let returnParams = parameters || []; const command = new import_client_ssm.GetParametersByPathCommand({ Path: path, Recursive: true, WithDecryption: true, NextToken: nextToken }); const output = await client.send(command); if (output.Parameters !== void 0) { returnParams = [...returnParams, ...output.Parameters]; } if (output.NextToken !== void 0) { return getParametersByPath(path, returnParams, output.NextToken, client); } return returnParams; }; var getParameters = async (names, client) => { client ??= ssmClient; const command = new import_client_ssm.GetParametersCommand({ Names: names, WithDecryption: true }); const result = await client.send(command); if (result.Parameters === void 0) { return []; } return result.Parameters; }; var extractParamValue = (path, name, params) => { const fullName = `${path.replace(/\/$/, "")}/${name}`; const item = params.find((item2) => item2.Name === fullName); if (!item || !item.Value) { throw new Error(`Parameter '${fullName}' is not set.`); } return item.Value; }; // src/ssm-parameter-collection.ts var ParameterCollection = class { constructor(path, client) { this.path = path; this.client = client; } map = /* @__PURE__ */ new Map(); async hasParam(param) { if (this.map.size < 1) { await this.loadParameters(); } return this.map.has(param); } async findParam(param) { if (this.map.size < 1) { await this.loadParameters(); } return this.map.get(param); } async getParam(param) { if (!await this.hasParam(param)) { throw new Error(`Parameter '${param.toString()}' does not exist'`); } return this.map.get(param); } async get() { if (this.map.size < 1) { await this.loadParameters(); } return this.map; } async loadParameters() { if (!this.path) { throw new Error(`Parameter path is not set or is undefined`); } const params = await getParametersByPath( this.path, void 0, void 0, this.client ); params.forEach((param) => { const fullName = param.Name; const name = fullName.replace(`${this.path}/`, ""); this.map.set(name, param); }); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ParameterCollection, extractParamValue, getParameters, getParametersByPath, ssmClient });