< Summary - Envilder CLI

Information
Class: src/envilder/apps/shared/ContainerConfiguration.ts
Assembly: Default
File(s): src/envilder/apps/shared/ContainerConfiguration.ts
Tag: 561_41292037308
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 105
Line coverage: 100%
Branch coverage
100%
Covered branches: 15
Total branches: 15
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 {
 10  DEFAULT_PROVIDER,
 11  unsupportedProviderMessage,
 12} from '../../core/domain/ProviderConfiguration.js';
 13import type { ILogger } from '../../core/domain/ports/ILogger.js';
 14import type { ISecretMasker } from '../../core/domain/ports/ISecretMasker.js';
 15import type { ISecretProvider } from '../../core/domain/ports/ISecretProvider.js';
 16import type { IVariableStore } from '../../core/domain/ports/IVariableStore.js';
 17import { createAwsSecretProvider } from '../../core/infrastructure/aws/AwsSecretProviderFactory.js';
 18import { createAzureSecretProvider } from '../../core/infrastructure/azure/AzureSecretProviderFactory.js';
 19import { NoOpSecretMasker } from '../../core/infrastructure/github/NoOpSecretMasker.js';
 20import { ConsoleLogger } from '../../core/infrastructure/logger/ConsoleLogger.js';
 21import { FileVariableStore } from '../../core/infrastructure/variableStore/FileVariableStore.js';
 22import { TYPES } from '../../core/types.js';
 23
 24type ProviderFactory = (
 25  config: MapFileConfig,
 26  logger: ILogger,
 27) => ISecretProvider;
 28
 1129const providerFactories: Record<string, ProviderFactory> = {
 8430  aws: (config, logger) => createAwsSecretProvider(config, logger),
 2431  azure: (config) => createAzureSecretProvider(config),
 32};
 33
 34/** The providers the CLI and the GitHub Action can resolve secrets from. */
 35export const SUPPORTED_PROVIDERS: readonly string[] =
 1136  Object.keys(providerFactories);
 37
 38export function configureInfrastructureServices(
 39  container: Container,
 40  config: MapFileConfig = {},
 41): void {
 11142  if (!container.isBound(TYPES.ILogger)) {
 5343    container.bind<ILogger>(TYPES.ILogger).to(ConsoleLogger).inSingletonScope();
 44  }
 45
 11146  const logger = container.get<ILogger>(TYPES.ILogger);
 47
 11148  if (!container.isBound(TYPES.IVariableStore)) {
 11049    container
 50      .bind<IVariableStore>(TYPES.IVariableStore)
 51      .to(FileVariableStore)
 52      .inSingletonScope();
 53  }
 54
 11155  if (!container.isBound(TYPES.ISecretMasker)) {
 5756    container
 57      .bind<ISecretMasker>(TYPES.ISecretMasker)
 58      .to(NoOpSecretMasker)
 59      .inSingletonScope();
 60  }
 61
 11162  const selectedProvider = config.provider?.toLowerCase() || DEFAULT_PROVIDER;
 63
 11164  if (config.profile && selectedProvider !== 'aws') {
 165    logger.warn(
 66      `--profile is only supported with the aws provider` +
 67        ` and will be ignored` +
 68        ` (current provider: ${selectedProvider}).`,
 69    );
 70  }
 71
 11172  const factory = providerFactories[selectedProvider];
 11173  if (!factory) {
 374    throw new InvalidArgumentError(
 75      unsupportedProviderMessage(`${config.provider}`, SUPPORTED_PROVIDERS),
 76    );
 77  }
 10878  const secretProvider = factory(config, logger);
 79
 10880  container
 81    .bind<ISecretProvider>(TYPES.ISecretProvider)
 82    .toConstantValue(secretProvider);
 83}
 84
 85export function configureApplicationServices(container: Container): void {
 9486  container
 87    .bind<PullSecretsToEnvCommandHandler>(TYPES.PullSecretsToEnvCommandHandler)
 88    .to(PullSecretsToEnvCommandHandler)
 89    .inTransientScope();
 90
 9491  container
 92    .bind<PushEnvToSecretsCommandHandler>(TYPES.PushEnvToSecretsCommandHandler)
 93    .to(PushEnvToSecretsCommandHandler)
 94    .inTransientScope();
 95
 9496  container
 97    .bind<PushSingleCommandHandler>(TYPES.PushSingleCommandHandler)
 98    .to(PushSingleCommandHandler)
 99    .inTransientScope();
 100
 94101  container
 102    .bind<DispatchActionCommandHandler>(TYPES.DispatchActionCommandHandler)
 103    .to(DispatchActionCommandHandler)
 104    .inTransientScope();
 105}