chore: Move catalogPlugin to catalog-backend
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
committed by
Patrik Oldsberg
parent
0d71831aae
commit
699881cdd9
@@ -14,94 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createBackend } from '@backstage/backend-app-api';
|
||||
import { createBackendModule } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
createBackend,
|
||||
loggerToWinstonLogger,
|
||||
} from '@backstage/backend-app-api';
|
||||
import {
|
||||
configServiceRef,
|
||||
createBackendModule,
|
||||
createBackendPlugin,
|
||||
createServiceRef,
|
||||
databaseServiceRef,
|
||||
loggerServiceRef,
|
||||
permissionsServiceRef,
|
||||
urlReaderServiceRef,
|
||||
httpRouterServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
CatalogBuilder,
|
||||
CatalogProcessor,
|
||||
catalogPlugin,
|
||||
catalogProcessingInitApiRef,
|
||||
} from '@backstage/plugin-catalog-backend';
|
||||
import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend';
|
||||
|
||||
interface CatalogProcessingInitApi {
|
||||
addProcessor(processor: CatalogProcessor): void;
|
||||
}
|
||||
|
||||
export const catalogProcessingInitApiRef =
|
||||
createServiceRef<CatalogProcessingInitApi>({
|
||||
id: 'catalog.processing',
|
||||
});
|
||||
|
||||
class CatalogExtensionPointImpl implements CatalogProcessingInitApi {
|
||||
#processors = new Array<CatalogProcessor>();
|
||||
|
||||
addProcessor(processor: CatalogProcessor): void {
|
||||
this.#processors.push(processor);
|
||||
}
|
||||
|
||||
get processors() {
|
||||
return this.#processors;
|
||||
}
|
||||
}
|
||||
|
||||
export const catalogPlugin = createBackendPlugin({
|
||||
id: 'catalog',
|
||||
register(env) {
|
||||
const processingExtensions = new CatalogExtensionPointImpl();
|
||||
// plugins depending on this API will be initialized before this plugins init method is executed.
|
||||
env.registerExtensionPoint(
|
||||
catalogProcessingInitApiRef,
|
||||
processingExtensions,
|
||||
);
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
logger: loggerServiceRef,
|
||||
config: configServiceRef,
|
||||
reader: urlReaderServiceRef,
|
||||
permissions: permissionsServiceRef,
|
||||
database: databaseServiceRef,
|
||||
httpRouter: httpRouterServiceRef,
|
||||
},
|
||||
async init({
|
||||
logger,
|
||||
config,
|
||||
reader,
|
||||
database,
|
||||
permissions,
|
||||
httpRouter,
|
||||
}) {
|
||||
const winstonLogger = loggerToWinstonLogger(logger);
|
||||
const builder = await CatalogBuilder.create({
|
||||
config,
|
||||
reader,
|
||||
permissions,
|
||||
database,
|
||||
logger: winstonLogger,
|
||||
});
|
||||
builder.addProcessor(...processingExtensions.processors);
|
||||
const { processingEngine, router } = await builder.build();
|
||||
|
||||
await processingEngine.start();
|
||||
|
||||
httpRouter.use(router);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const scaffolderCatalogExtension = createBackendModule({
|
||||
moduleId: 'scaffolder.extention',
|
||||
pluginId: 'catalog',
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
```ts
|
||||
/// <reference types="node" />
|
||||
|
||||
import { BackendRegistrable } from '@backstage/backend-plugin-api';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { CatalogEntityDocument } from '@backstage/plugin-catalog-common';
|
||||
import { CatalogProcessor } from '@backstage/plugin-catalog-node';
|
||||
@@ -46,6 +47,7 @@ import { Readable } from 'stream';
|
||||
import { ResourcePermission } from '@backstage/plugin-permission-common';
|
||||
import { Router } from 'express';
|
||||
import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
import { TokenManager } from '@backstage/backend-common';
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
import { Validators } from '@backstage/catalog-model';
|
||||
@@ -215,6 +217,9 @@ export type CatalogEnvironment = {
|
||||
export type CatalogPermissionRule<TParams extends unknown[] = unknown[]> =
|
||||
PermissionRule<Entity, EntitiesSearchFilter, 'catalog-entity', TParams>;
|
||||
|
||||
// @alpha
|
||||
export const catalogPlugin: (option: unknown) => BackendRegistrable;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CatalogProcessingEngine {
|
||||
// (undocumented)
|
||||
@@ -223,6 +228,15 @@ export interface CatalogProcessingEngine {
|
||||
stop(): Promise<void>;
|
||||
}
|
||||
|
||||
// @alpha (undocumented)
|
||||
export interface CatalogProcessingInitApi {
|
||||
// (undocumented)
|
||||
addProcessor(processor: CatalogProcessor): void;
|
||||
}
|
||||
|
||||
// @alpha (undocumented)
|
||||
export const catalogProcessingInitApiRef: ServiceRef<CatalogProcessingInitApi>;
|
||||
|
||||
export { CatalogProcessor };
|
||||
|
||||
export { CatalogProcessorCache };
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
"clean": "backstage-cli package clean"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-app-api": "^0.0.0",
|
||||
"@backstage/backend-plugin-api": "^0.0.0",
|
||||
"@backstage/plugin-catalog-node": "^0.0.0",
|
||||
"@backstage/backend-common": "^0.14.1-next.2",
|
||||
"@backstage/catalog-client": "^1.0.4-next.1",
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2022 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 { loggerToWinstonLogger } from '@backstage/backend-app-api';
|
||||
import {
|
||||
configServiceRef,
|
||||
createBackendPlugin,
|
||||
createServiceRef,
|
||||
databaseServiceRef,
|
||||
loggerServiceRef,
|
||||
permissionsServiceRef,
|
||||
urlReaderServiceRef,
|
||||
httpRouterServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { CatalogProcessor } from '../api/processor';
|
||||
import { CatalogBuilder } from './CatalogBuilder';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export interface CatalogProcessingInitApi {
|
||||
addProcessor(processor: CatalogProcessor): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export const catalogProcessingInitApiRef =
|
||||
createServiceRef<CatalogProcessingInitApi>({
|
||||
id: 'catalog.processing',
|
||||
});
|
||||
|
||||
class CatalogExtensionPointImpl implements CatalogProcessingInitApi {
|
||||
#processors = new Array<CatalogProcessor>();
|
||||
|
||||
addProcessor(processor: CatalogProcessor): void {
|
||||
this.#processors.push(processor);
|
||||
}
|
||||
|
||||
get processors() {
|
||||
return this.#processors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Catalog plugin
|
||||
* @alpha
|
||||
*/
|
||||
export const catalogPlugin = createBackendPlugin({
|
||||
id: 'catalog',
|
||||
register(env) {
|
||||
const processingExtensions = new CatalogExtensionPointImpl();
|
||||
// plugins depending on this API will be initialized before this plugins init method is executed.
|
||||
env.registerExtensionPoint(
|
||||
catalogProcessingInitApiRef,
|
||||
processingExtensions,
|
||||
);
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
logger: loggerServiceRef,
|
||||
config: configServiceRef,
|
||||
reader: urlReaderServiceRef,
|
||||
permissions: permissionsServiceRef,
|
||||
database: databaseServiceRef,
|
||||
httpRouter: httpRouterServiceRef,
|
||||
},
|
||||
async init({
|
||||
logger,
|
||||
config,
|
||||
reader,
|
||||
database,
|
||||
permissions,
|
||||
httpRouter,
|
||||
}) {
|
||||
const winstonLogger = loggerToWinstonLogger(logger);
|
||||
const builder = await CatalogBuilder.create({
|
||||
config,
|
||||
reader,
|
||||
permissions,
|
||||
database,
|
||||
logger: winstonLogger,
|
||||
});
|
||||
builder.addProcessor(...processingExtensions.processors);
|
||||
const { processingEngine, router } = await builder.build();
|
||||
|
||||
await processingEngine.start();
|
||||
|
||||
httpRouter.use(router);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -16,3 +16,6 @@
|
||||
|
||||
export type { CatalogEnvironment } from './CatalogBuilder';
|
||||
export { CatalogBuilder } from './CatalogBuilder';
|
||||
|
||||
export type { CatalogProcessingInitApi } from './CatalogPlugin';
|
||||
export { catalogPlugin, catalogProcessingInitApiRef } from './CatalogPlugin';
|
||||
|
||||
Reference in New Issue
Block a user