diff --git a/.changeset/wet-crabs-send.md b/.changeset/wet-crabs-send.md new file mode 100644 index 0000000000..edac0562fd --- /dev/null +++ b/.changeset/wet-crabs-send.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Add support to disable catalog providers and processors via configuration diff --git a/plugins/catalog-backend/config.d.ts b/plugins/catalog-backend/config.d.ts index a506476dbf..659cf82280 100644 --- a/plugins/catalog-backend/config.d.ts +++ b/plugins/catalog-backend/config.d.ts @@ -221,5 +221,37 @@ export interface Config { * housing catalog-info files. */ processingInterval?: HumanDuration | false; + + /** + * Catalog provide specific configuration. + * Additional configuration for providers are specified in the catalog + * modules. + */ + providers?: { + /** + * Name is the provider ID, e.g. "bitbucketServer" + */ + [name: string]: { + /** + * Whether the provider is enabled or not. Defaults to true. + */ + enabled?: boolean; + }; + }; + /** + * Configuration for entity processors. Additional configuration for + * processors are specified in the catalog modules. + */ + processors?: { + /** + * Name is the processor ID, e.g. "catalog-processor" + */ + [name: string]: { + /** + * Whether the processor is enabled or not. Defaults to true. + */ + enabled?: boolean; + }; + }; }; } diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index e697c6e77f..aab2efd1cb 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -568,9 +568,11 @@ export class CatalogBuilder { const locationStore = new DefaultLocationStore(dbClient); const configLocationProvider = new ConfigLocationEntityProvider(config); - const entityProviders = lodash.uniqBy( - [...this.entityProviders, locationStore, configLocationProvider], - provider => provider.getProviderName(), + const entityProviders = this.filterProviders( + lodash.uniqBy( + [...this.entityProviders, locationStore, configLocationProvider], + provider => provider.getProviderName(), + ), ); const processingEngine = new DefaultCatalogProcessingEngine({ @@ -725,7 +727,30 @@ export class CatalogBuilder { this.checkMissingExternalProcessors(processors); - return processors; + return this.filterProcessors(processors); + } + + private filterProcessors(processors: CatalogProcessor[]) { + const { config } = this.env; + const processorsConfig = config.getOptionalConfig('catalog.processors'); + if (!processorsConfig) { + return processors; + } + const keys = Object.keys(processorsConfig); + for (const key of keys) { + if (!processors.find(p => p.getProcessorName() === key)) { + this.env.logger.warn( + `Invalid catalog processor configuration catalog.processors.${key}: no such processor`, + ); + } + } + + return processors.filter(p => { + const processorConfig = processorsConfig.getOptionalConfig( + p.getProcessorName(), + ); + return processorConfig?.getOptionalBoolean('enabled') ?? true; + }); } // TODO(Rugvip): These old processors are removed, for a while we'll be throwing @@ -838,6 +863,30 @@ export class CatalogBuilder { ); } + private filterProviders(providers: EntityProvider[]) { + const { config, logger } = this.env; + const providersConfig = config.getOptionalConfig('catalog.providers'); + if (!providersConfig) { + return providers; + } + + const keys = Object.keys(providersConfig); + for (const key of keys) { + if (!providers.find(p => p.getProviderName() === key)) { + logger.warn( + `Invalid catalog provider configuration catalog.providers.${key}: no such provider`, + ); + } + } + + return providers.filter(p => { + const providerConfig = providersConfig.getOptionalConfig( + p.getProviderName(), + ); + return providerConfig?.getOptionalBoolean('enabled') ?? true; + }); + } + private static getDefaultProcessingInterval( config: Config, ): ProcessingIntervalFunction {