refactor: deprecate create router
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -9,11 +9,11 @@ import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { CatalogEntityDocument } from '@backstage/plugin-catalog-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { GetEntitiesRequest } from '@backstage/catalog-client';
|
||||
import { Permission } from '@backstage/plugin-permission-common';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { Readable } from 'stream';
|
||||
import { TokenManager } from '@backstage/backend-common';
|
||||
|
||||
@@ -25,7 +25,7 @@ export type CatalogCollatorEntityTransformer = (
|
||||
// @public (undocumented)
|
||||
export const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer;
|
||||
|
||||
// @public
|
||||
// @public @deprecated
|
||||
export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {
|
||||
// (undocumented)
|
||||
static fromConfig(
|
||||
@@ -40,10 +40,10 @@ export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {
|
||||
readonly visibilityPermission: Permission;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
// @public @deprecated (undocumented)
|
||||
export type DefaultCatalogCollatorFactoryOptions = {
|
||||
auth?: AuthService;
|
||||
discovery: PluginEndpointDiscovery;
|
||||
discovery: DiscoveryService;
|
||||
tokenManager?: TokenManager;
|
||||
locationTemplate?: string;
|
||||
filter?: GetEntitiesRequest['filter'];
|
||||
|
||||
+3
-12
@@ -14,10 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { registerMswTestHooks } from '@backstage/backend-test-utils';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
@@ -26,6 +22,7 @@ import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { Readable } from 'stream';
|
||||
import { DefaultCatalogCollatorFactory } from './DefaultCatalogCollatorFactory';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
|
||||
const server = setupServer();
|
||||
|
||||
@@ -61,17 +58,13 @@ const expectedEntities: Entity[] = [
|
||||
|
||||
describe('DefaultCatalogCollatorFactory', () => {
|
||||
const config = new ConfigReader({});
|
||||
const mockDiscoveryApi: jest.Mocked<PluginEndpointDiscovery> = {
|
||||
const mockDiscoveryApi: jest.Mocked<DiscoveryService> = {
|
||||
getBaseUrl: jest.fn().mockResolvedValue('http://localhost:7007'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
const mockTokenManager: jest.Mocked<TokenManager> = {
|
||||
getToken: jest.fn().mockResolvedValue({ token: '' }),
|
||||
authenticate: jest.fn(),
|
||||
};
|
||||
|
||||
const options = {
|
||||
discovery: mockDiscoveryApi,
|
||||
tokenManager: mockTokenManager,
|
||||
};
|
||||
|
||||
registerMswTestHooks(server);
|
||||
@@ -209,7 +202,6 @@ describe('DefaultCatalogCollatorFactory', () => {
|
||||
// Provide an alternate location template.
|
||||
factory = DefaultCatalogCollatorFactory.fromConfig(new ConfigReader({}), {
|
||||
discovery: mockDiscoveryApi,
|
||||
tokenManager: mockTokenManager,
|
||||
locationTemplate: '/software/:name',
|
||||
});
|
||||
collator = await factory.getCollator();
|
||||
@@ -225,7 +217,6 @@ describe('DefaultCatalogCollatorFactory', () => {
|
||||
// Provide a custom filter.
|
||||
factory = DefaultCatalogCollatorFactory.fromConfig(new ConfigReader({}), {
|
||||
discovery: mockDiscoveryApi,
|
||||
tokenManager: mockTokenManager,
|
||||
filter: {
|
||||
kind: ['Foo', 'Bar'],
|
||||
},
|
||||
|
||||
+8
-5
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
createLegacyAuthAdapters,
|
||||
} from '@backstage/backend-common';
|
||||
@@ -34,12 +33,15 @@ import { Readable } from 'stream';
|
||||
import { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer';
|
||||
import { readCollatorConfigOptions } from './config';
|
||||
import { defaultCatalogCollatorEntityTransformer } from './defaultCatalogCollatorEntityTransformer';
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
|
||||
/** @public */
|
||||
/**
|
||||
* @public
|
||||
* @deprecated This type is deprecated along with the {@link DefaultCatalogCollatorFactory}.
|
||||
*/
|
||||
export type DefaultCatalogCollatorFactoryOptions = {
|
||||
auth?: AuthService;
|
||||
discovery: PluginEndpointDiscovery;
|
||||
discovery: DiscoveryService;
|
||||
tokenManager?: TokenManager;
|
||||
/**
|
||||
* @deprecated Use the config key `search.collators.catalog.locationTemplate` instead.
|
||||
@@ -64,6 +66,7 @@ export type DefaultCatalogCollatorFactoryOptions = {
|
||||
* Collates entities from the Catalog into documents for the search backend.
|
||||
*
|
||||
* @public
|
||||
* @deprecated Migrate to the {@link https://backstage.io/docs/backend-system/building-backends/migrating | new backend system} and install this collator via module instead (see {@link https://github.com/backstage/backstage/blob/nbs10/search-deprecate-create-router/plugins/search-backend-module-catalog/README.md#installation | here} for more installation details).
|
||||
*/
|
||||
export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {
|
||||
public readonly type = 'software-catalog';
|
||||
@@ -105,7 +108,7 @@ export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {
|
||||
batchSize: number;
|
||||
entityTransformer?: CatalogCollatorEntityTransformer;
|
||||
auth: AuthService;
|
||||
discovery: PluginEndpointDiscovery;
|
||||
discovery: DiscoveryService;
|
||||
catalogClient?: CatalogApi;
|
||||
}) {
|
||||
const {
|
||||
|
||||
@@ -14,7 +14,6 @@ import { Config } from '@backstage/config';
|
||||
import type { ConnectionOptions } from 'tls';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import { IndexableResultSet } from '@backstage/plugin-search-common';
|
||||
import { Logger } from 'winston';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { Readable } from 'stream';
|
||||
import { SearchEngine } from '@backstage/plugin-search-backend-node';
|
||||
@@ -306,7 +305,7 @@ export interface ElasticSearchNodeOptions {
|
||||
|
||||
// @public
|
||||
export type ElasticSearchOptions = {
|
||||
logger: Logger | LoggerService;
|
||||
logger: LoggerService;
|
||||
config: Config;
|
||||
aliasPostfix?: string;
|
||||
indexPrefix?: string;
|
||||
@@ -330,7 +329,7 @@ export class ElasticSearchSearchEngine implements SearchEngine {
|
||||
elasticSearchClientOptions: ElasticSearchClientOptions,
|
||||
aliasPostfix: string,
|
||||
indexPrefix: string,
|
||||
logger: Logger | LoggerService,
|
||||
logger: LoggerService,
|
||||
batchSize: number,
|
||||
highlightOptions?: ElasticSearchHighlightOptions,
|
||||
);
|
||||
@@ -373,7 +372,7 @@ export type ElasticSearchSearchEngineIndexerOptions = {
|
||||
indexPrefix: string;
|
||||
indexSeparator: string;
|
||||
alias: string;
|
||||
logger: Logger | LoggerService;
|
||||
logger: LoggerService;
|
||||
elasticSearchClientWrapper: ElasticSearchClientWrapper;
|
||||
batchSize: number;
|
||||
skipRefresh?: boolean;
|
||||
|
||||
@@ -59,8 +59,7 @@
|
||||
"aws4": "^1.12.0",
|
||||
"elastic-builder": "^2.16.0",
|
||||
"lodash": "^4.17.21",
|
||||
"uuid": "^9.0.0",
|
||||
"winston": "^3.2.1"
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
|
||||
+2
-3
@@ -33,7 +33,6 @@ import {
|
||||
import { ElasticSearchClientWrapper } from './ElasticSearchClientWrapper';
|
||||
import { ElasticSearchCustomIndexTemplate } from './types';
|
||||
import { ElasticSearchSearchEngineIndexer } from './ElasticSearchSearchEngineIndexer';
|
||||
import { Logger } from 'winston';
|
||||
import { MissingIndexError } from '@backstage/plugin-search-backend-node';
|
||||
import esb from 'elastic-builder';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
@@ -77,7 +76,7 @@ export type ElasticSearchQueryTranslator = (
|
||||
* @public
|
||||
*/
|
||||
export type ElasticSearchOptions = {
|
||||
logger: Logger | LoggerService;
|
||||
logger: LoggerService;
|
||||
config: Config;
|
||||
aliasPostfix?: string;
|
||||
indexPrefix?: string;
|
||||
@@ -131,7 +130,7 @@ export class ElasticSearchSearchEngine implements SearchEngine {
|
||||
private readonly elasticSearchClientOptions: ElasticSearchClientOptions,
|
||||
private readonly aliasPostfix: string,
|
||||
private readonly indexPrefix: string,
|
||||
private readonly logger: Logger | LoggerService,
|
||||
private readonly logger: LoggerService,
|
||||
private readonly batchSize: number,
|
||||
highlightOptions?: ElasticSearchHighlightOptions,
|
||||
) {
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@
|
||||
import { BatchSearchEngineIndexer } from '@backstage/plugin-search-backend-node';
|
||||
import { ElasticSearchClientWrapper } from './ElasticSearchClientWrapper';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import { Logger } from 'winston';
|
||||
import { Readable } from 'stream';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
|
||||
@@ -30,7 +29,7 @@ export type ElasticSearchSearchEngineIndexerOptions = {
|
||||
indexPrefix: string;
|
||||
indexSeparator: string;
|
||||
alias: string;
|
||||
logger: Logger | LoggerService;
|
||||
logger: LoggerService;
|
||||
elasticSearchClientWrapper: ElasticSearchClientWrapper;
|
||||
batchSize: number;
|
||||
skipRefresh?: boolean;
|
||||
@@ -56,7 +55,7 @@ export class ElasticSearchSearchEngineIndexer extends BatchSearchEngineIndexer {
|
||||
private readonly indexPrefix: string;
|
||||
private readonly indexSeparator: string;
|
||||
private readonly alias: string;
|
||||
private readonly logger: Logger | LoggerService;
|
||||
private readonly logger: LoggerService;
|
||||
private readonly sourceStream: Readable;
|
||||
private readonly elasticSearchClientWrapper: ElasticSearchClientWrapper;
|
||||
private configuredBatchSize: number;
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
|
||||
import { ExploreTool } from '@backstage-community/plugin-explore-common';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { Readable } from 'stream';
|
||||
import { TokenManager } from '@backstage/backend-common';
|
||||
|
||||
// @public
|
||||
export interface ToolDocument extends IndexableDocument, ExploreTool {}
|
||||
|
||||
// @public
|
||||
// @public @deprecated
|
||||
export class ToolDocumentCollatorFactory implements DocumentCollatorFactory {
|
||||
// (undocumented)
|
||||
execute(): AsyncGenerator<ToolDocument>;
|
||||
@@ -33,9 +33,9 @@ export class ToolDocumentCollatorFactory implements DocumentCollatorFactory {
|
||||
readonly type: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
// @public @deprecated (undocumented)
|
||||
export type ToolDocumentCollatorFactoryOptions = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
discovery: DiscoveryService;
|
||||
logger: LoggerService;
|
||||
tokenManager?: TokenManager;
|
||||
auth?: AuthService;
|
||||
|
||||
+3
-10
@@ -13,10 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { TestPipeline } from '@backstage/plugin-search-backend-node';
|
||||
import {
|
||||
@@ -27,6 +23,7 @@ import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { Readable } from 'stream';
|
||||
import { ToolDocumentCollatorFactory } from './ToolDocumentCollatorFactory';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
|
||||
const logger = mockServices.logger.mock();
|
||||
|
||||
@@ -58,18 +55,14 @@ const mockTools = {
|
||||
|
||||
describe('ToolDocumentCollatorFactory', () => {
|
||||
const config = new ConfigReader({});
|
||||
const mockDiscoveryApi: jest.Mocked<PluginEndpointDiscovery> = {
|
||||
const mockDiscoveryApi: jest.Mocked<DiscoveryService> = {
|
||||
getBaseUrl: jest.fn().mockResolvedValue('http://test-backend/api/explore'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
const mockTokenManager: jest.Mocked<TokenManager> = {
|
||||
getToken: jest.fn().mockResolvedValue({ token: '' }),
|
||||
authenticate: jest.fn(),
|
||||
};
|
||||
|
||||
const options = {
|
||||
discovery: mockDiscoveryApi,
|
||||
logger,
|
||||
tokenManager: mockTokenManager,
|
||||
};
|
||||
|
||||
it('has expected type', () => {
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
import {
|
||||
createLegacyAuthAdapters,
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { AuthService, LoggerService } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
AuthService,
|
||||
DiscoveryService,
|
||||
LoggerService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { ExploreTool } from '@backstage-community/plugin-explore-common';
|
||||
import {
|
||||
@@ -37,12 +40,11 @@ import { Readable } from 'stream';
|
||||
export interface ToolDocument extends IndexableDocument, ExploreTool {}
|
||||
|
||||
/**
|
||||
* The options for the {@link ToolDocumentCollatorFactory}.
|
||||
*
|
||||
* @public
|
||||
* @deprecated This type is deprecated along with the {@link ToolDocumentCollatorFactory}.
|
||||
*/
|
||||
export type ToolDocumentCollatorFactoryOptions = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
discovery: DiscoveryService;
|
||||
logger: LoggerService;
|
||||
tokenManager?: TokenManager;
|
||||
auth?: AuthService;
|
||||
@@ -52,18 +54,18 @@ export type ToolDocumentCollatorFactoryOptions = {
|
||||
* Search collator responsible for collecting explore tools to index.
|
||||
*
|
||||
* @public
|
||||
* @deprecated Migrate to the {@link https://backstage.io/docs/backend-system/building-backends/migrating | new backend system} and install this collator via module instead (see {@link https://github.com/backstage/backstage/blob/nbs10/search-deprecate-create-router/plugins/search-backend-module-explore/README.md#installation | here} for more installation details).
|
||||
*/
|
||||
export class ToolDocumentCollatorFactory implements DocumentCollatorFactory {
|
||||
public readonly type: string = 'tools';
|
||||
|
||||
private readonly discovery: PluginEndpointDiscovery;
|
||||
private readonly discovery: DiscoveryService;
|
||||
private readonly logger: LoggerService;
|
||||
private readonly auth: AuthService;
|
||||
|
||||
private constructor(options: ToolDocumentCollatorFactoryOptions) {
|
||||
this.discovery = options.discovery;
|
||||
this.logger = options.logger;
|
||||
|
||||
this.auth = createLegacyAuthAdapters(options).auth;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
```ts
|
||||
import { BatchSearchEngineIndexer } from '@backstage/plugin-search-backend-node';
|
||||
import { Config } from '@backstage/config';
|
||||
import { DatabaseService } from '@backstage/backend-plugin-api';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import { IndexableResultSet } from '@backstage/plugin-search-common';
|
||||
import { Knex } from 'knex';
|
||||
import { Logger } from 'winston';
|
||||
import { PluginDatabaseManager } from '@backstage/backend-common';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { SearchEngine } from '@backstage/plugin-search-backend-node';
|
||||
import { SearchQuery } from '@backstage/plugin-search-common';
|
||||
|
||||
@@ -25,9 +25,7 @@ export class DatabaseDocumentStore implements DatabaseStore {
|
||||
// (undocumented)
|
||||
completeInsert(tx: Knex.Transaction, type: string): Promise<void>;
|
||||
// (undocumented)
|
||||
static create(
|
||||
database: PluginDatabaseManager,
|
||||
): Promise<DatabaseDocumentStore>;
|
||||
static create(database: DatabaseService): Promise<DatabaseDocumentStore>;
|
||||
// (undocumented)
|
||||
getTransaction(): Promise<Knex.Transaction>;
|
||||
// (undocumented)
|
||||
@@ -85,12 +83,16 @@ export interface DocumentResultRow {
|
||||
// @public (undocumented)
|
||||
export class PgSearchEngine implements SearchEngine {
|
||||
// @deprecated
|
||||
constructor(databaseStore: DatabaseStore, config: Config, logger?: Logger);
|
||||
constructor(
|
||||
databaseStore: DatabaseStore,
|
||||
config: Config,
|
||||
logger?: LoggerService,
|
||||
);
|
||||
// @deprecated (undocumented)
|
||||
static from(options: {
|
||||
database: PluginDatabaseManager;
|
||||
database: DatabaseService;
|
||||
config: Config;
|
||||
logger?: Logger;
|
||||
logger?: LoggerService;
|
||||
}): Promise<PgSearchEngine>;
|
||||
// (undocumented)
|
||||
static fromConfig(
|
||||
@@ -104,7 +106,7 @@ export class PgSearchEngine implements SearchEngine {
|
||||
// (undocumented)
|
||||
setTranslator(translator: PgSearchQueryTranslator): void;
|
||||
// (undocumented)
|
||||
static supported(database: PluginDatabaseManager): Promise<boolean>;
|
||||
static supported(database: DatabaseService): Promise<boolean>;
|
||||
// (undocumented)
|
||||
translator(
|
||||
query: SearchQuery,
|
||||
@@ -128,7 +130,7 @@ export type PgSearchEngineIndexerOptions = {
|
||||
batchSize: number;
|
||||
type: string;
|
||||
databaseStore: DatabaseStore;
|
||||
logger?: Logger;
|
||||
logger?: LoggerService;
|
||||
};
|
||||
|
||||
// @public
|
||||
@@ -146,8 +148,8 @@ export type PgSearchHighlightOptions = {
|
||||
|
||||
// @public
|
||||
export type PgSearchOptions = {
|
||||
database: PluginDatabaseManager;
|
||||
logger?: Logger;
|
||||
database: DatabaseService;
|
||||
logger?: LoggerService;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -56,8 +56,7 @@
|
||||
"@backstage/plugin-search-common": "workspace:^",
|
||||
"knex": "^3.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"uuid": "^9.0.0",
|
||||
"winston": "^3.2.1"
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PluginDatabaseManager } from '@backstage/backend-common';
|
||||
import { SearchEngine } from '@backstage/plugin-search-backend-node';
|
||||
import {
|
||||
SearchQuery,
|
||||
@@ -28,8 +27,8 @@ import {
|
||||
PgSearchQuery,
|
||||
} from '../database';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
import { DatabaseService, LoggerService } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* Search query that the Postgres search engine understands.
|
||||
@@ -62,8 +61,8 @@ export type PgSearchQueryTranslator = (
|
||||
* @public
|
||||
*/
|
||||
export type PgSearchOptions = {
|
||||
database: PluginDatabaseManager;
|
||||
logger?: Logger;
|
||||
database: DatabaseService;
|
||||
logger?: LoggerService;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -84,7 +83,7 @@ export type PgSearchHighlightOptions = {
|
||||
|
||||
/** @public */
|
||||
export class PgSearchEngine implements SearchEngine {
|
||||
private readonly logger?: Logger;
|
||||
private readonly logger?: LoggerService;
|
||||
private readonly highlightOptions: PgSearchHighlightOptions;
|
||||
private readonly indexerBatchSize: number;
|
||||
|
||||
@@ -94,7 +93,7 @@ export class PgSearchEngine implements SearchEngine {
|
||||
constructor(
|
||||
private readonly databaseStore: DatabaseStore,
|
||||
config: Config,
|
||||
logger?: Logger,
|
||||
logger?: LoggerService,
|
||||
) {
|
||||
const uuidTag = uuid();
|
||||
const highlightConfig = config.getOptionalConfig(
|
||||
@@ -121,12 +120,12 @@ export class PgSearchEngine implements SearchEngine {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This will be removed in a future release, please us fromConfig instead
|
||||
* @deprecated This will be removed in a future release, please use fromConfig instead
|
||||
*/
|
||||
static async from(options: {
|
||||
database: PluginDatabaseManager;
|
||||
database: DatabaseService;
|
||||
config: Config;
|
||||
logger?: Logger;
|
||||
logger?: LoggerService;
|
||||
}): Promise<PgSearchEngine> {
|
||||
return new PgSearchEngine(
|
||||
await DatabaseDocumentStore.create(options.database),
|
||||
@@ -143,7 +142,7 @@ export class PgSearchEngine implements SearchEngine {
|
||||
);
|
||||
}
|
||||
|
||||
static async supported(database: PluginDatabaseManager): Promise<boolean> {
|
||||
static async supported(database: DatabaseService): Promise<boolean> {
|
||||
return await DatabaseDocumentStore.supported(await database.getClient());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,20 +17,20 @@
|
||||
import { BatchSearchEngineIndexer } from '@backstage/plugin-search-backend-node';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import { Knex } from 'knex';
|
||||
import { Logger } from 'winston';
|
||||
import { DatabaseStore } from '../database';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
|
||||
/** @public */
|
||||
export type PgSearchEngineIndexerOptions = {
|
||||
batchSize: number;
|
||||
type: string;
|
||||
databaseStore: DatabaseStore;
|
||||
logger?: Logger;
|
||||
logger?: LoggerService;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export class PgSearchEngineIndexer extends BatchSearchEngineIndexer {
|
||||
private logger?: Logger;
|
||||
private logger?: LoggerService;
|
||||
private store: DatabaseStore;
|
||||
private type: string;
|
||||
private tx: Knex.Transaction | undefined;
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';
|
||||
import { PgSearchEngine } from './PgSearchEngine';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
@@ -41,7 +40,7 @@ export default createBackendModule({
|
||||
searchEngineRegistry.setSearchEngine(
|
||||
await PgSearchEngine.fromConfig(config, {
|
||||
database,
|
||||
logger: loggerToWinstonLogger(logger),
|
||||
logger,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PluginDatabaseManager } from '@backstage/backend-common';
|
||||
import { resolvePackagePath } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
DatabaseService,
|
||||
resolvePackagePath,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import { Knex } from 'knex';
|
||||
import {
|
||||
@@ -33,7 +35,7 @@ const migrationsDir = resolvePackagePath(
|
||||
/** @public */
|
||||
export class DatabaseDocumentStore implements DatabaseStore {
|
||||
static async create(
|
||||
database: PluginDatabaseManager,
|
||||
database: DatabaseService,
|
||||
): Promise<DatabaseDocumentStore> {
|
||||
const knex = await database.getClient();
|
||||
try {
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
import { AuthService } from '@backstage/backend-plugin-api';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { Config } from '@backstage/config';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { HttpAuthService } from '@backstage/backend-plugin-api';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { Permission } from '@backstage/plugin-permission-common';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { Readable } from 'stream';
|
||||
import { TechDocsDocument } from '@backstage/plugin-techdocs-node';
|
||||
import { TokenManager } from '@backstage/backend-common';
|
||||
@@ -21,7 +21,7 @@ import { TokenManager } from '@backstage/backend-common';
|
||||
// @public (undocumented)
|
||||
export const defaultTechDocsCollatorEntityTransformer: TechDocsCollatorEntityTransformer;
|
||||
|
||||
// @public
|
||||
// @public @deprecated
|
||||
export class DefaultTechDocsCollatorFactory implements DocumentCollatorFactory {
|
||||
// (undocumented)
|
||||
static fromConfig(
|
||||
@@ -41,9 +41,9 @@ export type TechDocsCollatorEntityTransformer = (
|
||||
entity: Entity,
|
||||
) => Omit<TechDocsDocument, 'location' | 'authorization'>;
|
||||
|
||||
// @public
|
||||
// @public @deprecated
|
||||
export type TechDocsCollatorFactoryOptions = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
discovery: DiscoveryService;
|
||||
logger: LoggerService;
|
||||
tokenManager?: TokenManager;
|
||||
auth?: AuthService;
|
||||
|
||||
+2
-11
@@ -13,10 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { TestPipeline } from '@backstage/plugin-search-backend-node';
|
||||
@@ -30,6 +26,7 @@ import { Readable } from 'stream';
|
||||
import { DefaultTechDocsCollatorFactory } from './DefaultTechDocsCollatorFactory';
|
||||
import { defaultTechDocsCollatorEntityTransformer } from './defaultTechDocsCollatorEntityTransformer';
|
||||
import { TechDocsCollatorEntityTransformer } from './TechDocsCollatorEntityTransformer';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
|
||||
const logger = mockServices.logger.mock();
|
||||
|
||||
@@ -82,18 +79,13 @@ const expectedEntities: Entity[] = [
|
||||
|
||||
describe('DefaultTechDocsCollatorFactory', () => {
|
||||
const config = new ConfigReader({});
|
||||
const mockDiscoveryApi: jest.Mocked<PluginEndpointDiscovery> = {
|
||||
const mockDiscoveryApi: jest.Mocked<DiscoveryService> = {
|
||||
getBaseUrl: jest.fn().mockResolvedValue('http://test-backend'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
const mockTokenManager: jest.Mocked<TokenManager> = {
|
||||
getToken: jest.fn().mockResolvedValue({ token: '' }),
|
||||
authenticate: jest.fn(),
|
||||
};
|
||||
const options = {
|
||||
logger,
|
||||
discovery: mockDiscoveryApi,
|
||||
tokenManager: mockTokenManager,
|
||||
};
|
||||
|
||||
it('has expected type', () => {
|
||||
@@ -187,7 +179,6 @@ describe('DefaultTechDocsCollatorFactory', () => {
|
||||
});
|
||||
factory = DefaultTechDocsCollatorFactory.fromConfig(_config, {
|
||||
discovery: mockDiscoveryApi,
|
||||
tokenManager: mockTokenManager,
|
||||
logger,
|
||||
});
|
||||
collator = await factory.getCollator();
|
||||
|
||||
+5
-3
@@ -16,7 +16,6 @@
|
||||
|
||||
import {
|
||||
createLegacyAuthAdapters,
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
} from '@backstage/backend-common';
|
||||
import {
|
||||
@@ -43,6 +42,7 @@ import { TechDocsCollatorEntityTransformer } from './TechDocsCollatorEntityTrans
|
||||
import { defaultTechDocsCollatorEntityTransformer } from './defaultTechDocsCollatorEntityTransformer';
|
||||
import {
|
||||
AuthService,
|
||||
DiscoveryService,
|
||||
HttpAuthService,
|
||||
LoggerService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
@@ -57,9 +57,10 @@ interface MkSearchIndexDoc {
|
||||
* Options to configure the TechDocs collator factory
|
||||
*
|
||||
* @public
|
||||
* @deprecated This type is deprecated along with the {@link DefaultTechDocsCollatorFactory}.
|
||||
*/
|
||||
export type TechDocsCollatorFactoryOptions = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
discovery: DiscoveryService;
|
||||
logger: LoggerService;
|
||||
tokenManager?: TokenManager;
|
||||
auth?: AuthService;
|
||||
@@ -82,13 +83,14 @@ type EntityInfo = {
|
||||
* TechDocs documents.
|
||||
*
|
||||
* @public
|
||||
* @deprecated Migrate to the {@link https://backstage.io/docs/backend-system/building-backends/migrating | new backend system} and install this collator via module instead (see {@link https://github.com/backstage/backstage/blob/nbs10/search-deprecate-create-router/plugins/search-backend-module-techdocs/README.md#installation | here} for more installation details).
|
||||
*/
|
||||
export class DefaultTechDocsCollatorFactory implements DocumentCollatorFactory {
|
||||
public readonly type: string = 'techdocs';
|
||||
public readonly visibilityPermission: Permission =
|
||||
catalogEntityReadPermission;
|
||||
|
||||
private discovery: PluginEndpointDiscovery;
|
||||
private discovery: DiscoveryService;
|
||||
private locationTemplate: string;
|
||||
private readonly logger: LoggerService;
|
||||
private readonly auth: AuthService;
|
||||
|
||||
@@ -14,10 +14,10 @@ import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
|
||||
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
|
||||
import { SearchEngine } from '@backstage/plugin-search-backend-node';
|
||||
|
||||
// @public (undocumented)
|
||||
// @public @deprecated (undocumented)
|
||||
export function createRouter(options: RouterOptions): Promise<express.Router>;
|
||||
|
||||
// @public (undocumented)
|
||||
// @public @deprecated (undocumented)
|
||||
export type RouterOptions = {
|
||||
engine: SearchEngine;
|
||||
types: Record<string, DocumentTypeInfo>;
|
||||
|
||||
@@ -72,7 +72,6 @@
|
||||
"express": "^4.17.1",
|
||||
"lodash": "^4.17.21",
|
||||
"qs": "^6.10.1",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
|
||||
import {
|
||||
@@ -27,6 +26,8 @@ import { createRouter } from './router';
|
||||
import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils';
|
||||
import { Server } from 'http';
|
||||
import { mockCredentials, mockServices } from '@backstage/backend-test-utils';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';
|
||||
|
||||
const mockPermissionEvaluator: PermissionEvaluator = {
|
||||
authorize: () => {
|
||||
@@ -42,7 +43,7 @@ describe('createRouter', () => {
|
||||
let mockSearchEngine: jest.Mocked<SearchEngine>;
|
||||
|
||||
const mockBaseUrl = 'http://backstage:9191/api/proxy';
|
||||
const discovery: PluginEndpointDiscovery = {
|
||||
const discovery: DiscoveryService = {
|
||||
async getBaseUrl() {
|
||||
return mockBaseUrl;
|
||||
},
|
||||
@@ -83,7 +84,11 @@ describe('createRouter', () => {
|
||||
auth: mockServices.auth(),
|
||||
httpAuth: mockServices.httpAuth(),
|
||||
});
|
||||
app = wrapInOpenApiTestServer(express().use(router));
|
||||
const errorHandler = MiddlewareFactory.create({
|
||||
config: mockServices.rootConfig(),
|
||||
logger: mockServices.rootLogger(),
|
||||
}).error();
|
||||
app = wrapInOpenApiTestServer(express().use(router).use(errorHandler));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
import express from 'express';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
createLegacyAuthAdapters,
|
||||
errorHandler,
|
||||
HostDiscovery,
|
||||
} from '@backstage/backend-common';
|
||||
import { createLegacyAuthAdapters } from '@backstage/backend-common';
|
||||
import { InputError } from '@backstage/errors';
|
||||
import { Config } from '@backstage/config';
|
||||
import { JsonObject, JsonValue } from '@backstage/types';
|
||||
@@ -43,6 +39,7 @@ import {
|
||||
HttpAuthService,
|
||||
LoggerService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { HostDiscovery } from '@backstage/backend-defaults/discovery';
|
||||
|
||||
const jsonObjectSchema: z.ZodSchema<JsonObject> = z.lazy(() => {
|
||||
const jsonValueSchema: z.ZodSchema<JsonValue> = z.lazy(() =>
|
||||
@@ -61,6 +58,7 @@ const jsonObjectSchema: z.ZodSchema<JsonObject> = z.lazy(() => {
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated Please migrate to the new backend system as this will be removed in the future.
|
||||
*/
|
||||
export type RouterOptions = {
|
||||
engine: SearchEngine;
|
||||
@@ -69,6 +67,7 @@ export type RouterOptions = {
|
||||
permissions: PermissionEvaluator | PermissionAuthorizer;
|
||||
config: Config;
|
||||
logger: LoggerService;
|
||||
// TODO: Make "auth" and "httpAuth" required once we remove the usage of "tokenManager"
|
||||
auth?: AuthService;
|
||||
httpAuth?: HttpAuthService;
|
||||
};
|
||||
@@ -79,6 +78,7 @@ const allowedLocationProtocols = ['http:', 'https:'];
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated Please migrate to the new backend system as this will be removed in the future.
|
||||
*/
|
||||
export async function createRouter(
|
||||
options: RouterOptions,
|
||||
@@ -93,6 +93,7 @@ export async function createRouter(
|
||||
discovery = HostDiscovery.fromConfig(config),
|
||||
} = options;
|
||||
|
||||
// TODO: stop using this adapter when the "tokenManager" is removed
|
||||
const { auth, httpAuth } = createLegacyAuthAdapters({
|
||||
...options,
|
||||
discovery,
|
||||
@@ -217,7 +218,5 @@ export async function createRouter(
|
||||
}
|
||||
});
|
||||
|
||||
router.use(errorHandler());
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -7445,7 +7445,6 @@ __metadata:
|
||||
elastic-builder: ^2.16.0
|
||||
lodash: ^4.17.21
|
||||
uuid: ^9.0.0
|
||||
winston: ^3.2.1
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -7480,7 +7479,6 @@ __metadata:
|
||||
knex: ^3.0.0
|
||||
lodash: ^4.17.21
|
||||
uuid: ^9.0.0
|
||||
winston: ^3.2.1
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -7572,7 +7570,6 @@ __metadata:
|
||||
lodash: ^4.17.21
|
||||
qs: ^6.10.1
|
||||
supertest: ^6.1.3
|
||||
winston: ^3.2.1
|
||||
yn: ^4.0.0
|
||||
zod: ^3.22.4
|
||||
languageName: unknown
|
||||
|
||||
Reference in New Issue
Block a user