< Summary - Envilder CLI

Information
Class: src/envilder/core/domain/ProviderConfiguration.ts
Assembly: Default
File(s): src/envilder/core/domain/ProviderConfiguration.ts
Tag: 561_41292037308
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 87
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/core/domain/ProviderConfiguration.ts

#LineLine coverage
 1/**
 2 * Which `$config` fields each provider accepts, and the messages that report a
 3 * provider configuration that cannot work. Shared by the provider wiring (pull,
 4 * push, exec) and the map file validator, so a check and a run describe the
 5 * same problem with the same words.
 6 */
 7
 8/** Every provider the map file schema (`spec/map-file.v1.json`) declares. */
 149export const MAP_FILE_PROVIDERS: readonly string[] = [
 10  'aws',
 11  'azure',
 12  'gcp',
 13  'hashicorp',
 14  'file',
 15];
 16
 1417export const DEFAULT_PROVIDER = 'aws';
 18
 19/** Provider-specific `$config` fields and the providers that accept each. */
 20export const PROVIDER_SPECIFIC_FIELDS: Readonly<
 21  Record<string, readonly string[]>
 1422> = {
 23  profile: ['aws'],
 24  vaultUrl: ['azure', 'hashicorp'],
 25  projectId: ['gcp'],
 26  namespace: ['hashicorp'],
 27  path: ['file'],
 28};
 29
 30/** The `$config` field each provider cannot work without. */
 1431export const REQUIRED_PROVIDER_FIELDS: Readonly<Record<string, string>> = {
 32  azure: 'vaultUrl',
 33  gcp: 'projectId',
 34  hashicorp: 'vaultUrl',
 35  file: 'path',
 36};
 37
 1438const PROVIDER_LABELS: Readonly<Record<string, string>> = {
 39  aws: 'AWS',
 40  azure: 'Azure',
 41  gcp: 'GCP',
 42  hashicorp: 'HashiCorp',
 43  file: 'file',
 44};
 45
 1446const FIELD_FLAGS: Readonly<Record<string, string>> = {
 47  profile: '--profile',
 48  vaultUrl: '--vault-url',
 49};
 50
 51export function unsupportedProviderMessage(
 52  provider: string,
 53  supportedProviders: readonly string[],
 54): string {
 955  return (
 56    `Unsupported provider: ${provider}.` +
 57    ` Supported providers:` +
 58    ` ${supportedProviders.join(', ')}`
 59  );
 60}
 61
 62/**
 63 * Reports a provider-specific field set for a provider that does not use it.
 64 * `subject` names where the field came from, such as `--profile` or
 65 * `$config.profile`.
 66 */
 67export function fieldOutsideProviderMessage(
 68  subject: string,
 69  validProviders: readonly string[],
 70  provider: string,
 71): string {
 1772  return (
 73    `${subject} is only supported with the` +
 74    ` ${validProviders.join(' or ')} provider` +
 75    ` (current provider: ${provider}).`
 76  );
 77}
 78
 79export function requiredFieldMessage(field: string, provider: string): string {
 980  const flag = FIELD_FLAGS[field];
 981  return (
 82    `${field} is required when using` +
 83    ` ${PROVIDER_LABELS[provider] ?? provider} provider.` +
 84    ` Set it in $config.${field} in your map file` +
 85    (flag === undefined ? '.' : ` or via ${flag} flag.`)
 86  );
 87}