< Summary - Envilder CLI

Information
Class: src/envilder/core/application/validateRemoteKeys/ValidateRemoteKeysCommandHandler.ts
Assembly: Default
File(s): src/envilder/core/application/validateRemoteKeys/ValidateRemoteKeysCommandHandler.ts
Tag: 561_41292037308
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 42
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/core/application/validateRemoteKeys/ValidateRemoteKeysCommandHandler.ts

#LineLine coverage
 1import { inject, injectable } from 'inversify';
 2import type { ISecretProvider } from '../../domain/ports/ISecretProvider.js';
 3import type { IVariableStore } from '../../domain/ports/IVariableStore.js';
 4import type { RemoteKeyCheck } from '../../domain/SecretExistence.js';
 5import { TYPES } from '../../types.js';
 6import type { ValidateRemoteKeysCommand } from './ValidateRemoteKeysCommand.js';
 7
 8/**
 9 * Checks that every secret path declared in a map file exists in the
 10 * provider, without reading any value. A path shared by several variables is
 11 * checked once. Returns one check per variable, in map-file order. Run it on a
 12 * map file that passed offline validation.
 13 */
 14@injectable()
 815export class ValidateRemoteKeysCommandHandler {
 16  constructor(
 17    @inject(TYPES.ISecretProvider)
 2118    private readonly secretProvider: ISecretProvider,
 19    @inject(TYPES.IVariableStore)
 2120    private readonly variableStore: IVariableStore,
 21  ) {}
 22
 23  async handle(command: ValidateRemoteKeysCommand): Promise<RemoteKeyCheck[]> {
 2124    const mappings = Object.entries(
 25      await this.variableStore.getMapping(command.mapPath),
 26    );
 2127    if (typeof this.secretProvider.logIdentity === 'function') {
 428      await this.secretProvider.logIdentity();
 29    }
 2130    const existence = await this.secretProvider.checkSecretsExist([
 3631      ...new Set(mappings.map(([, path]) => path)),
 32    ]);
 3333    return mappings.map(([variable, path]) => ({
 34      variable,
 35      path,
 36      ...(existence.get(path) ?? {
 37        status: 'provider_error',
 38        reason: 'The provider returned no result for this secret.',
 39      }),
 40    }));
 41  }
 42}