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
105 lines • 5.47 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
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 { inject, injectable } from 'inversify';
import { InvalidArgumentError } from '../../domain/errors/DomainErrors.js';
import { OperationMode } from '../../domain/OperationMode.js';
import { TYPES } from '../../types.js';
import { PullSecretsToEnvCommand } from '../pullSecretsToEnv/PullSecretsToEnvCommand.js';
import { PushEnvToSecretsCommand } from '../pushEnvToSecrets/PushEnvToSecretsCommand.js';
import { PushSingleCommand } from '../pushSingle/PushSingleCommand.js';
let DispatchActionCommandHandler = class DispatchActionCommandHandler {
constructor(pullHandler, pushHandler, pushSingleHandler, secretProvider) {
this.pullHandler = pullHandler;
this.pushHandler = pushHandler;
this.pushSingleHandler = pushSingleHandler;
this.secretProvider = secretProvider;
}
handleCommand(command) {
return __awaiter(this, void 0, void 0, function* () {
this.validateRequiredArguments(command);
if (typeof this.secretProvider.logIdentity === 'function') {
yield this.secretProvider.logIdentity();
}
switch (command.mode) {
case OperationMode.PUSH_SINGLE:
yield this.handlePushSingle(command);
break;
case OperationMode.PUSH_ENV_TO_SECRETS:
yield this.handlePush(command);
break;
case OperationMode.PULL_SECRETS_TO_ENV:
yield this.handlePull(command);
break;
default:
throw new InvalidArgumentError(`Unsupported operation mode: ${command.mode}`);
}
});
}
validateRequiredArguments(command) {
if (command.mode === OperationMode.PUSH_SINGLE) {
this.validatePushSingleOptions(command);
return;
}
this.validateMapAndEnvFileOptions(command);
}
handlePushSingle(command) {
return __awaiter(this, void 0, void 0, function* () {
this.validatePushSingleOptions(command);
const pushSingleCommand = PushSingleCommand.create(command.key, command.value, command.secretPath);
yield this.pushSingleHandler.handle(pushSingleCommand);
});
}
handlePush(command) {
return __awaiter(this, void 0, void 0, function* () {
this.validateMapAndEnvFileOptions(command);
const pushEnvToSecretsCommand = PushEnvToSecretsCommand.create(command.map, command.envfile);
yield this.pushHandler.handle(pushEnvToSecretsCommand);
});
}
handlePull(command) {
return __awaiter(this, void 0, void 0, function* () {
this.validateMapAndEnvFileOptions(command);
const pullSecretsToEnvCommand = PullSecretsToEnvCommand.create(command.map, command.envfile);
yield this.pullHandler.handle(pullSecretsToEnvCommand);
});
}
validatePushSingleOptions(command) {
if (!command.key || !command.value || !command.secretPath) {
throw new InvalidArgumentError('Missing required arguments: --key, --value, and --secret-path');
}
}
validateMapAndEnvFileOptions(command) {
if (!command.map || !command.envfile) {
throw new InvalidArgumentError('Missing required arguments: --map and --envfile');
}
}
};
DispatchActionCommandHandler = __decorate([
injectable(),
__param(0, inject(TYPES.PullSecretsToEnvCommandHandler)),
__param(1, inject(TYPES.PushEnvToSecretsCommandHandler)),
__param(2, inject(TYPES.PushSingleCommandHandler)),
__param(3, inject(TYPES.ISecretProvider)),
__metadata("design:paramtypes", [Function, Function, Function, Object])
], DispatchActionCommandHandler);
export { DispatchActionCommandHandler };
//# sourceMappingURL=DispatchActionCommandHandler.js.map