< Summary - Envilder CLI

Information
Class: src/envilder/core/application/pushSingle/PushSingleCommandHandler.ts
Assembly: Default
File(s): src/envilder/core/application/pushSingle/PushSingleCommandHandler.ts
Tag: 427_29134414720
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 57
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/core/application/pushSingle/PushSingleCommandHandler.ts

#LineLine coverage
 1import { inject, injectable } from 'inversify';
 2import pc from 'picocolors';
 3import { EnvironmentVariable } from '../../domain/EnvironmentVariable.js';
 4import type { ILogger } from '../../domain/ports/ILogger.js';
 5import type { ISecretProvider } from '../../domain/ports/ISecretProvider.js';
 6import { TYPES } from '../../types.js';
 7import type { PushSingleCommand } from './PushSingleCommand.js';
 8
 9@injectable()
 810export class PushSingleCommandHandler {
 811  private static readonly RULE = pc.magenta('\u2501'.repeat(60));
 12
 13  constructor(
 14    @inject(TYPES.ISecretProvider)
 2515    private readonly secretProvider: ISecretProvider,
 2516    @inject(TYPES.ILogger) private readonly logger: ILogger,
 17  ) {}
 18
 19  /**
 20   * Handles the PushSingleCommand which pushes a single environment variable to the secret store.
 21   *
 22   * @param command - The PushSingleCommand containing key, value and secretPath
 23   */
 24  async handle(command: PushSingleCommand): Promise<void> {
 525    try {
 526      const maskedPath = EnvironmentVariable.maskSecretPath(command.secretPath);
 27
 528      this.logger.info(`\n${pc.bold(pc.magenta('\u{1F4E4} PUSHING SECRET'))}`);
 529      this.logger.info(PushSingleCommandHandler.RULE);
 530      this.logger.info(
 31        `  ${pc.dim('\u2192 ')}${pc.bold(command.key)}${pc.dim(' \u2192 ')}${pc.dim(maskedPath)}`,
 32      );
 33
 534      const envVariable = new EnvironmentVariable(
 35        command.key,
 36        command.value,
 37        true,
 38      );
 39
 540      await this.secretProvider.setSecret(command.secretPath, command.value);
 441      this.logger.info(
 42        `\n${pc.bold(pc.green('\u2B50 SECRET PUSHED'))}${pc.dim(
 43          '  \u2014  ',
 44        )}${pc.bold(command.key)}${pc.dim('=')}${envVariable.maskedValue}${pc.dim(
 45          ' \u2192 ',
 46        )}${pc.dim(maskedPath)}\n`,
 47      );
 48    } catch (error) {
 49      const errorMessage =
 150        error instanceof Error ? error.message : String(error);
 151      this.logger.error(
 52        `Failed to push variable to secret store: ${errorMessage}`,
 53      );
 154      throw error;
 55    }
 56  }
 57}

Methods/Properties

constructor
handle