< Summary - Envilder CLI

Information
Class: src/envilder/apps/cli/Startup.ts
Assembly: Default
File(s): src/envilder/apps/cli/Startup.ts
Tag: 561_41292037308
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 111
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/apps/cli/Startup.ts

#LineLine coverage
 1import { Container } from 'inversify';
 2import { ExecWithSecretsCommandHandler } from '../../core/application/execWithSecrets/ExecWithSecretsCommandHandler.js';
 3import { ValidateMapFileCommandHandler } from '../../core/application/validateMapFile/ValidateMapFileCommandHandler.js';
 4import { ValidateRemoteKeysCommandHandler } from '../../core/application/validateRemoteKeys/ValidateRemoteKeysCommandHan
 5import type { MapFileConfig } from '../../core/domain/MapFileConfig.js';
 6import type { ILogger } from '../../core/domain/ports/ILogger.js';
 7import type { IProcessContext } from '../../core/domain/ports/IProcessContext.js';
 8import type { IProcessRunner } from '../../core/domain/ports/IProcessRunner.js';
 9import type { ISecretMasker } from '../../core/domain/ports/ISecretMasker.js';
 10import type { IVariableStore } from '../../core/domain/ports/IVariableStore.js';
 11import { ConsoleLogger } from '../../core/infrastructure/logger/ConsoleLogger.js';
 12import { CrossSpawnProcessRunner } from '../../core/infrastructure/process/CrossSpawnProcessRunner.js';
 13import { NodeProcessContext } from '../../core/infrastructure/process/NodeProcessContext.js';
 14import { FileVariableStore } from '../../core/infrastructure/variableStore/FileVariableStore.js';
 15import { TYPES } from '../../core/types.js';
 16import {
 17  configureApplicationServices,
 18  configureInfrastructureServices,
 19} from '../shared/ContainerConfiguration.js';
 20
 21export class Startup {
 22  private readonly container: Container;
 23
 24  constructor() {
 12025    this.container = new Container();
 26  }
 27
 28  static build(): Startup {
 12029    return new Startup();
 30  }
 31
 32  configureServices(): this {
 7933    configureApplicationServices(this.container);
 7934    return this;
 35  }
 36
 37  /**
 38   * Wires the services specific to `envilder exec`: its handler, the process
 39   * runner, and the given logger and secret masker. The logger must keep
 40   * stdout free for the child. Call it before `configureInfrastructure`,
 41   * which only binds the defaults left unbound.
 42   */
 43  configureExec(secretMasker: ISecretMasker, logger: ILogger): this {
 3844    this.container.bind<ILogger>(TYPES.ILogger).toConstantValue(logger);
 3845    this.container
 46      .bind<ISecretMasker>(TYPES.ISecretMasker)
 47      .toConstantValue(secretMasker);
 3848    this.container
 49      .bind<IProcessRunner>(TYPES.IProcessRunner)
 50      .to(CrossSpawnProcessRunner)
 51      .inSingletonScope();
 3852    this.container
 53      .bind<IProcessContext>(TYPES.IProcessContext)
 54      .to(NodeProcessContext)
 55      .inSingletonScope();
 3856    this.container
 57      .bind<ExecWithSecretsCommandHandler>(TYPES.ExecWithSecretsCommandHandler)
 58      .to(ExecWithSecretsCommandHandler)
 59      .inTransientScope();
 3860    return this;
 61  }
 62
 63  /**
 64   * Wires `envilder validate --offline`: the map file is read and checked
 65   * locally, so no secret provider is bound. Use it instead of
 66   * `configureServices` and `configureInfrastructure`.
 67   */
 68  configureOfflineValidation(): this {
 2469    this.container
 70      .bind<ILogger>(TYPES.ILogger)
 71      .to(ConsoleLogger)
 72      .inSingletonScope();
 2473    this.container
 74      .bind<IVariableStore>(TYPES.IVariableStore)
 75      .to(FileVariableStore)
 76      .inSingletonScope();
 2477    this.container
 78      .bind<ValidateMapFileCommandHandler>(TYPES.ValidateMapFileCommandHandler)
 79      .to(ValidateMapFileCommandHandler)
 80      .inTransientScope();
 2481    return this;
 82  }
 83
 84  /**
 85   * Wires the remote part of `envilder validate`, which checks that each
 86   * declared secret exists. Call `configureInfrastructure` afterwards to bind
 87   * the secret provider, the logger and the variable store.
 88   */
 89  configureRemoteValidation(): this {
 1390    this.container
 91      .bind<ValidateRemoteKeysCommandHandler>(
 92        TYPES.ValidateRemoteKeysCommandHandler,
 93      )
 94      .to(ValidateRemoteKeysCommandHandler)
 95      .inTransientScope();
 1396    return this;
 97  }
 98
 99  configureInfrastructure(config?: MapFileConfig): this {
 91100    configureInfrastructureServices(this.container, config);
 91101    return this;
 102  }
 103
 104  create(): Container {
 113105    return this.container;
 106  }
 107
 108  getServiceProvider(): Container {
 2109    return this.container;
 110  }
 111}