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
81 lines • 3.78 kB
JavaScript
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 'reflect-metadata';
import { DispatchActionCommand } from '../../../core/application/dispatch/DispatchActionCommand.js';
import { ConsoleLogger } from '../../../core/infrastructure/logger/ConsoleLogger.js';
import { readMapFileConfig } from '../../../core/infrastructure/variableStore/FileVariableStore.js';
import { TYPES } from '../../../core/types.js';
import { presentGhaError } from '../errors/GhaErrorPresenter.js';
import { Startup } from '../Startup.js';
/**
* Reads GitHub Actions inputs from environment variables.
* GitHub Actions passes inputs as INPUT_<NAME> environment variables.
*/
function readInputs() {
const mapFile = process.env.INPUT_MAP_FILE;
const envFile = process.env.INPUT_ENV_FILE;
const provider = process.env.INPUT_PROVIDER;
const vaultUrl = process.env.INPUT_VAULT_URL;
return {
options: {
map: mapFile,
envfile: envFile,
// GitHub Action only supports pull mode
push: false,
},
provider: provider || undefined,
vaultUrl: vaultUrl || undefined,
};
}
function executeCommand(serviceProvider, options) {
return __awaiter(this, void 0, void 0, function* () {
const commandHandler = serviceProvider.get(TYPES.DispatchActionCommandHandler);
const command = DispatchActionCommand.fromCliOptions(options);
yield commandHandler.handleCommand(command);
});
}
export function main() {
return __awaiter(this, void 0, void 0, function* () {
const { options, provider, vaultUrl } = readInputs();
let serviceProvider;
let logger = new ConsoleLogger();
try {
const fileConfig = options.map ? yield readMapFileConfig(options.map) : {};
const config = Object.assign(Object.assign(Object.assign({}, fileConfig), (provider && { provider })), (vaultUrl && { vaultUrl }));
const startup = Startup.build();
startup.configureServices().configureInfrastructure(config);
serviceProvider = startup.create();
logger = serviceProvider.get(TYPES.ILogger);
}
catch (error) {
const message = error instanceof Error ? error.message : String(error);
logger.error(`🚨 Failed to initialize: ${message}`);
throw error;
}
try {
// Validate required inputs
if (!options.map || !options.envfile) {
throw new Error('🚨 Missing required inputs! Please provide map-file and env-file.');
}
logger.info('🔑 Envilder GitHub Action - Starting secret pull...');
logger.info(`📋 Map file: ${options.map}`);
logger.info(`📄 Env file: ${options.envfile}`);
yield executeCommand(serviceProvider, options);
logger.info('✅ Secrets pulled successfully!');
}
catch (error) {
for (const line of presentGhaError(error)) {
logger.error(line);
}
throw error;
}
});
}
//# sourceMappingURL=Gha.js.map