refactor(search-backend): use credential for authorized search engines
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -19,11 +19,10 @@ import { TaskInvocationDefinition, TaskRunner } from '@backstage/backend-tasks';
|
||||
import {
|
||||
DocumentCollatorFactory,
|
||||
DocumentDecoratorFactory,
|
||||
SearchEngine,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { Readable, Transform } from 'stream';
|
||||
import { IndexBuilder } from './IndexBuilder';
|
||||
import { LunrSearchEngine } from './index';
|
||||
import { LunrSearchEngine, SearchEngine } from './index';
|
||||
|
||||
class TestDocumentCollatorFactory implements DocumentCollatorFactory {
|
||||
readonly type: string = 'anything';
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
import {
|
||||
DocumentDecoratorFactory,
|
||||
DocumentTypeInfo,
|
||||
SearchEngine,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { Transform, pipeline } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
import { Scheduler } from './Scheduler';
|
||||
import {
|
||||
SearchEngine,
|
||||
IndexBuilderOptions,
|
||||
RegisterCollatorParameters,
|
||||
RegisterDecoratorParameters,
|
||||
|
||||
@@ -22,10 +22,7 @@ import {
|
||||
coreServices,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
DocumentTypeInfo,
|
||||
SearchEngine,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { DocumentTypeInfo } from '@backstage/plugin-search-common';
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
|
||||
import {
|
||||
@@ -33,8 +30,15 @@ import {
|
||||
RegisterDecoratorParameters,
|
||||
} from '@backstage/plugin-search-backend-node';
|
||||
|
||||
import { SearchEngine } from './types';
|
||||
import { IndexBuilder } from './IndexBuilder';
|
||||
|
||||
export type {
|
||||
SearchEngine,
|
||||
QueryRequestOptions,
|
||||
QueryTranslator,
|
||||
} from './types';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
* Options for build method on {@link SearchIndexService}.
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import lunr from 'lunr';
|
||||
import {
|
||||
IndexableDocument,
|
||||
SearchEngine,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import {
|
||||
ConcreteLunrQuery,
|
||||
LunrSearchEngine,
|
||||
@@ -28,6 +25,7 @@ import {
|
||||
parseHighlightFields,
|
||||
} from './LunrSearchEngine';
|
||||
import { LunrSearchEngineIndexer } from './LunrSearchEngineIndexer';
|
||||
import { SearchEngine } from '../types';
|
||||
import { TestPipeline } from '../test-utils';
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,9 +18,8 @@ import {
|
||||
IndexableDocument,
|
||||
IndexableResultSet,
|
||||
SearchQuery,
|
||||
QueryTranslator,
|
||||
SearchEngine,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { SearchEngine, QueryTranslator } from '../types';
|
||||
import { MissingIndexError } from '../errors';
|
||||
import lunr from 'lunr';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
@@ -33,6 +33,9 @@ export type {
|
||||
IndexBuilderOptions,
|
||||
RegisterCollatorParameters,
|
||||
RegisterDecoratorParameters,
|
||||
SearchEngine,
|
||||
QueryRequestOptions,
|
||||
QueryTranslator,
|
||||
} from './types';
|
||||
export * from './errors';
|
||||
export * from './indexing';
|
||||
|
||||
@@ -14,12 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BackstageCredentials } from '@backstage/backend-plugin-api';
|
||||
import { TaskRunner } from '@backstage/backend-tasks';
|
||||
import {
|
||||
DocumentCollatorFactory,
|
||||
DocumentDecoratorFactory,
|
||||
SearchEngine,
|
||||
IndexableResultSet,
|
||||
SearchQuery,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { Writable } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
/**
|
||||
@@ -57,3 +60,55 @@ export interface RegisterDecoratorParameters {
|
||||
*/
|
||||
factory: DocumentDecoratorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* A type of function responsible for translating an abstract search query into
|
||||
* a concrete query relevant to a particular search engine.
|
||||
* @public
|
||||
*/
|
||||
export type QueryTranslator = (query: SearchQuery) => unknown;
|
||||
|
||||
/**
|
||||
* Options when querying a search engine.
|
||||
* @public
|
||||
*/
|
||||
export type QueryRequestOptions =
|
||||
| {
|
||||
/** @deprecated use the `credentials` option instead. */
|
||||
token?: string;
|
||||
}
|
||||
| {
|
||||
credentials: BackstageCredentials;
|
||||
};
|
||||
|
||||
/**
|
||||
* Interface that must be implemented by specific search engines, responsible
|
||||
* for performing indexing and querying and translating abstract queries into
|
||||
* concrete, search engine-specific queries.
|
||||
* @public
|
||||
*/
|
||||
export interface SearchEngine {
|
||||
/**
|
||||
* Override the default translator provided by the SearchEngine.
|
||||
*/
|
||||
setTranslator(translator: QueryTranslator): void;
|
||||
|
||||
/**
|
||||
* Factory method for getting a search engine indexer for a given document
|
||||
* type.
|
||||
*
|
||||
* @param type - The type or name of the document set for which an indexer
|
||||
* should be retrieved. This corresponds to the `type` property on the
|
||||
* document collator/decorator factories and will most often be used to
|
||||
* identify an index or group to which documents should be written.
|
||||
*/
|
||||
getIndexer(type: string): Promise<Writable>;
|
||||
|
||||
/**
|
||||
* Perform a search query against the SearchEngine.
|
||||
*/
|
||||
query(
|
||||
query: SearchQuery,
|
||||
options?: QueryRequestOptions,
|
||||
): Promise<IndexableResultSet>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user