From 5ae202c23c0a1ea6a695fc655c650c1c8cb49bfd Mon Sep 17 00:00:00 2001 From: Philipp Hugenroth Date: Tue, 8 Aug 2023 17:22:29 +0200 Subject: [PATCH] Remove options for Explore & TechDocs module - Quick fix for permission-backend Signed-off-by: Philipp Hugenroth --- plugins/permission-backend/src/plugin.ts | 4 +- .../search-backend-module-explore/config.d.ts | 25 ++++ .../src/alpha.ts | 97 +++++++------- .../config.d.ts | 30 +++++ .../src/alpha.ts | 123 +++++++++--------- 5 files changed, 161 insertions(+), 118 deletions(-) create mode 100644 plugins/search-backend-module-explore/config.d.ts create mode 100644 plugins/search-backend-module-techdocs/config.d.ts diff --git a/plugins/permission-backend/src/plugin.ts b/plugins/permission-backend/src/plugin.ts index a6b731b120..a131b6e4b4 100644 --- a/plugins/permission-backend/src/plugin.ts +++ b/plugins/permission-backend/src/plugin.ts @@ -80,7 +80,7 @@ export const permissionModuleAllowAllPolicy = createBackendModule({ * * @alpha */ -export const permissionPlugin = createBackendPlugin(() => ({ +export const permissionPlugin = createBackendPlugin({ pluginId: 'permission', register(env) { const policies = new PolicyExtensionPointImpl(); @@ -115,4 +115,4 @@ export const permissionPlugin = createBackendPlugin(() => ({ }, }); }, -})); +}); diff --git a/plugins/search-backend-module-explore/config.d.ts b/plugins/search-backend-module-explore/config.d.ts new file mode 100644 index 0000000000..a9f60632ae --- /dev/null +++ b/plugins/search-backend-module-explore/config.d.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TaskScheduleDefinitionConfig } from '@backstage/backend-tasks'; + +export interface Config { + search?: { + explore?: { + schedule?: TaskScheduleDefinitionConfig; + }; + }; +} diff --git a/plugins/search-backend-module-explore/src/alpha.ts b/plugins/search-backend-module-explore/src/alpha.ts index fadbcda3a5..b60bed66ae 100644 --- a/plugins/search-backend-module-explore/src/alpha.ts +++ b/plugins/search-backend-module-explore/src/alpha.ts @@ -23,66 +23,59 @@ import { coreServices, createBackendModule, } from '@backstage/backend-plugin-api'; -import { TaskScheduleDefinition } from '@backstage/backend-tasks'; import { loggerToWinstonLogger } from '@backstage/backend-common'; import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; import { ToolDocumentCollatorFactory } from '@backstage/plugin-search-backend-module-explore'; - -/** - * Options for {@link searchModuleExploreCollator}. - * - * @alpha - */ -export type SearchModuleExploreCollatorOptions = { - schedule?: TaskScheduleDefinition; -}; +import { readTaskScheduleDefinitionFromConfig } from '@backstage/backend-tasks'; /** * Search backend module for the Explore index. * * @alpha */ -export const searchModuleExploreCollator = createBackendModule( - (options?: SearchModuleExploreCollatorOptions) => ({ - moduleId: 'exploreCollator', - pluginId: 'search', - register(env) { - env.registerInit({ - deps: { - config: coreServices.rootConfig, - logger: coreServices.logger, - discovery: coreServices.discovery, - scheduler: coreServices.scheduler, - tokenManager: coreServices.tokenManager, - indexRegistry: searchIndexRegistryExtensionPoint, - }, - async init({ - config, - logger, - discovery, - scheduler, - indexRegistry, - tokenManager, - }) { - const defaultSchedule = { - frequency: { minutes: 10 }, - timeout: { minutes: 15 }, - initialDelay: { seconds: 3 }, - }; +export const searchModuleExploreCollator = createBackendModule({ + moduleId: 'exploreCollator', + pluginId: 'search', + register(env) { + env.registerInit({ + deps: { + config: coreServices.rootConfig, + logger: coreServices.logger, + discovery: coreServices.discovery, + scheduler: coreServices.scheduler, + tokenManager: coreServices.tokenManager, + indexRegistry: searchIndexRegistryExtensionPoint, + }, + async init({ + config, + logger, + discovery, + scheduler, + indexRegistry, + tokenManager, + }) { + const defaultSchedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, + }; - indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner( - options?.schedule ?? defaultSchedule, - ), - factory: ToolDocumentCollatorFactory.fromConfig(config, { - discovery, - logger: loggerToWinstonLogger(logger), - tokenManager, - }), - }); - }, - }); - }, - }), -); + const schedule = config.has('search.explore.schedule') + ? readTaskScheduleDefinitionFromConfig( + config.getConfig('search.explore.schedule'), + ) + : defaultSchedule; + + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner(schedule), + factory: ToolDocumentCollatorFactory.fromConfig(config, { + discovery, + logger: loggerToWinstonLogger(logger), + tokenManager, + }), + }); + }, + }); + }, +}); diff --git a/plugins/search-backend-module-techdocs/config.d.ts b/plugins/search-backend-module-techdocs/config.d.ts new file mode 100644 index 0000000000..645895243b --- /dev/null +++ b/plugins/search-backend-module-techdocs/config.d.ts @@ -0,0 +1,30 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TaskScheduleDefinitionConfig } from '@backstage/backend-tasks'; + +export interface Config { + search?: { + techdocs?: { + schedule?: TaskScheduleDefinitionConfig; + collatorsFactory?: { + locationTemplate?: string; + parallelismLimit?: number; + legacyPathCasing?: boolean; + }; + }; + }; +} diff --git a/plugins/search-backend-module-techdocs/src/alpha.ts b/plugins/search-backend-module-techdocs/src/alpha.ts index 5d82b6804f..e4c75425ca 100644 --- a/plugins/search-backend-module-techdocs/src/alpha.ts +++ b/plugins/search-backend-module-techdocs/src/alpha.ts @@ -19,79 +19,74 @@ * A module for the search backend that exports TechDocs modules. */ +import { loggerToWinstonLogger } from '@backstage/backend-common'; import { coreServices, createBackendModule, } from '@backstage/backend-plugin-api'; -import { TaskScheduleDefinition } from '@backstage/backend-tasks'; -import { loggerToWinstonLogger } from '@backstage/backend-common'; -import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; +import { readTaskScheduleDefinitionFromConfig } from '@backstage/backend-tasks'; import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; - -import { - DefaultTechDocsCollatorFactory, - TechDocsCollatorFactoryOptions, -} from '@backstage/plugin-search-backend-module-techdocs'; - -/** - * @alpha - * Options for {@link searchModuleTechDocsCollator}. - */ -export type SearchModuleTechDocsCollatorOptions = Omit< - TechDocsCollatorFactoryOptions, - 'logger' | 'discovery' | 'tokenManager' | 'catalogClient' -> & { - schedule?: TaskScheduleDefinition; -}; +import { DefaultTechDocsCollatorFactory } from '@backstage/plugin-search-backend-module-techdocs'; +import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; /** * @alpha * Search backend module for the TechDocs index. */ -export const searchModuleTechDocsCollator = createBackendModule( - (options?: SearchModuleTechDocsCollatorOptions) => ({ - moduleId: 'techDocsCollator', - pluginId: 'search', - register(env) { - env.registerInit({ - deps: { - config: coreServices.rootConfig, - logger: coreServices.logger, - discovery: coreServices.discovery, - tokenManager: coreServices.tokenManager, - scheduler: coreServices.scheduler, - catalog: catalogServiceRef, - indexRegistry: searchIndexRegistryExtensionPoint, - }, - async init({ - config, - logger, - discovery, - tokenManager, - scheduler, - catalog, - indexRegistry, - }) { - const defaultSchedule = { - frequency: { minutes: 10 }, - timeout: { minutes: 15 }, - initialDelay: { seconds: 3 }, - }; +export const searchModuleTechDocsCollator = createBackendModule({ + moduleId: 'techDocsCollator', + pluginId: 'search', + register(env) { + env.registerInit({ + deps: { + config: coreServices.rootConfig, + logger: coreServices.logger, + discovery: coreServices.discovery, + tokenManager: coreServices.tokenManager, + scheduler: coreServices.scheduler, + catalog: catalogServiceRef, + indexRegistry: searchIndexRegistryExtensionPoint, + }, + async init({ + config, + logger, + discovery, + tokenManager, + scheduler, + catalog, + indexRegistry, + }) { + const defaultSchedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, + }; - indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner( - options?.schedule ?? defaultSchedule, + const schedule = config.has('search.explore.schedule') + ? readTaskScheduleDefinitionFromConfig( + config.getConfig('search.explore.schedule'), + ) + : defaultSchedule; + + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner(schedule), + factory: DefaultTechDocsCollatorFactory.fromConfig(config, { + locationTemplate: config.getOptionalString( + 'search.techdocs.collatorsFactory.locationTemplate', ), - factory: DefaultTechDocsCollatorFactory.fromConfig(config, { - ...options, - discovery, - tokenManager, - logger: loggerToWinstonLogger(logger), - catalogClient: catalog, - }), - }); - }, - }); - }, - }), -); + parallelismLimit: config.getOptionalNumber( + 'search.techdocs.collatorsFactory.parallelismLimit', + ), + legacyPathCasing: config.getOptionalBoolean( + 'search.techdocs.collatorsFactory.legacyPathCasing', + ), + discovery, + tokenManager, + logger: loggerToWinstonLogger(logger), + catalogClient: catalog, + }), + }); + }, + }); + }, +});