Merge pull request #29647 from backstage/rugvip/rmlegacy

packages: remove backend-legacy package
This commit is contained in:
Patrik Oldsberg
2025-04-17 09:55:03 +02:00
committed by GitHub
22 changed files with 12 additions and 9810 deletions
+5 -9
View File
@@ -141,15 +141,7 @@ from `@backstage/core-plugin-api`.
## Accessing ConfigApi in Backend Plugins
### Old Backend System
In the old backend system plugins, the configuration is passed in via options from the main
backend package. See for example
[packages/backend-legacy/src/plugins/auth.ts](https://github.com/backstage/backstage/blob/244eef851f5aa19f91c7c9b5c12d5df95cf482ca/packages/backend/src/plugins/auth.ts#L23).
### New Backend System
In the new backend system, plugins are able to directly access config through dependencies. You can access config like so,
In the backend system, plugins are able to directly access config through dependencies. You can access config like so,
```ts title="plugins/your-plugin-backend/src/plugin.ts"
export const yourPlugin = createBackendPlugin({
@@ -175,3 +167,7 @@ export const yourPlugin = createBackendPlugin({
},
});
```
### Old Backend System
In the old backend system plugins, the configuration is passed in via options from the main backend package.
@@ -53,9 +53,7 @@ Some defining traits of entity providers:
### Creating an Entity Provider
The recommended way of instantiating the catalog backend classes is to use the
`CatalogBuilder`, as illustrated in the
[example backend here](https://github.com/backstage/backstage/blob/master/packages/backend-legacy/src/plugins/catalog.ts).
The recommended way of instantiating the catalog backend classes is to use the `CatalogBuilder`.
We will create a new
[`EntityProvider`](https://github.com/backstage/backstage/blob/master/plugins/catalog-node/src/api/provider.ts)
subclass that can be added to this catalog builder.
@@ -637,9 +635,7 @@ does so!
### Creating a Catalog Data Reader Processor
The recommended way of instantiating the catalog backend classes is to use the
`CatalogBuilder`, as illustrated in the
[example backend here](https://github.com/backstage/backstage/blob/master/packages/backend-legacy/src/plugins/catalog.ts).
The recommended way of instantiating the catalog backend classes is to use the `CatalogBuilder`.
We will create a new
[`CatalogProcessor`](https://github.com/backstage/backstage/blob/master/plugins/catalog-node/src/api/processor.ts)
subclass that can be added to this catalog builder.
-1
View File
@@ -52,7 +52,6 @@
"snyk:test:package": "yarn snyk:test --include",
"start": "backstage-cli repo start",
"start-backend": "echo \"Use 'yarn start example-backend' instead\"",
"start-backend:legacy": "echo \"Use 'yarn start example-backend-legacy' instead\"",
"start:microsite": "cd microsite/ && yarn start",
"start:next": "yarn start example-app-next example-backend",
"storybook": "yarn ./storybook run storybook",
-1
View File
@@ -1 +0,0 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
-10
View File
@@ -1,10 +0,0 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.22.1
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JS-ISOLATEDVM-3037320:
- '*':
reason: We do not pass any V8 cache data, and are therefore unaffected by this vulnerability
expires: 2033-07-02T16:55:57.077Z
created: 2023-07-02T16:55:57.077Z
patch: {}
File diff suppressed because it is too large Load Diff
-61
View File
@@ -1,61 +0,0 @@
# example-backend-legacy
This package is an EXAMPLE of a Backstage backend using the old backend system.
The main purpose of this package is to provide a test bed for Backstage plugins
that have a backend part. Feel free to experiment locally or within your fork
by adding dependencies and routes to this backend, to try things out.
By running the `@backstage/create-app` script, you get your own separate Backstage backend.
## Development
To run the example backend, first go to the project root and run
```bash
yarn install
```
You should only need to do this once.
After that, go to the `packages/backend-legacy` directory and run
```bash
yarn start
```
If you want to override any configuration locally, for example adding any secrets,
you can do so in `app-config.local.yaml`.
The backend starts up on port 7007 per default.
### Debugging
The backend is a node process that can be inspected to allow breakpoints and live debugging. To enable this, pass the `--inspect` flag to [backend:dev](https://backstage.io/docs/tooling/cli/build-system#backend-development).
To debug the backend in [Visual Studio Code](https://code.visualstudio.com/):
- Enable Auto Attach (⌘ + Shift + P > Toggle Auto Attach > Only With Flag)
- Open a VSCode terminal (Control + `)
- Run the backend from the VSCode terminal: `yarn start-backend:legacy --inspect`
## Populating The Catalog
If you want to use the catalog functionality, you need to add so called
locations to the backend. These are places where the backend can find some
entity descriptor data to consume and serve. For more information, see
[Software Catalog Overview - Adding Components to the Catalog](https://backstage.io/docs/features/software-catalog/#adding-components-to-the-catalog).
For convenience we already include some statically configured example locations
in `app-config.yaml` under `catalog.locations`. For local development you can override these in your own `app-config.local.yaml`.
## Authentication
We chose [Passport](http://www.passportjs.org/) as authentication platform due to its comprehensive set of supported authentication [strategies](http://www.passportjs.org/packages/).
Read more about the [auth-backend](https://github.com/backstage/backstage/blob/master/plugins/auth-backend/README.md) and [how to add a new provider](https://github.com/backstage/backstage/blob/master/docs/auth/add-auth-provider.md)
## Documentation
- [Backstage Readme](https://github.com/backstage/backstage/blob/master/README.md)
- [Backstage Documentation](https://backstage.io/docs)
@@ -1,9 +0,0 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: example-backend-legacy
title: example-backend-legacy
spec:
lifecycle: experimental
type: backstage-backend
owner: maintainers
-27
View File
@@ -1,27 +0,0 @@
# Knip report
## Unused dependencies (12)
| Name | Location | Severity |
| :------------------------------------------------- | :----------- | :------- |
| @backstage/plugin-scaffolder-backend-module-gitlab | package.json | error |
| @backstage/plugin-scaffolder-backend-module-rails | package.json | error |
| @backstage/plugin-search-backend-module-catalog | package.json | error |
| @backstage/plugin-signals-backend | package.json | error |
| azure-devops-node-api | package.json | error |
| @gitbeaker/node | package.json | error |
| better-sqlite3 | package.json | error |
| @octokit/rest | package.json | error |
| dockerode | package.json | error |
| mysql2 | package.json | error |
| luxon | package.json | error |
| pg | package.json | error |
## Unused devDependencies (3)
| Name | Location | Severity |
| :------------------------------- | :----------- | :------- |
| @types/express-serve-static-core | package.json | error |
| @types/dockerode | package.json | error |
| @types/luxon | package.json | error |
-84
View File
@@ -1,84 +0,0 @@
{
"name": "example-backend-legacy",
"version": "0.2.109",
"backstage": {
"role": "backend"
},
"private": true,
"keywords": [
"backstage"
],
"homepage": "https://backstage.io",
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "packages/backend-legacy"
},
"license": "Apache-2.0",
"main": "dist/index.cjs.js",
"types": "src/index.ts",
"files": [
"dist"
],
"scripts": {
"build": "backstage-cli package build",
"clean": "backstage-cli package clean",
"lint": "backstage-cli package lint",
"start": "backstage-cli package start",
"test": "backstage-cli package test"
},
"dependencies": {
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-defaults": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/catalog-client": "workspace:^",
"@backstage/catalog-model": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/integration": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-catalog-backend": "workspace:^",
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "workspace:^",
"@backstage/plugin-catalog-node": "workspace:^",
"@backstage/plugin-events-backend": "workspace:^",
"@backstage/plugin-events-node": "workspace:^",
"@backstage/plugin-kubernetes-backend": "workspace:^",
"@backstage/plugin-permission-backend": "workspace:^",
"@backstage/plugin-permission-common": "workspace:^",
"@backstage/plugin-permission-node": "workspace:^",
"@backstage/plugin-scaffolder-backend": "workspace:^",
"@backstage/plugin-scaffolder-backend-module-confluence-to-markdown": "workspace:^",
"@backstage/plugin-scaffolder-backend-module-gitlab": "workspace:^",
"@backstage/plugin-scaffolder-backend-module-rails": "workspace:^",
"@backstage/plugin-search-backend": "workspace:^",
"@backstage/plugin-search-backend-module-catalog": "workspace:^",
"@backstage/plugin-search-backend-module-elasticsearch": "workspace:^",
"@backstage/plugin-search-backend-module-explore": "workspace:^",
"@backstage/plugin-search-backend-module-pg": "workspace:^",
"@backstage/plugin-search-backend-module-techdocs": "workspace:^",
"@backstage/plugin-search-backend-node": "workspace:^",
"@backstage/plugin-signals-backend": "workspace:^",
"@backstage/plugin-signals-node": "workspace:^",
"@backstage/plugin-techdocs-backend": "workspace:^",
"@gitbeaker/node": "^35.1.0",
"@octokit/rest": "^19.0.3",
"azure-devops-node-api": "^14.0.0",
"better-sqlite3": "^11.0.0",
"dockerode": "^4.0.0",
"express": "^4.17.1",
"express-prom-bundle": "^7.0.0",
"express-promise-router": "^4.1.0",
"luxon": "^3.0.0",
"mysql2": "^3.0.0",
"pg": "^8.11.3",
"pg-connection-string": "^2.3.0",
"prom-client": "^15.0.0",
"winston": "^3.2.1"
},
"devDependencies": {
"@backstage/cli": "workspace:^",
"@types/dockerode": "^3.3.0",
"@types/express": "^4.17.6",
"@types/express-serve-static-core": "^4.17.5",
"@types/luxon": "^3.0.0"
}
}
-24
View File
@@ -1,24 +0,0 @@
/*
* Copyright 2020 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 { PluginEnvironment } from './types';
describe('test', () => {
it('unbreaks the test runner', () => {
const unbreaker = {} as PluginEnvironment;
expect(unbreaker).toBeTruthy();
});
});
-155
View File
@@ -1,155 +0,0 @@
/*
* 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.
*/
/*
* Hi!
*
* Note that this is an EXAMPLE Backstage backend. Please check the README.
*
* Happy hacking!
*/
import Router from 'express-promise-router';
import {
CacheManager,
createLegacyAuthAdapters,
createServiceBuilder,
DatabaseManager,
getRootLogger,
HostDiscovery,
loadBackendConfig,
notFoundHandler,
ServerTokenManager,
useHotMemoize,
} from '@backstage/backend-common';
import { Config } from '@backstage/config';
import healthcheck from './plugins/healthcheck';
import { metricsHandler, metricsInit } from './metrics';
import catalog from './plugins/catalog';
import events from './plugins/events';
import kubernetes from './plugins/kubernetes';
import scaffolder from './plugins/scaffolder';
import permission from './plugins/permission';
import { PluginEnvironment } from './types';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
import { DefaultEventsService } from '@backstage/plugin-events-node';
import { DefaultSignalsService } from '@backstage/plugin-signals-node';
import { UrlReaders } from '@backstage/backend-defaults/urlReader';
import { DefaultSchedulerService } from '@backstage/backend-defaults/scheduler';
function makeCreateEnv(config: Config) {
const root = getRootLogger();
const reader = UrlReaders.default({ logger: root, config });
const discovery = HostDiscovery.fromConfig(config);
const tokenManager = ServerTokenManager.fromConfig(config, { logger: root });
const { auth } = createLegacyAuthAdapters({
auth: undefined,
discovery,
tokenManager,
});
const permissions = ServerPermissionClient.fromConfig(config, {
discovery,
auth,
});
const databaseManager = DatabaseManager.fromConfig(config, { logger: root });
const cacheManager = CacheManager.fromConfig(config);
const identity = DefaultIdentityClient.create({
discovery,
});
const eventsService = DefaultEventsService.create({ logger: root, config });
const signalsService = DefaultSignalsService.create({
events: eventsService,
});
root.info(`Created UrlReader ${reader}`);
return (plugin: string): PluginEnvironment => {
const logger = root.child({ type: 'plugin', plugin });
const database = databaseManager.forPlugin(plugin);
const cache = cacheManager.forPlugin(plugin);
const scheduler = DefaultSchedulerService.create({
logger,
database,
});
return {
logger,
cache,
database,
config,
reader,
events: eventsService,
discovery,
tokenManager,
permissions,
scheduler,
identity,
signals: signalsService,
};
};
}
async function main() {
metricsInit();
const logger = getRootLogger();
logger.info(
`You are running an example backend, which is supposed to be mainly used for contributing back to Backstage. ` +
`Do NOT deploy this to production. Read more here https://backstage.io/docs/getting-started/`,
);
const config = await loadBackendConfig({
argv: process.argv,
logger,
});
const createEnv = makeCreateEnv(config);
const healthcheckEnv = useHotMemoize(module, () => createEnv('healthcheck'));
const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
const scaffolderEnv = useHotMemoize(module, () => createEnv('scaffolder'));
const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes'));
const permissionEnv = useHotMemoize(module, () => createEnv('permission'));
const eventsEnv = useHotMemoize(module, () => createEnv('events'));
const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
apiRouter.use('/events', await events(eventsEnv));
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv));
apiRouter.use('/permission', await permission(permissionEnv));
apiRouter.use(notFoundHandler());
const service = createServiceBuilder(module)
.loadConfig(config)
.addRouter('', await healthcheck(healthcheckEnv))
.addRouter('', metricsHandler())
.addRouter('/api', apiRouter);
await service.start().catch(err => {
logger.error(err);
process.exit(1);
});
}
module.hot?.accept();
main().catch(error => {
console.error('Backend failed to start up', error);
process.exit(1);
});
-63
View File
@@ -1,63 +0,0 @@
/*
* Copyright 2021 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 { useHotCleanup } from '@backstage/backend-common';
import { RequestHandler, Request } from 'express';
import promBundle from 'express-prom-bundle';
import prom from 'prom-client';
import * as url from 'url';
/**
* Experimental Prometheus metrics used to benchmark the performance of the
* software catalog. Use this at your own risk.
*/
const rootRegEx = new RegExp('^/([^/]*)/.*');
const apiRegEx = new RegExp('^/api/([^/]*)/.*');
function normalizePath(req: Request): string {
const path = url.parse(req.originalUrl || req.url).pathname || '/';
// Capture /api/ and the plugin name
if (apiRegEx.test(path)) {
return path.replace(apiRegEx, '/api/$1');
}
// Only the first path segment at root level
return path.replace(rootRegEx, '/$1');
}
export function metricsInit(): void {
prom.collectDefaultMetrics({ prefix: 'backstage_' });
}
/**
* Adds a /metrics endpoint, register default runtime metrics and instrument the router.
*/
export function metricsHandler(): RequestHandler {
// We can only initialize the metrics once and have to clean them up between hot reloads
useHotCleanup(module, () => prom.register.clear());
return promBundle({
includeMethod: true,
includePath: true,
// Using includePath alone is problematic, as it will include path labels with high
// cardinality (e.g. path params). Instead we would have to template them. However, this
// is difficult, as every backend plugin might use different routes. Instead we only take
// the first directory of the path, to have at least an idea how each plugin performs:
normalizePath,
promClient: { collectDefaultMetrics: {} },
});
}
@@ -1,60 +0,0 @@
/*
* Copyright 2020 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 {
EntityProvider,
EntityProviderConnection,
} from '@backstage/plugin-catalog-node';
import { EventParams, EventsService } from '@backstage/plugin-events-node';
import { Logger } from 'winston';
export class DemoEventBasedEntityProvider implements EntityProvider {
private readonly logger: Logger;
private readonly events: EventsService;
private readonly topics: string[];
constructor(opts: {
events: EventsService;
logger: Logger;
topics: string[];
}) {
this.events = opts.events;
this.logger = opts.logger;
this.topics = opts.topics;
}
async subscribe() {
await this.events.subscribe({
id: 'DemoEventBasedEntityProvider',
topics: this.topics,
onEvent: async (params: EventParams): Promise<void> => {
this.logger.info(
`onEvent: topic=${params.topic}, metadata=${JSON.stringify(
params.metadata,
)}, payload=${JSON.stringify(params.eventPayload)}`,
);
},
});
}
async connect(_: EntityProviderConnection): Promise<void> {
// not doing anything here
}
getProviderName(): string {
return DemoEventBasedEntityProvider.name;
}
}
@@ -1,41 +0,0 @@
/*
* Copyright 2020 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 { CatalogBuilder } from '@backstage/plugin-catalog-backend';
import { ScaffolderEntitiesProcessor } from '@backstage/plugin-catalog-backend-module-scaffolder-entity-model';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { DemoEventBasedEntityProvider } from './DemoEventBasedEntityProvider';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const builder = CatalogBuilder.create(env);
builder.addProcessor(new ScaffolderEntitiesProcessor());
const demoProvider = new DemoEventBasedEntityProvider({
events: env.events,
logger: env.logger,
topics: ['example'],
});
await demoProvider.subscribe();
builder.addEntityProvider(demoProvider);
const { processingEngine, router } = await builder.build();
await processingEngine.start();
return router;
}
@@ -1,34 +0,0 @@
/*
* 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 { HttpPostIngressEventPublisher } from '@backstage/plugin-events-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const eventsRouter = Router();
const http = HttpPostIngressEventPublisher.fromConfig({
config: env.config,
events: env.events,
logger: env.logger,
});
http.bind(eventsRouter);
return eventsRouter;
}
@@ -1,28 +0,0 @@
/*
* Copyright 2020 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 { createStatusCheckRouter } from '@backstage/backend-common';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
return await createStatusCheckRouter({
logger: env.logger,
path: '/healthcheck',
});
}
@@ -1,34 +0,0 @@
/*
* Copyright 2020 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 { KubernetesBuilder } from '@backstage/plugin-kubernetes-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { CatalogClient } from '@backstage/catalog-client';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const catalogApi = new CatalogClient({ discoveryApi: env.discovery });
const { router } = await KubernetesBuilder.createBuilder({
logger: env.logger,
config: env.config,
catalogApi,
permissions: env.permissions,
discovery: env.discovery,
}).build();
return router;
}
@@ -1,53 +0,0 @@
/*
* Copyright 2021 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 { BackstageIdentityResponse } from '@backstage/plugin-auth-node';
import { createRouter } from '@backstage/plugin-permission-backend';
import {
AuthorizeResult,
PolicyDecision,
} from '@backstage/plugin-permission-common';
import {
PermissionPolicy,
PolicyQuery,
} from '@backstage/plugin-permission-node';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
class ExamplePermissionPolicy implements PermissionPolicy {
async handle(
_request: PolicyQuery,
_user?: BackstageIdentityResponse,
): Promise<PolicyDecision> {
// some logic to determine if the user is allowed to access the resource
return {
result: AuthorizeResult.ALLOW,
};
}
}
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
return await createRouter({
config: env.config,
logger: env.logger,
discovery: env.discovery,
policy: new ExamplePermissionPolicy(),
identity: env.identity,
});
}
@@ -1,63 +0,0 @@
/*
* Copyright 2020 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 { CatalogClient } from '@backstage/catalog-client';
import {
createBuiltinActions,
createRouter,
} from '@backstage/plugin-scaffolder-backend';
import { Router } from 'express';
import type { PluginEnvironment } from '../types';
import { ScmIntegrations } from '@backstage/integration';
import { createConfluenceToMarkdownAction } from '@backstage/plugin-scaffolder-backend-module-confluence-to-markdown';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const catalogClient = new CatalogClient({
discoveryApi: env.discovery,
});
const integrations = ScmIntegrations.fromConfig(env.config);
const builtInActions = createBuiltinActions({
integrations,
config: env.config,
catalogClient,
reader: env.reader,
});
const actions = [
...builtInActions,
createConfluenceToMarkdownAction({
integrations,
config: env.config,
reader: env.reader,
}),
];
return await createRouter({
logger: env.logger,
config: env.config,
database: env.database,
catalogClient: catalogClient,
reader: env.reader,
discovery: env.discovery,
scheduler: env.scheduler,
permissions: env.permissions,
actions,
});
}
-44
View File
@@ -1,44 +0,0 @@
/*
* Copyright 2020 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 { Logger } from 'winston';
import { Config } from '@backstage/config';
import { PluginCacheManager, TokenManager } from '@backstage/backend-common';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { EventsService } from '@backstage/plugin-events-node';
import { SignalsService } from '@backstage/plugin-signals-node';
import {
UrlReaderService,
SchedulerService,
DatabaseService,
DiscoveryService,
} from '@backstage/backend-plugin-api';
export type PluginEnvironment = {
logger: Logger;
cache: PluginCacheManager;
database: DatabaseService;
config: Config;
reader: UrlReaderService;
discovery: DiscoveryService;
tokenManager: TokenManager;
permissions: PermissionEvaluator;
scheduler: SchedulerService;
identity: IdentityApi;
events: EventsService;
signals: SignalsService;
};
+5 -175
View File
@@ -7179,7 +7179,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-scaffolder-backend-module-confluence-to-markdown@workspace:^, @backstage/plugin-scaffolder-backend-module-confluence-to-markdown@workspace:plugins/scaffolder-backend-module-confluence-to-markdown":
"@backstage/plugin-scaffolder-backend-module-confluence-to-markdown@workspace:plugins/scaffolder-backend-module-confluence-to-markdown":
version: 0.0.0-use.local
resolution: "@backstage/plugin-scaffolder-backend-module-confluence-to-markdown@workspace:plugins/scaffolder-backend-module-confluence-to-markdown"
dependencies:
@@ -7335,7 +7335,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-scaffolder-backend-module-rails@workspace:^, @backstage/plugin-scaffolder-backend-module-rails@workspace:plugins/scaffolder-backend-module-rails":
"@backstage/plugin-scaffolder-backend-module-rails@workspace:plugins/scaffolder-backend-module-rails":
version: 0.0.0-use.local
resolution: "@backstage/plugin-scaffolder-backend-module-rails@workspace:plugins/scaffolder-backend-module-rails"
dependencies:
@@ -7695,7 +7695,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-search-backend-module-elasticsearch@workspace:^, @backstage/plugin-search-backend-module-elasticsearch@workspace:plugins/search-backend-module-elasticsearch":
"@backstage/plugin-search-backend-module-elasticsearch@workspace:plugins/search-backend-module-elasticsearch":
version: 0.0.0-use.local
resolution: "@backstage/plugin-search-backend-module-elasticsearch@workspace:plugins/search-backend-module-elasticsearch"
dependencies:
@@ -7732,7 +7732,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-search-backend-module-pg@workspace:^, @backstage/plugin-search-backend-module-pg@workspace:plugins/search-backend-module-pg":
"@backstage/plugin-search-backend-module-pg@workspace:plugins/search-backend-module-pg":
version: 0.0.0-use.local
resolution: "@backstage/plugin-search-backend-module-pg@workspace:plugins/search-backend-module-pg"
dependencies:
@@ -9774,20 +9774,6 @@ __metadata:
languageName: node
linkType: hard
"@gitbeaker/core@npm:^35.8.1":
version: 35.8.1
resolution: "@gitbeaker/core@npm:35.8.1"
dependencies:
"@gitbeaker/requester-utils": "npm:^35.8.1"
form-data: "npm:^4.0.0"
li: "npm:^1.3.0"
mime: "npm:^3.0.0"
query-string: "npm:^7.0.0"
xcase: "npm:^2.0.1"
checksum: 10/5e3eda56f74678ceaec6d494318a0fa9b20d587f307e4d269206cf3ffb6363c8361effd43ef465f7b19f467d7a2caea0e95705a5af88c0bede06bfd897a463f0
languageName: node
linkType: hard
"@gitbeaker/core@npm:^40.6.0":
version: 40.6.0
resolution: "@gitbeaker/core@npm:40.6.0"
@@ -9810,30 +9796,6 @@ __metadata:
languageName: node
linkType: hard
"@gitbeaker/node@npm:^35.1.0":
version: 35.8.1
resolution: "@gitbeaker/node@npm:35.8.1"
dependencies:
"@gitbeaker/core": "npm:^35.8.1"
"@gitbeaker/requester-utils": "npm:^35.8.1"
delay: "npm:^5.0.0"
got: "npm:^11.8.3"
xcase: "npm:^2.0.1"
checksum: 10/1c0acb9e6b352656b3aee91dc4d5673958e8bf0adac152a7c679a21c620b06973ab8276419ee162ea1c127fcb38f60ff3d3cc9fcdcc7bf3bcb9e3b8aa6e3ab78
languageName: node
linkType: hard
"@gitbeaker/requester-utils@npm:^35.8.1":
version: 35.8.1
resolution: "@gitbeaker/requester-utils@npm:35.8.1"
dependencies:
form-data: "npm:^4.0.0"
qs: "npm:^6.10.1"
xcase: "npm:^2.0.1"
checksum: 10/f939216443682303b80b72fa59158cf3fb4a95d31251bb0b4cffa83bd0e0ad0e949645aaaa08fe4dfcd7d06ea5a1547e5688c02b608e8bc76b1e12286935c265
languageName: node
linkType: hard
"@gitbeaker/requester-utils@npm:^40.6.0":
version: 40.6.0
resolution: "@gitbeaker/requester-utils@npm:40.6.0"
@@ -26748,13 +26710,6 @@ __metadata:
languageName: node
linkType: hard
"decode-uri-component@npm:^0.2.0":
version: 0.2.2
resolution: "decode-uri-component@npm:0.2.2"
checksum: 10/17a0e5fa400bf9ea84432226e252aa7b5e72793e16bf80b907c99b46a799aeacc139ec20ea57121e50c7bd875a1a4365928f884e92abf02e21a5a13790a0f33e
languageName: node
linkType: hard
"decompress-response@npm:^3.3.0":
version: 3.3.0
resolution: "decompress-response@npm:3.3.0"
@@ -26928,13 +26883,6 @@ __metadata:
languageName: node
linkType: hard
"delay@npm:^5.0.0":
version: 5.0.0
resolution: "delay@npm:5.0.0"
checksum: 10/62f151151ecfde0d9afbb8a6be37a6d103c4cb24f35a20ef3fe56f920b0d0d0bb02bc9c0a3084d0179ef669ca332b91155f2ee4d9854622cd2cdba5fc95285f9
languageName: node
linkType: hard
"delayed-stream@npm:~1.0.0":
version: 1.0.0
resolution: "delayed-stream@npm:1.0.0"
@@ -28949,63 +28897,6 @@ __metadata:
languageName: unknown
linkType: soft
"example-backend-legacy@workspace:packages/backend-legacy":
version: 0.0.0-use.local
resolution: "example-backend-legacy@workspace:packages/backend-legacy"
dependencies:
"@backstage/backend-common": "npm:^0.25.0"
"@backstage/backend-defaults": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/catalog-client": "workspace:^"
"@backstage/catalog-model": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/config": "workspace:^"
"@backstage/integration": "workspace:^"
"@backstage/plugin-auth-node": "workspace:^"
"@backstage/plugin-catalog-backend": "workspace:^"
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "workspace:^"
"@backstage/plugin-catalog-node": "workspace:^"
"@backstage/plugin-events-backend": "workspace:^"
"@backstage/plugin-events-node": "workspace:^"
"@backstage/plugin-kubernetes-backend": "workspace:^"
"@backstage/plugin-permission-backend": "workspace:^"
"@backstage/plugin-permission-common": "workspace:^"
"@backstage/plugin-permission-node": "workspace:^"
"@backstage/plugin-scaffolder-backend": "workspace:^"
"@backstage/plugin-scaffolder-backend-module-confluence-to-markdown": "workspace:^"
"@backstage/plugin-scaffolder-backend-module-gitlab": "workspace:^"
"@backstage/plugin-scaffolder-backend-module-rails": "workspace:^"
"@backstage/plugin-search-backend": "workspace:^"
"@backstage/plugin-search-backend-module-catalog": "workspace:^"
"@backstage/plugin-search-backend-module-elasticsearch": "workspace:^"
"@backstage/plugin-search-backend-module-explore": "workspace:^"
"@backstage/plugin-search-backend-module-pg": "workspace:^"
"@backstage/plugin-search-backend-module-techdocs": "workspace:^"
"@backstage/plugin-search-backend-node": "workspace:^"
"@backstage/plugin-signals-backend": "workspace:^"
"@backstage/plugin-signals-node": "workspace:^"
"@backstage/plugin-techdocs-backend": "workspace:^"
"@gitbeaker/node": "npm:^35.1.0"
"@octokit/rest": "npm:^19.0.3"
"@types/dockerode": "npm:^3.3.0"
"@types/express": "npm:^4.17.6"
"@types/express-serve-static-core": "npm:^4.17.5"
"@types/luxon": "npm:^3.0.0"
azure-devops-node-api: "npm:^14.0.0"
better-sqlite3: "npm:^11.0.0"
dockerode: "npm:^4.0.0"
express: "npm:^4.17.1"
express-prom-bundle: "npm:^7.0.0"
express-promise-router: "npm:^4.1.0"
luxon: "npm:^3.0.0"
mysql2: "npm:^3.0.0"
pg: "npm:^8.11.3"
pg-connection-string: "npm:^2.3.0"
prom-client: "npm:^15.0.0"
winston: "npm:^3.2.1"
languageName: unknown
linkType: soft
"example-backend@workspace:packages/backend":
version: 0.0.0-use.local
resolution: "example-backend@workspace:packages/backend"
@@ -29179,20 +29070,6 @@ __metadata:
languageName: node
linkType: hard
"express-prom-bundle@npm:^7.0.0":
version: 7.0.2
resolution: "express-prom-bundle@npm:7.0.2"
dependencies:
"@types/express": "npm:^4.17.21"
express: "npm:^4.18.2"
on-finished: "npm:^2.3.0"
url-value-parser: "npm:^2.0.0"
peerDependencies:
prom-client: ">=15.0.0"
checksum: 10/19d95252eaaaedae1a05d90bbb96cbcc60e82e7710baa18810bd9c327b864b743f4e16bc2a5b3f7e51dcd505ac86db4fd9391c72c11cf6c0dc2c8df893870e02
languageName: node
linkType: hard
"express-promise-router@npm:^4.1.0, express-promise-router@npm:^4.1.1":
version: 4.1.1
resolution: "express-promise-router@npm:4.1.1"
@@ -29628,13 +29505,6 @@ __metadata:
languageName: node
linkType: hard
"filter-obj@npm:^1.1.0":
version: 1.1.0
resolution: "filter-obj@npm:1.1.0"
checksum: 10/9d681939eec2b4b129cb4f307b7e93d954a0657421d4e5357d86093b26d3f4f570909ed43717dcfd62428b3cf8cddd9841b35f9d40d12ac62cfabaa677942593
languageName: node
linkType: hard
"finalhandler@npm:1.1.2":
version: 1.1.2
resolution: "finalhandler@npm:1.1.2"
@@ -30886,7 +30756,7 @@ __metadata:
languageName: node
linkType: hard
"got@npm:^11.7.0, got@npm:^11.8.3":
"got@npm:^11.7.0":
version: 11.8.6
resolution: "got@npm:11.8.6"
dependencies:
@@ -34861,13 +34731,6 @@ __metadata:
languageName: node
linkType: hard
"li@npm:^1.3.0":
version: 1.3.0
resolution: "li@npm:1.3.0"
checksum: 10/825a1e132da5263e16cf24df92b787c5030c6549be66a8b2087e74ca56474aa681183f3a11b5f14e61d5d583af5f776ecf3b320ad689842511f36030339f6a0c
languageName: node
linkType: hard
"libsodium-wrappers@npm:^0.7.11":
version: 0.7.15
resolution: "libsodium-wrappers@npm:0.7.15"
@@ -40742,18 +40605,6 @@ __metadata:
languageName: node
linkType: hard
"query-string@npm:^7.0.0":
version: 7.0.0
resolution: "query-string@npm:7.0.0"
dependencies:
decode-uri-component: "npm:^0.2.0"
filter-obj: "npm:^1.1.0"
split-on-first: "npm:^1.0.0"
strict-uri-encode: "npm:^2.0.0"
checksum: 10/7f5031ede27d31448a08ec36255f0a6a1410a966456e493a651ccaf0605365c9b0f04f95d6c7d47c638a4502e0530a710812b90b597e5d99e2075af2c8c7da02
languageName: node
linkType: hard
"querystring-es3@npm:^0.2.1":
version: 0.2.1
resolution: "querystring-es3@npm:0.2.1"
@@ -43940,13 +43791,6 @@ __metadata:
languageName: node
linkType: hard
"split-on-first@npm:^1.0.0":
version: 1.1.0
resolution: "split-on-first@npm:1.1.0"
checksum: 10/16ff85b54ddcf17f9147210a4022529b343edbcbea4ce977c8f30e38408b8d6e0f25f92cd35b86a524d4797f455e29ab89eb8db787f3c10708e0b47ebf528d30
languageName: node
linkType: hard
"split2@npm:^3.0.0":
version: 3.2.2
resolution: "split2@npm:3.2.2"
@@ -44329,13 +44173,6 @@ __metadata:
languageName: node
linkType: hard
"strict-uri-encode@npm:^2.0.0":
version: 2.0.0
resolution: "strict-uri-encode@npm:2.0.0"
checksum: 10/eaac4cf978b6fbd480f1092cab8b233c9b949bcabfc9b598dd79a758f7243c28765ef7639c876fa72940dac687181b35486ea01ff7df3e65ce3848c64822c581
languageName: node
linkType: hard
"string-argv@npm:^0.3.2, string-argv@npm:~0.3.1":
version: 0.3.2
resolution: "string-argv@npm:0.3.2"
@@ -46693,13 +46530,6 @@ __metadata:
languageName: node
linkType: hard
"url-value-parser@npm:^2.0.0":
version: 2.0.3
resolution: "url-value-parser@npm:2.0.3"
checksum: 10/f13a2693b633896329956372a58a1c0f6666d72b87c85dff05564a132c1a5d2a698ca3097a481bf06afc1f5007c08ec67499136736c25c38f3ee84e877d72732
languageName: node
linkType: hard
"url@npm:^0.11.0, url@npm:^0.11.4":
version: 0.11.4
resolution: "url@npm:0.11.4"