refactor: apply review suggestions
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
---
|
||||
'@backstage/create-app': patch
|
||||
---
|
||||
|
||||
Update the search backend template to forward env discovery to the router.
|
||||
@@ -2,4 +2,4 @@
|
||||
'@backstage/plugin-search-backend': patch
|
||||
---
|
||||
|
||||
**BREAKING**: Update the router to use the new `auth` services. The router now requires a discovery service option to get credentials for the permission service.
|
||||
Update the router to use the new `auth` services, it now accepts an optional discovery service option to get credentials for the permission service.
|
||||
|
||||
@@ -60,7 +60,6 @@ export default async function createPlugin(
|
||||
engine: indexBuilder.getSearchEngine(),
|
||||
types: indexBuilder.getDocumentTypes(),
|
||||
permissions: env.permissions,
|
||||
discovery: env.discovery,
|
||||
config: env.config,
|
||||
logger: env.logger,
|
||||
});
|
||||
|
||||
@@ -3,39 +3,12 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
/// <reference types="node" />
|
||||
|
||||
import { BackstageCredentials } from '@backstage/backend-plugin-api';
|
||||
import { DocumentTypeInfo } from '@backstage/plugin-search-common';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { IndexableResultSet } from '@backstage/plugin-search-common';
|
||||
import { RegisterCollatorParameters } from '@backstage/plugin-search-backend-node';
|
||||
import { RegisterDecoratorParameters } from '@backstage/plugin-search-backend-node';
|
||||
import { SearchQuery } from '@backstage/plugin-search-common';
|
||||
import { SearchEngine } from '@backstage/plugin-search-backend-node';
|
||||
import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
import { Writable } from 'stream';
|
||||
|
||||
// @public
|
||||
export type QueryRequestOptions =
|
||||
| {
|
||||
token?: string;
|
||||
}
|
||||
| {
|
||||
credentials: BackstageCredentials;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type QueryTranslator = (query: SearchQuery) => unknown;
|
||||
|
||||
// @public
|
||||
export interface SearchEngine {
|
||||
getIndexer(type: string): Promise<Writable>;
|
||||
query(
|
||||
query: SearchQuery,
|
||||
options?: QueryRequestOptions,
|
||||
): Promise<IndexableResultSet>;
|
||||
setTranslator(translator: QueryTranslator): void;
|
||||
}
|
||||
|
||||
// @alpha
|
||||
export interface SearchEngineRegistryExtensionPoint {
|
||||
|
||||
@@ -30,14 +30,10 @@ import {
|
||||
RegisterDecoratorParameters,
|
||||
} from '@backstage/plugin-search-backend-node';
|
||||
|
||||
import { SearchEngine } from './types';
|
||||
import { IndexBuilder } from './IndexBuilder';
|
||||
|
||||
export type {
|
||||
import {
|
||||
SearchEngine,
|
||||
QueryRequestOptions,
|
||||
QueryTranslator,
|
||||
} from './types';
|
||||
IndexBuilder,
|
||||
} from '@backstage/plugin-search-backend-node';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
|
||||
@@ -21,7 +21,7 @@ export function createRouter(options: RouterOptions): Promise<express.Router>;
|
||||
export type RouterOptions = {
|
||||
engine: SearchEngine;
|
||||
types: Record<string, DocumentTypeInfo>;
|
||||
discovery: DiscoveryService;
|
||||
discovery?: DiscoveryService;
|
||||
permissions: PermissionEvaluator | PermissionAuthorizer;
|
||||
config: Config;
|
||||
logger: Logger;
|
||||
|
||||
@@ -18,6 +18,7 @@ import express from 'express';
|
||||
import { Logger } from 'winston';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
HostDiscovery,
|
||||
createLegacyAuthAdapters,
|
||||
errorHandler,
|
||||
} from '@backstage/backend-common';
|
||||
@@ -64,7 +65,7 @@ const jsonObjectSchema: z.ZodSchema<JsonObject> = z.lazy(() => {
|
||||
export type RouterOptions = {
|
||||
engine: SearchEngine;
|
||||
types: Record<string, DocumentTypeInfo>;
|
||||
discovery: DiscoveryService;
|
||||
discovery?: DiscoveryService;
|
||||
permissions: PermissionEvaluator | PermissionAuthorizer;
|
||||
config: Config;
|
||||
logger: Logger;
|
||||
@@ -83,9 +84,19 @@ export async function createRouter(
|
||||
options: RouterOptions,
|
||||
): Promise<express.Router> {
|
||||
const router = await createOpenApiRouter();
|
||||
const { engine: inputEngine, types, permissions, config, logger } = options;
|
||||
const {
|
||||
engine: inputEngine,
|
||||
types,
|
||||
permissions,
|
||||
config,
|
||||
logger,
|
||||
discovery = HostDiscovery.fromConfig(config),
|
||||
} = options;
|
||||
|
||||
const { auth, httpAuth } = createLegacyAuthAdapters(options);
|
||||
const { auth, httpAuth } = createLegacyAuthAdapters({
|
||||
...options,
|
||||
discovery,
|
||||
});
|
||||
|
||||
const maxPageLimit =
|
||||
config.getOptionalNumber('search.maxPageLimit') ?? defaultMaxPageLimit;
|
||||
|
||||
Reference in New Issue
Block a user