UNPKG

envilder

Version:

A CLI that securely centralizes your environment variables from AWS SSM as a single source of truth

75 lines 3.02 kB
import { SSM } from '@aws-sdk/client-ssm'; import { fromIni } from '@aws-sdk/credential-providers'; import { Container } from 'inversify'; import { DispatchActionCommandHandler } from '../../envilder/application/dispatch/DispatchActionCommandHandler.js'; import { PullSsmToEnvCommandHandler } from '../../envilder/application/pullSsmToEnv/PullSsmToEnvCommandHandler.js'; import { PushEnvToSsmCommandHandler } from '../../envilder/application/pushEnvToSsm/PushEnvToSsmCommandHandler.js'; import { PushSingleCommandHandler } from '../../envilder/application/pushSingle/PushSingleCommandHandler.js'; import { AwsSsmSecretProvider } from '../../envilder/infrastructure/aws/AwsSsmSecretProvider.js'; import { ConsoleLogger } from '../../envilder/infrastructure/logger/ConsoleLogger.js'; import { FileVariableStore } from '../../envilder/infrastructure/variableStore/FileVariableStore.js'; import { TYPES } from '../../envilder/types.js'; export class Startup { constructor() { this.container = new Container(); } static build() { return new Startup(); } configureServices() { this.configureApplicationServices(); return this; } /** * Configures infrastructure services for the application. * Optionally accepts an AWS profile to use for service configuration. * @param awsProfile - The AWS profile to use for configuring infrastructure services. * @returns The current instance for method chaining. */ configureInfrastructure(awsProfile) { this.configureInfrastructureServices(awsProfile); return this; } create() { return this.container; } getServiceProvider() { return this.container; } configureInfrastructureServices(awsProfile) { this.container .bind(TYPES.ILogger) .to(ConsoleLogger) .inSingletonScope(); this.container .bind(TYPES.IVariableStore) .to(FileVariableStore) .inSingletonScope(); const ssm = awsProfile ? new SSM({ credentials: fromIni({ profile: awsProfile }) }) : new SSM(); const secretProvider = new AwsSsmSecretProvider(ssm); this.container .bind(TYPES.ISecretProvider) .toConstantValue(secretProvider); } configureApplicationServices() { this.container .bind(TYPES.PullSsmToEnvCommandHandler) .to(PullSsmToEnvCommandHandler) .inTransientScope(); this.container .bind(TYPES.PushEnvToSsmCommandHandler) .to(PushEnvToSsmCommandHandler) .inTransientScope(); this.container .bind(TYPES.PushSingleCommandHandler) .to(PushSingleCommandHandler) .inTransientScope(); this.container .bind(TYPES.DispatchActionCommandHandler) .to(DispatchActionCommandHandler) .inTransientScope(); } } //# sourceMappingURL=Startup.js.map