-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog-env-substitute.ts
More file actions
42 lines (37 loc) · 1.79 KB
/
Copy pathcatalog-env-substitute.ts
File metadata and controls
42 lines (37 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Expand `${MARVEL_*}` placeholders in catalog YAML before parsing.
*
* Only placeholders matching /^[A-Z][A-Z0-9_]*$/ inside `${…}` are expanded so
* scaffolder templates keep `${{ … }}` Nunjucks syntax untouched.
*
* Backstage itself does not substitute these when reading static YAML; use the
* same expansion in CI (this validator), an initContainer with envsubst, Helm,
* or another render step before the catalog loads the files.
*/
/** Defaults used when a variable is unset — keeps `yarn validate:catalog` green without a `.env`. */
export const MARVEL_CATALOG_ENV_DEFAULTS: Record<string, string> = {
MARVEL_STATIC_CATALOG_USER_NAME: 'catalog-local-user',
MARVEL_STATIC_USER_DISPLAY_NAME: 'Catalog local user',
MARVEL_STATIC_USER_EMAIL: 'catalog-local-user@example.com',
MARVEL_STATIC_USER_GROUP_PRIMARY: 'cluster-admins',
MARVEL_RHDH_GITHUB_PROJECT_SLUG: 'janus-idp/backstage-showcase',
MARVEL_RHDH_QUAY_REPOSITORY_SLUG: 'janus-idp/backstage-showcase',
MARVEL_RHDH_SONAR_PROJECT_KEY: 'janus-idp_backstage-showcase',
MARVEL_RHDH_TECHDOCS_REF: 'url:https://github.com/janus-idp/backstage-showcase',
MARVEL_RHDH_ARGOCD_APP_NAME: 'rhdh',
MARVEL_RHDH_KUBERNETES_ID: 'rhdh',
MARVEL_RHDH_KUBERNETES_NAMESPACE: 'rhdh',
MARVEL_BACKSTAGE_DOCS_URL: 'https://backstage.io/docs',
MARVEL_TOPOLOGY_KUBERNETES_ID: 'sample-topology-workload',
MARVEL_TEKTON_ENTITY_SELECTOR: 'backstage-demo',
};
const placeholderRe = /\$\{([A-Z][A-Z0-9_]*)\}/g;
export function applyCatalogEnvSubstitutions(raw: string): string {
return raw.replace(placeholderRe, (full, key: string) => {
const fromEnv = process.env[key];
if (fromEnv !== undefined && fromEnv !== '') return fromEnv;
const d = MARVEL_CATALOG_ENV_DEFAULTS[key];
if (d !== undefined) return d;
return full;
});
}