< Summary - Envilder CLI

Information
Class: src/envilder/apps/shared/ContainerConfiguration.ts
Assembly: Default
File(s): src/envilder/apps/shared/ContainerConfiguration.ts
Tag: 484_34168995013
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 106
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
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 { ISecretMasker } from '../../core/domain/ports/ISecretMasker.js';
 11import type { ISecretProvider } from '../../core/domain/ports/ISecretProvider.js';
 12import type { IVariableStore } from '../../core/domain/ports/IVariableStore.js';
 13import { createAwsSecretProvider } from '../../core/infrastructure/aws/AwsSecretProviderFactory.js';
 14import {
 15  type AzureProviderOptions,
 16  createAzureSecretProvider,
 17} from '../../core/infrastructure/azure/AzureSecretProviderFactory.js';
 18import { NoOpSecretMasker } from '../../core/infrastructure/github/NoOpSecretMasker.js';
 19import { ConsoleLogger } from '../../core/infrastructure/logger/ConsoleLogger.js';
 20import { FileVariableStore } from '../../core/infrastructure/variableStore/FileVariableStore.js';
 21import { TYPES } from '../../core/types.js';
 22
 23export type InfrastructureOptions = AzureProviderOptions;
 24
 25type ProviderFactory = (
 26  config: MapFileConfig,
 27  options: InfrastructureOptions,
 28  logger: ILogger,
 29) => ISecretProvider;
 30
 731const providerFactories: Record<string, ProviderFactory> = {
 2432  aws: (config, _options, logger) => createAwsSecretProvider(config, logger),
 1733  azure: (config, options) => createAzureSecretProvider(config, options),
 34};
 35
 36export function configureInfrastructureServices(
 37  container: Container,
 38  config: MapFileConfig = {},
 39  options: InfrastructureOptions = {},
 40): void {
 4441  if (!container.isBound(TYPES.ILogger)) {
 3942    container.bind<ILogger>(TYPES.ILogger).to(ConsoleLogger).inSingletonScope();
 43  }
 44
 4445  const logger = container.get<ILogger>(TYPES.ILogger);
 46
 4447  if (!container.isBound(TYPES.IVariableStore)) {
 4348    container
 49      .bind<IVariableStore>(TYPES.IVariableStore)
 50      .to(FileVariableStore)
 51      .inSingletonScope();
 52  }
 53
 4454  if (!container.isBound(TYPES.ISecretMasker)) {
 2855    container
 56      .bind<ISecretMasker>(TYPES.ISecretMasker)
 57      .to(NoOpSecretMasker)
 58      .inSingletonScope();
 59  }
 60
 4461  const selectedProvider = config.provider?.toLowerCase() || 'aws';
 62
 4463  if (config.profile && selectedProvider !== 'aws') {
 164    logger.warn(
 65      `--profile is only supported with the aws provider` +
 66        ` and will be ignored` +
 67        ` (current provider: ${selectedProvider}).`,
 68    );
 69  }
 70
 4471  const factory = providerFactories[selectedProvider];
 4472  if (!factory) {
 373    throw new InvalidArgumentError(
 74      `Unsupported provider: ${config.provider}.` +
 75        ` Supported providers:` +
 76        ` ${Object.keys(providerFactories).join(', ')}`,
 77    );
 78  }
 4179  const secretProvider = factory(config, options, logger);
 80
 4181  container
 82    .bind<ISecretProvider>(TYPES.ISecretProvider)
 83    .toConstantValue(secretProvider);
 84}
 85
 86export function configureApplicationServices(container: Container): void {
 4087  container
 88    .bind<PullSecretsToEnvCommandHandler>(TYPES.PullSecretsToEnvCommandHandler)
 89    .to(PullSecretsToEnvCommandHandler)
 90    .inTransientScope();
 91
 4092  container
 93    .bind<PushEnvToSecretsCommandHandler>(TYPES.PushEnvToSecretsCommandHandler)
 94    .to(PushEnvToSecretsCommandHandler)
 95    .inTransientScope();
 96
 4097  container
 98    .bind<PushSingleCommandHandler>(TYPES.PushSingleCommandHandler)
 99    .to(PushSingleCommandHandler)
 100    .inTransientScope();
 101
 40102  container
 103    .bind<DispatchActionCommandHandler>(TYPES.DispatchActionCommandHandler)
 104    .to(DispatchActionCommandHandler)
 105    .inTransientScope();
 106}