From c4b846359c09a6515e67ec8c766e1e559443043a Mon Sep 17 00:00:00 2001 From: Jacob Bolda Date: Tue, 21 Mar 2023 16:32:35 -0500 Subject: [PATCH 1/2] Allow Replacement Of BuiltinKindsEntityProcessor Signed-off-by: Jacob Bolda --- .changeset/silly-adults-accept.md | 5 +++++ .../software-catalog/extending-the-model.md | 1 + .../catalog-backend/src/service/CatalogBuilder.ts | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/silly-adults-accept.md diff --git a/.changeset/silly-adults-accept.md b/.changeset/silly-adults-accept.md new file mode 100644 index 0000000000..9db04d2490 --- /dev/null +++ b/.changeset/silly-adults-accept.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Allow replacement of the BuiltinKindsEntityProcessor which enables customization of schema validation and connections emitted. diff --git a/docs/features/software-catalog/extending-the-model.md b/docs/features/software-catalog/extending-the-model.md index bdd043b8a8..c254d7d0b6 100644 --- a/docs/features/software-catalog/extending-the-model.md +++ b/docs/features/software-catalog/extending-the-model.md @@ -170,6 +170,7 @@ its schema. There is a builtin processor that implements this for all known core kinds and matches the data against their fixed validation schema. This processor can be replaced when building the backend catalog using the `CatalogBuilder`, with a processor of your own that validates the data differently. +This replacement processor must have a name that matches the builtin processor, `BuiltinKindsEntityProcessor`. This type of extension is high risk, and may have high impact across the ecosystem depending on the type of change that is made. It is therefore not diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index 7da5d69767..8d40745e9d 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -599,16 +599,26 @@ export class CatalogBuilder { ...this.placeholderResolvers, }; - // These are always there no matter what + // The placeholder is always there no matter what const processors: CatalogProcessor[] = [ new PlaceholderProcessor({ resolvers: placeholderResolvers, reader, integrations, }), - new BuiltinKindsEntityProcessor(), ]; + // If the user adds a processor named 'BuiltinKindsEntityProcessor', + // skip inclusion of the catalog-backend version. + if ( + !this.processors.find( + processor => + processor.getProcessorName() === 'BuiltinKindsEntityProcessor', + ) + ) { + processors.push(new BuiltinKindsEntityProcessor()); + } + // These are only added unless the user replaced them all if (!this.processorsReplace) { processors.push(...this.getDefaultProcessors()); From 0f4e3e53beaa16c71efa01cebceeecd42dbfb435 Mon Sep 17 00:00:00 2001 From: Jacob Bolda Date: Wed, 22 Mar 2023 12:03:21 -0500 Subject: [PATCH 2/2] compare BuiltinKindsEntityProcessor name directly after init Signed-off-by: Jacob Bolda --- plugins/catalog-backend/src/service/CatalogBuilder.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index 8d40745e9d..782ad1bf3c 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -608,15 +608,17 @@ export class CatalogBuilder { }), ]; + const builtinKindsEntityProcessor = new BuiltinKindsEntityProcessor(); // If the user adds a processor named 'BuiltinKindsEntityProcessor', // skip inclusion of the catalog-backend version. if ( - !this.processors.find( + !this.processors.some( processor => - processor.getProcessorName() === 'BuiltinKindsEntityProcessor', + processor.getProcessorName() === + builtinKindsEntityProcessor.getProcessorName(), ) ) { - processors.push(new BuiltinKindsEntityProcessor()); + processors.push(builtinKindsEntityProcessor); } // These are only added unless the user replaced them all