diff --git a/.changeset/nice-dryers-dream.md b/.changeset/nice-dryers-dream.md new file mode 100644 index 0000000000..a447bb564a --- /dev/null +++ b/.changeset/nice-dryers-dream.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Implement `NextCatalogBuilder.addEntityProvider` diff --git a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts index e859a225e5..2551c16879 100644 --- a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts +++ b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts @@ -63,7 +63,11 @@ import { } from '../ingestion/processors/PlaceholderProcessor'; import { defaultEntityDataParser } from '../ingestion/processors/util/parse'; import { LocationAnalyzer } from '../ingestion/types'; -import { CatalogProcessingEngine, LocationService } from '../next/types'; +import { + CatalogProcessingEngine, + EntityProvider, + LocationService, +} from '../next/types'; import { ConfigLocationEntityProvider } from './ConfigLocationEntityProvider'; import { DefaultProcessingDatabase } from './database/DefaultProcessingDatabase'; import { DefaultCatalogProcessingEngine } from './DefaultCatalogProcessingEngine'; @@ -105,6 +109,7 @@ export class NextCatalogBuilder { private entityPoliciesReplace: boolean; private placeholderResolvers: Record; private fieldFormatValidators: Partial; + private entityProviders: EntityProvider[]; private processors: CatalogProcessor[]; private processorsReplace: boolean; private parser: CatalogProcessorParser | undefined; @@ -116,6 +121,7 @@ export class NextCatalogBuilder { this.entityPoliciesReplace = false; this.placeholderResolvers = {}; this.fieldFormatValidators = {}; + this.entityProviders = []; this.processors = []; this.processorsReplace = false; this.parser = undefined; @@ -198,6 +204,20 @@ export class NextCatalogBuilder { return this; } + /** + * Adds or replaces entity providers. These are responsible for bootstrapping + * the list of entities out of original data sources. For example, there is + * one entity source for the config locations, and one for the database + * stored locations. If you ingest entities out of a third party system, you + * may want to implement that in terms of an entity provider as well. + * + * @param providers One or more entity providers + */ + addEntityProvider(...providers: EntityProvider[]): NextCatalogBuilder { + this.entityProviders.push(...providers); + return this; + } + /** * Adds entity processors. These are responsible for reading, parsing, and * processing entities before they are persisted in the catalog. @@ -277,13 +297,18 @@ export class NextCatalogBuilder { policy, }); const entitiesCatalog = new NextEntitiesCatalog(dbClient); + const stitcher = new Stitcher(dbClient, logger); const locationStore = new DefaultLocationStore(dbClient); - const stitcher = new Stitcher(dbClient, logger); const configLocationProvider = new ConfigLocationEntityProvider(config); + const entityProviders = lodash.uniqBy( + [...this.entityProviders, locationStore, configLocationProvider], + provider => provider.getProviderName(), + ); + const processingEngine = new DefaultCatalogProcessingEngine( logger, - [locationStore, configLocationProvider], + entityProviders, processingDatabase, orchestrator, stitcher, @@ -295,6 +320,7 @@ export class NextCatalogBuilder { locationStore, orchestrator, ); + return { entitiesCatalog, locationsCatalog,