< Summary - Envilder CLI

Information
Class: src/envilder/core/domain/SecretExistence.ts
Assembly: Default
File(s): src/envilder/core/domain/SecretExistence.ts
Tag: 561_41292037308
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 65
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/core/domain/SecretExistence.ts

#LineLine coverage
 1/**
 2 * Whether a secret declared in the map file can be resolved, as checked by
 3 * `envilder validate` without reading its value:
 4 *
 5 * - `exists`: the secret is there and the identity can see it.
 6 * - `missing`: the provider answered that there is no such secret.
 7 * - `access_denied`: the identity is not allowed to check the secret, so
 8 *   whether it exists is unknown. Never reported as `missing`.
 9 * - `authentication_failed`: the provider rejected the credentials.
 10 * - `provider_error`: anything else, for example an unreachable provider.
 11 */
 12export type SecretExistenceStatus =
 13  | 'exists'
 14  | 'missing'
 15  | 'access_denied'
 16  | 'authentication_failed'
 17  | 'provider_error';
 18
 19/**
 20 * The outcome of checking one secret path. `reason` explains a status other
 21 * than `exists` or `missing` when the provider gave one; it never carries a
 22 * secret value.
 23 */
 24export type SecretExistence = {
 25  readonly status: SecretExistenceStatus;
 26  readonly reason?: string;
 27};
 28
 29/** One variable of the map file with the outcome for the path it maps to. */
 30export type RemoteKeyCheck = SecretExistence & {
 31  readonly variable: string;
 32  readonly path: string;
 33};
 34
 35/** Every failing status, in the order a summary lists them. */
 636const FAILING_STATUSES: readonly SecretExistenceStatus[] = [
 37  'missing',
 38  'access_denied',
 39  'authentication_failed',
 40  'provider_error',
 41];
 42
 43/** How a status reads in text output: `access denied`, not `access_denied`. */
 44export function describeSecretExistenceStatus(
 45  status: SecretExistenceStatus,
 46): string {
 4047  return status.replace(/_/g, ' ');
 48}
 49
 50/**
 51 * Counts the failing checks by status, for example `2 missing, 1 access
 52 * denied`. Empty when every secret exists.
 53 */
 54export function summarizeFailures(checks: readonly RemoteKeyCheck[]): string {
 9655  return FAILING_STATUSES.map((status) => ({
 56    status,
 20057    count: checks.filter((check) => check.status === status).length,
 58  }))
 9659    .filter(({ count }) => count > 0)
 60    .map(
 61      ({ status, count }) =>
 1862        `${count} ${describeSecretExistenceStatus(status)}`,
 63    )
 64    .join(', ');
 65}