UNPKG

@fntio/infra-client

Version:

Self-hosted AWS access portal: credential vending, target-account trust, and grant-driven private networking as CDK stacks and constructs.

52 lines (51 loc) • 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_STAGE_KINDS = exports.DEFAULT_DIMENSION_LABELS = void 0; exports.resolveAccountDimensions = resolveAccountDimensions; exports.DEFAULT_DIMENSION_LABELS = { tenant: "Tenant", project: "Project", stage: "Stage" }; /** What a stage value means when the block lists none: the dashboard's old name heuristic, made explicit. */ exports.DEFAULT_STAGE_KINDS = { prod: "prod", prd: "prod", production: "prod", live: "prod", staging: "staging", stage: "staging", stg: "staging", preprod: "staging", test: "staging", qa: "staging", uat: "staging", dev: "dev", develop: "dev", development: "dev", eng: "dev", sandbox: "sandbox", sbx: "sandbox", }; const STAGE_KINDS = ["prod", "staging", "dev", "sandbox"]; function resolveAccountDimensions(cfg) { if (!cfg) return undefined; const labels = { ...exports.DEFAULT_DIMENSION_LABELS }; for (const key of ["tenant", "project", "stage"]) { const v = cfg.labels?.[key]; if (v === undefined) continue; if (typeof v !== "string" || !v.trim() || v.trim().length > 30) { throw new Error(`accountDimensions.labels.${key} must be 1 to 30 characters (got ${JSON.stringify(v)}).`); } labels[key] = v.trim(); } const stages = { ...exports.DEFAULT_STAGE_KINDS }; for (const [value, kind] of Object.entries(cfg.stages ?? {})) { if (!/^[a-z0-9]+$/.test(value)) { throw new Error(`accountDimensions.stages key "${value}" must be lower-case letters and digits (a stage as it appears in account names).`); } if (!STAGE_KINDS.includes(kind)) { throw new Error(`accountDimensions.stages.${value} must be one of ${STAGE_KINDS.join(", ")} (got ${JSON.stringify(kind)}).`); } stages[value] = kind; } return { enabled: cfg.enabled === true, labels, stages }; }