| | | 1 | | import { inject, injectable } from 'inversify'; |
| | | 2 | | import { EnvironmentVariable } from '../../domain/EnvironmentVariable.js'; |
| | | 3 | | import type { ILogger } from '../../domain/ports/ILogger.js'; |
| | | 4 | | import type { ISecretProvider } from '../../domain/ports/ISecretProvider.js'; |
| | | 5 | | import { TYPES } from '../../types.js'; |
| | | 6 | | import type { PushSingleCommand } from './PushSingleCommand.js'; |
| | | 7 | | |
| | | 8 | | @injectable() |
| | 8 | 9 | | export class PushSingleCommandHandler { |
| | | 10 | | constructor( |
| | | 11 | | @inject(TYPES.ISecretProvider) |
| | 21 | 12 | | private readonly secretProvider: ISecretProvider, |
| | 21 | 13 | | @inject(TYPES.ILogger) private readonly logger: ILogger, |
| | | 14 | | ) {} |
| | | 15 | | |
| | | 16 | | /** |
| | | 17 | | * Handles the PushSingleCommand which pushes a single environment variable to the secret store. |
| | | 18 | | * |
| | | 19 | | * @param command - The PushSingleCommand containing key, value and secretPath |
| | | 20 | | */ |
| | | 21 | | async handle(command: PushSingleCommand): Promise<void> { |
| | 3 | 22 | | try { |
| | 3 | 23 | | this.logger.info( |
| | | 24 | | `Starting push operation for key '${command.key}' to path '${EnvironmentVariable.maskSecretPath(command.secretPa |
| | | 25 | | ); |
| | | 26 | | |
| | 3 | 27 | | const envVariable = new EnvironmentVariable( |
| | | 28 | | command.key, |
| | | 29 | | command.value, |
| | | 30 | | true, |
| | | 31 | | ); |
| | | 32 | | |
| | 3 | 33 | | await this.secretProvider.setSecret(command.secretPath, command.value); |
| | 2 | 34 | | this.logger.info( |
| | | 35 | | `Pushed ${command.key}=${envVariable.maskedValue} to secret store at path ${EnvironmentVariable.maskSecretPath(c |
| | | 36 | | ); |
| | | 37 | | } catch (error) { |
| | | 38 | | const errorMessage = |
| | 1 | 39 | | error instanceof Error ? error.message : String(error); |
| | 1 | 40 | | this.logger.error( |
| | | 41 | | `Failed to push variable to secret store: ${errorMessage}`, |
| | | 42 | | ); |
| | 1 | 43 | | throw error; |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |