UNPKG

envilder

Version:

A CLI and GitHub Action that securely centralizes your environment variables from AWS SSM or Azure Key Vault as a single source of truth

68 lines 2.68 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; /** * {@link ISecretProvider} backed by Azure Key Vault. * * Secrets are fetched in parallel. Secrets that return HTTP 404 * are treated as missing and silently omitted from the result. */ export class AzureKeyVaultSecretProvider { constructor(secretClient) { if (!secretClient) { throw new Error('secretClient cannot be null'); } this.secretClient = secretClient; } getSecrets(names) { return __awaiter(this, void 0, void 0, function* () { const result = new Map(); if (names.length === 0) { return result; } for (const name of names) { if (!(name === null || name === void 0 ? void 0 : name.trim())) { throw new Error('Secret name cannot be null or empty'); } } const entries = yield Promise.all(names.map((name) => __awaiter(this, void 0, void 0, function* () { const value = yield this.fetchSecret(name); return [name, value]; }))); for (const [name, value] of entries) { if (value !== null) { result.set(name, value); } } return result; }); } fetchSecret(name) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const response = yield this.secretClient.getSecret(name); return (_a = response.value) !== null && _a !== void 0 ? _a : null; } catch (error) { if (isNotFound(error)) { return null; } throw error; } }); } } function isNotFound(error) { return (typeof error === 'object' && error !== null && 'statusCode' in error && error.statusCode === 404); } //# sourceMappingURL=azure-key-vault-secret-provider.js.map