diff --git a/.changeset/bright-ears-send.md b/.changeset/bright-ears-send.md new file mode 100644 index 0000000000..5104f2377b --- /dev/null +++ b/.changeset/bright-ears-send.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': minor +--- + +Enable YAML merge keys in yamlPlaceholderResolver diff --git a/.changeset/easy-hands-grow.md b/.changeset/easy-hands-grow.md new file mode 100644 index 0000000000..fc3cfd96e1 --- /dev/null +++ b/.changeset/easy-hands-grow.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog-backend': minor +'@backstage/plugin-catalog-node': minor +--- + +Make YAML merge (<<:) support configurable in the Backstage Catalog instead of always being enabled diff --git a/.changeset/twelve-spoons-feel.md b/.changeset/twelve-spoons-feel.md new file mode 100644 index 0000000000..21298b4e09 --- /dev/null +++ b/.changeset/twelve-spoons-feel.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog-backend': minor +'@backstage/plugin-catalog-node': minor +--- + +Enable YAML merge keys in yamlPlaceholderResolver diff --git a/plugins/catalog-backend/src/processors/PlaceholderProcessor.ts b/plugins/catalog-backend/src/processors/PlaceholderProcessor.ts index db045f648c..b33a2693f2 100644 --- a/plugins/catalog-backend/src/processors/PlaceholderProcessor.ts +++ b/plugins/catalog-backend/src/processors/PlaceholderProcessor.ts @@ -142,9 +142,13 @@ export async function yamlPlaceholderResolver( params.emit(processingResult.refresh(`url:${url}`)); + // YAML merge support enabled by default + const enableYamlMerge = false; + const parseOptions = { merge: enableYamlMerge }; + let documents: yaml.Document.Parsed[]; try { - documents = yaml.parseAllDocuments(content).filter(d => d); + documents = yaml.parseAllDocuments(content, parseOptions).filter(d => d); } catch (e) { throw new Error( `Placeholder \$${params.key} failed to parse YAML data at ${params.value}, ${e}`, diff --git a/plugins/catalog-node/report.api.md b/plugins/catalog-node/report.api.md index 9a9f91865c..d544bc6757 100644 --- a/plugins/catalog-node/report.api.md +++ b/plugins/catalog-node/report.api.md @@ -313,8 +313,15 @@ export function locationSpecToMetadataName(location: LocationSpec_2): string; export function parseEntityYaml( data: string | Buffer, location: LocationSpec_2, + options?: ParseEntityYamlOptions, ): Iterable; +// @public +export interface ParseEntityYamlOptions { + // (undocumented) + enableYamlMerge?: boolean; +} + // @public (undocumented) export type PlaceholderResolver = ( params: PlaceholderResolverParams, diff --git a/plugins/catalog-node/src/processing/index.ts b/plugins/catalog-node/src/processing/index.ts index 1610e0cb89..00c2551a60 100644 --- a/plugins/catalog-node/src/processing/index.ts +++ b/plugins/catalog-node/src/processing/index.ts @@ -24,4 +24,4 @@ export type { LocationAnalyzer, ScmLocationAnalyzer, } from './types'; -export { parseEntityYaml } from './parse'; +export { parseEntityYaml, type ParseEntityYamlOptions } from './parse'; diff --git a/plugins/catalog-node/src/processing/parse.ts b/plugins/catalog-node/src/processing/parse.ts index 2ef276d06d..5612ef991a 100644 --- a/plugins/catalog-node/src/processing/parse.ts +++ b/plugins/catalog-node/src/processing/parse.ts @@ -21,6 +21,15 @@ import { LocationSpec } from '@backstage/plugin-catalog-common'; import { CatalogProcessorResult } from '../api/processor'; import { processingResult } from '../api/processingResult'; +/** + * Options for parsing entity YAML files. + * + * @public + */ +export interface ParseEntityYamlOptions { + enableYamlMerge?: boolean; +} + /** * A helper function that parses a YAML file, properly handling multiple * documents in a single file. @@ -40,12 +49,16 @@ import { processingResult } from '../api/processingResult'; export function* parseEntityYaml( data: string | Buffer, location: LocationSpec, + options?: ParseEntityYamlOptions, ): Iterable { + const parseOptions = { merge: options?.enableYamlMerge ?? false }; + let documents: yaml.Document.Parsed[]; try { documents = yaml .parseAllDocuments( typeof data === 'string' ? data : data.toString('utf8'), + parseOptions, ) .filter(d => d); } catch (e) {