Merge pull request #13197 from backstage/mob/services

backend-system: add default service factories
This commit is contained in:
Patrik Oldsberg
2022-08-22 13:36:31 +02:00
committed by GitHub
25 changed files with 407 additions and 123 deletions
@@ -3,6 +3,7 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { CatalogProcessor } from '@backstage/plugin-catalog-backend';
import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend';
import { Config } from '@backstage/config';
@@ -14,6 +15,7 @@ import { LocationSpec } from '@backstage/plugin-catalog-backend';
import { Logger } from 'winston';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { TaskRunner } from '@backstage/backend-tasks';
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
// @public
export class GithubDiscoveryProcessor implements CatalogProcessor {
@@ -58,6 +60,16 @@ export class GitHubEntityProvider implements EntityProvider {
refresh(logger: Logger): Promise<void>;
}
// @alpha
export const githubEntityProviderCatalogModule: (
options?: GithubEntityProviderCatalogModuleOptions | undefined,
) => BackendFeature;
// @alpha
export type GithubEntityProviderCatalogModuleOptions = {
schedule?: TaskScheduleDefinition;
};
// @public
export type GithubMultiOrgConfig = Array<{
name: string;
@@ -9,7 +9,8 @@
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
"types": "dist/index.d.ts",
"alphaTypes": "dist/index.alpha.d.ts"
},
"backstage": {
"role": "backend-plugin-module"
@@ -24,7 +25,7 @@
"backstage"
],
"scripts": {
"build": "backstage-cli package build",
"build": "backstage-cli package build --experimental-type-build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"prepack": "backstage-cli package prepack",
@@ -35,11 +36,13 @@
"dependencies": {
"@backstage/backend-common": "^0.15.0",
"@backstage/backend-tasks": "^0.3.4",
"@backstage/backend-plugin-api": "^0.1.1",
"@backstage/catalog-model": "^1.1.0",
"@backstage/config": "^1.0.1",
"@backstage/errors": "^1.1.0",
"@backstage/integration": "^1.3.0",
"@backstage/plugin-catalog-backend": "^1.3.1",
"@backstage/plugin-catalog-node": "^1.0.1",
"@backstage/types": "^1.0.0",
"@octokit/graphql": "^5.0.0",
"lodash": "^4.17.21",
@@ -55,6 +58,7 @@
},
"files": [
"dist",
"alpha",
"config.d.ts"
],
"configSchema": "config.d.ts"
@@ -27,3 +27,5 @@ export { GitHubEntityProvider } from './providers/GitHubEntityProvider';
export { GitHubOrgEntityProvider } from './providers/GitHubOrgEntityProvider';
export type { GitHubOrgEntityProviderOptions } from './providers/GitHubOrgEntityProvider';
export type { GithubMultiOrgConfig } from './lib';
export { githubEntityProviderCatalogModule } from './module';
export type { GithubEntityProviderCatalogModuleOptions } from './module';
@@ -0,0 +1,69 @@
/*
* 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 {
createBackendModule,
loggerToWinstonLogger,
configServiceRef,
loggerServiceRef,
schedulerServiceRef,
} from '@backstage/backend-plugin-api';
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';
import { GitHubEntityProvider } from './providers/GitHubEntityProvider';
/**
* Options for {@link githubEntityProviderCatalogModule}.
*
* @alpha
*/
export type GithubEntityProviderCatalogModuleOptions = {
schedule?: TaskScheduleDefinition;
};
/**
* Registers the GitHubEntityProvider with the catalog processing extension point.
*
* @alpha
*/
export const githubEntityProviderCatalogModule = createBackendModule({
pluginId: 'catalog',
moduleId: 'github-entity-provider',
register(env, options?: GithubEntityProviderCatalogModuleOptions) {
env.registerInit({
deps: {
config: configServiceRef,
catalog: catalogProcessingExtensionPoint,
logger: loggerServiceRef,
scheduler: schedulerServiceRef,
},
async init({ config, catalog, logger, scheduler }) {
const scheduleDef = options?.schedule ?? {
frequency: { seconds: 600 },
timeout: { seconds: 900 },
initialDelay: { seconds: 3 },
};
catalog.addEntityProvider(
GitHubEntityProvider.fromConfig(config, {
logger: loggerToWinstonLogger(logger),
schedule: scheduler.createScheduledTaskRunner(scheduleDef),
}),
);
},
});
},
});
@@ -35,12 +35,16 @@ class CatalogExtensionPointImpl implements CatalogProcessingExtensionPoint {
#processors = new Array<CatalogProcessor>();
#entityProviders = new Array<EntityProvider>();
addProcessor(processor: CatalogProcessor): void {
this.#processors.push(processor);
addProcessor(
...processors: Array<CatalogProcessor | Array<CatalogProcessor>>
): void {
this.#processors.push(...processors.flat());
}
addEntityProvider(provider: EntityProvider): void {
this.#entityProviders.push(provider);
addEntityProvider(
...providers: Array<EntityProvider | Array<EntityProvider>>
): void {
this.#entityProviders.push(...providers.flat());
}
get processors() {
+6 -2
View File
@@ -13,9 +13,13 @@ import { JsonValue } from '@backstage/types';
// @alpha (undocumented)
export interface CatalogProcessingExtensionPoint {
// (undocumented)
addEntityProvider(provider: EntityProvider): void;
addEntityProvider(
...providers: Array<EntityProvider | Array<EntityProvider>>
): void;
// (undocumented)
addProcessor(processor: CatalogProcessor): void;
addProcessor(
...processors: Array<CatalogProcessor | Array<CatalogProcessor>>
): void;
}
// @alpha (undocumented)
+6 -2
View File
@@ -21,8 +21,12 @@ import { CatalogProcessor } from './api/processor';
* @alpha
*/
export interface CatalogProcessingExtensionPoint {
addProcessor(processor: CatalogProcessor): void;
addEntityProvider(provider: EntityProvider): void;
addProcessor(
...processors: Array<CatalogProcessor | Array<CatalogProcessor>>
): void;
addEntityProvider(
...providers: Array<EntityProvider | Array<EntityProvider>>
): void;
}
/**