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
62 lines • 3.05 kB
JavaScript
import { DispatchActionCommandHandler } from '../../core/application/dispatch/DispatchActionCommandHandler.js';
import { PullSecretsToEnvCommandHandler } from '../../core/application/pullSecretsToEnv/PullSecretsToEnvCommandHandler.js';
import { PushEnvToSecretsCommandHandler } from '../../core/application/pushEnvToSecrets/PushEnvToSecretsCommandHandler.js';
import { PushSingleCommandHandler } from '../../core/application/pushSingle/PushSingleCommandHandler.js';
import { InvalidArgumentError } from '../../core/domain/errors/DomainErrors.js';
import { createAwsSecretProvider } from '../../core/infrastructure/aws/AwsSecretProviderFactory.js';
import { createAzureSecretProvider, } from '../../core/infrastructure/azure/AzureSecretProviderFactory.js';
import { ConsoleLogger } from '../../core/infrastructure/logger/ConsoleLogger.js';
import { FileVariableStore } from '../../core/infrastructure/variableStore/FileVariableStore.js';
import { TYPES } from '../../core/types.js';
const providerFactories = {
aws: (config, _options, logger) => createAwsSecretProvider(config, logger),
azure: (config, options) => createAzureSecretProvider(config, options),
};
export function configureInfrastructureServices(container, config = {}, options = {}) {
var _a;
if (!container.isBound(TYPES.ILogger)) {
container.bind(TYPES.ILogger).to(ConsoleLogger).inSingletonScope();
}
const logger = container.get(TYPES.ILogger);
if (!container.isBound(TYPES.IVariableStore)) {
container
.bind(TYPES.IVariableStore)
.to(FileVariableStore)
.inSingletonScope();
}
const selectedProvider = ((_a = config.provider) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'aws';
if (config.profile && selectedProvider !== 'aws') {
logger.warn(`--profile is only supported with the aws provider` +
` and will be ignored` +
` (current provider: ${selectedProvider}).`);
}
const factory = providerFactories[selectedProvider];
if (!factory) {
throw new InvalidArgumentError(`Unsupported provider: ${config.provider}.` +
` Supported providers:` +
` ${Object.keys(providerFactories).join(', ')}`);
}
const secretProvider = factory(config, options, logger);
container
.bind(TYPES.ISecretProvider)
.toConstantValue(secretProvider);
}
export function configureApplicationServices(container) {
container
.bind(TYPES.PullSecretsToEnvCommandHandler)
.to(PullSecretsToEnvCommandHandler)
.inTransientScope();
container
.bind(TYPES.PushEnvToSecretsCommandHandler)
.to(PushEnvToSecretsCommandHandler)
.inTransientScope();
container
.bind(TYPES.PushSingleCommandHandler)
.to(PushSingleCommandHandler)
.inTransientScope();
container
.bind(TYPES.DispatchActionCommandHandler)
.to(DispatchActionCommandHandler)
.inTransientScope();
}
//# sourceMappingURL=ContainerConfiguration.js.map