< Summary - Envilder CLI

Information
Class: src/envilder/apps/shared/ContainerConfiguration.ts
Assembly: Default
File(s): src/envilder/apps/shared/ContainerConfiguration.ts
Tag: 427_29134414720
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 97
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/apps/shared/ContainerConfiguration.ts

#LineLine coverage
 1import type { Container } from 'inversify';
 2
 3import { DispatchActionCommandHandler } from '../../core/application/dispatch/DispatchActionCommandHandler.js';
 4import { PullSecretsToEnvCommandHandler } from '../../core/application/pullSecretsToEnv/PullSecretsToEnvCommandHandler.j
 5import { PushEnvToSecretsCommandHandler } from '../../core/application/pushEnvToSecrets/PushEnvToSecretsCommandHandler.j
 6import { PushSingleCommandHandler } from '../../core/application/pushSingle/PushSingleCommandHandler.js';
 7import { InvalidArgumentError } from '../../core/domain/errors/DomainErrors.js';
 8import type { MapFileConfig } from '../../core/domain/MapFileConfig.js';
 9import type { ILogger } from '../../core/domain/ports/ILogger.js';
 10import type { ISecretProvider } from '../../core/domain/ports/ISecretProvider.js';
 11import type { IVariableStore } from '../../core/domain/ports/IVariableStore.js';
 12import { createAwsSecretProvider } from '../../core/infrastructure/aws/AwsSecretProviderFactory.js';
 13import {
 14  type AzureProviderOptions,
 15  createAzureSecretProvider,
 16} from '../../core/infrastructure/azure/AzureSecretProviderFactory.js';
 17import { ConsoleLogger } from '../../core/infrastructure/logger/ConsoleLogger.js';
 18import { FileVariableStore } from '../../core/infrastructure/variableStore/FileVariableStore.js';
 19import { TYPES } from '../../core/types.js';
 20
 21export type InfrastructureOptions = AzureProviderOptions;
 22
 23type ProviderFactory = (
 24  config: MapFileConfig,
 25  options: InfrastructureOptions,
 26  logger: ILogger,
 27) => ISecretProvider;
 28
 729const providerFactories: Record<string, ProviderFactory> = {
 2430  aws: (config, _options, logger) => createAwsSecretProvider(config, logger),
 1731  azure: (config, options) => createAzureSecretProvider(config, options),
 32};
 33
 34export function configureInfrastructureServices(
 35  container: Container,
 36  config: MapFileConfig = {},
 37  options: InfrastructureOptions = {},
 38): void {
 4439  if (!container.isBound(TYPES.ILogger)) {
 3940    container.bind<ILogger>(TYPES.ILogger).to(ConsoleLogger).inSingletonScope();
 41  }
 42
 4443  const logger = container.get<ILogger>(TYPES.ILogger);
 44
 4445  if (!container.isBound(TYPES.IVariableStore)) {
 4346    container
 47      .bind<IVariableStore>(TYPES.IVariableStore)
 48      .to(FileVariableStore)
 49      .inSingletonScope();
 50  }
 51
 4452  const selectedProvider = config.provider?.toLowerCase() || 'aws';
 53
 4454  if (config.profile && selectedProvider !== 'aws') {
 155    logger.warn(
 56      `--profile is only supported with the aws provider` +
 57        ` and will be ignored` +
 58        ` (current provider: ${selectedProvider}).`,
 59    );
 60  }
 61
 4462  const factory = providerFactories[selectedProvider];
 4463  if (!factory) {
 364    throw new InvalidArgumentError(
 65      `Unsupported provider: ${config.provider}.` +
 66        ` Supported providers:` +
 67        ` ${Object.keys(providerFactories).join(', ')}`,
 68    );
 69  }
 4170  const secretProvider = factory(config, options, logger);
 71
 4172  container
 73    .bind<ISecretProvider>(TYPES.ISecretProvider)
 74    .toConstantValue(secretProvider);
 75}
 76
 77export function configureApplicationServices(container: Container): void {
 4078  container
 79    .bind<PullSecretsToEnvCommandHandler>(TYPES.PullSecretsToEnvCommandHandler)
 80    .to(PullSecretsToEnvCommandHandler)
 81    .inTransientScope();
 82
 4083  container
 84    .bind<PushEnvToSecretsCommandHandler>(TYPES.PushEnvToSecretsCommandHandler)
 85    .to(PushEnvToSecretsCommandHandler)
 86    .inTransientScope();
 87
 4088  container
 89    .bind<PushSingleCommandHandler>(TYPES.PushSingleCommandHandler)
 90    .to(PushSingleCommandHandler)
 91    .inTransientScope();
 92
 4093  container
 94    .bind<DispatchActionCommandHandler>(TYPES.DispatchActionCommandHandler)
 95    .to(DispatchActionCommandHandler)
 96    .inTransientScope();
 97}