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

37 lines 1.83 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()); }); }; import { SSM } from '@aws-sdk/client-ssm'; import { STS } from '@aws-sdk/client-sts'; import { AwsSsmSecretProvider } from './AwsSsmSecretProvider.js'; export function resolveRegionWithFallback(profile) { return __awaiter(this, void 0, void 0, function* () { if (process.env.AWS_REGION) { return process.env.AWS_REGION; } if (process.env.AWS_DEFAULT_REGION) { return process.env.AWS_DEFAULT_REGION; } try { return yield new SSM(profile ? { profile } : {}).config.region(); } catch (_a) { return 'us-east-1'; } }); } export function createAwsSecretProvider(config, logger) { const { profile } = config; const region = () => resolveRegionWithFallback(profile); const clientConfig = profile ? { profile, region } : { region }; const ssm = new SSM(clientConfig); const sts = new STS(Object.assign(Object.assign({}, clientConfig), { maxAttempts: 1, requestHandler: { requestTimeout: 2000 } })); return new AwsSsmSecretProvider(ssm, logger, sts, profile); } //# sourceMappingURL=AwsSecretProviderFactory.js.map