Skip to content

Commit

Permalink
feat: add new backend system support for existing backend plugins tha…
Browse files Browse the repository at this point in the history
…t have not been migrated over yet (#1132)

* feat(3scale-backend): add new backend system support for 3scale-backend

* feat(aap-backend): add new backend system support for aap-backend plugin

* chore(keycloak-backend): add TODO note to add extension points in future

* feat(kiali-backend): add new backend system support for kiali-backend plugin

* feat(matomo-backend): add new backend system support for the matomo-backend plugin

* feat(notifications-backend): add new backend system support for the notifications-backend plugin

* docs(3scale-backend): update README with new backend installation procedure

* docs(aap-backend): update README with new backend installation procedure

* docs(keycloak-backend): update README with new backend installation procedure

* docs(notifications-backend): update README with new backend installation procedure

* docs(matomo-backend): update README for new backend installation procedure

* feat(feedback-backend): add new backend system support

* docs(feedback-backend): update README with new backend installation procedure

* feat(quay-action): add support for the new backend system

* feat(kubernetes-action): add support for the new backend system

* feat(regex-actions): add new backend system support

* feat(servicenow-actions): add new backend system support

* feat(sonarqube-actions): add new backend system support

* feat(ocm-backend): add new backend system support

* feat(orchestrator-backend): add support for new backend system

* chore: remove unnecessary dynamic alpha.ts files

* feat(cli): update plugin templates to support new backend

* chore(cli): update scaffolder module name

* chore(cli): remove unused imports from the backend plugin template
  • Loading branch information
Zaperex authored Jan 30, 2024
1 parent e6ba8e3 commit 06e16fd
Show file tree
Hide file tree
Showing 90 changed files with 1,401 additions and 597 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/lib/new/factories/backendModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ describe('backendModule factory', () => {
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'templating module.ts.hbs',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'Installing:',
`moving plugins${sep}test-backend-module-tester-two`,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/new/factories/backendPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ describe('backendPlugin factory', () => {
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'templating plugin.ts.hbs',
'templating run.ts.hbs',
'copying setupTests.ts',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'copying router.test.ts',
'templating router.ts.hbs',
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/new/factories/scaffolderModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ describe('scaffolderModule factory', () => {
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating index.ts.hbs',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'templating module.ts.hbs',
'templating index.ts.hbs',
'copying index.ts',
'copying example.test.ts',
'copying example.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { {{moduleVar}} as default } from './module';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { coreServices, createBackendModule } from '@backstage/backend-plugin-api';

/**
* The {{moduleId}} backend module for the {{pluginId}} plugin.
*
* @alpha
*/
export const {{moduleVar}} = createBackendModule({
pluginId: '{{pluginId}}',
moduleId: '{{moduleId}}',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { {{id}}Plugin as default } from './plugin';

This file was deleted.

25 changes: 25 additions & 0 deletions packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { loggerToWinstonLogger } from '@backstage/backend-common';
import { coreServices, createBackendPlugin } from '@backstage/backend-plugin-api';

import { createRouter } from './service/router';

/**
* The {{id}} backend plugin.
*
* @alpha
*/
export const {{id}}Plugin = createBackendPlugin({
pluginId: '{{id}}',
register(env) {
env.registerInit({
deps: {
logger: coreServices.logger,
config: coreServices.rootConfig,
http: coreServices.httpRouter,
},
async init({ config, logger, http }) {
http.use(() => createRouter({...config, logger: loggerToWinstonLogger(logger)}));
},
});
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { errorHandler, loggerToWinstonLogger } from '@backstage/backend-common';
import { coreServices, createBackendPlugin } from '@backstage/backend-plugin-api';
import { errorHandler } from '@backstage/backend-common';
import express from 'express';
import Router from 'express-promise-router';
import { Logger } from 'winston';
Expand All @@ -23,18 +22,4 @@ export async function createRouter(
router.use(errorHandler());
return router;
}
export const {{id}}Plugin = createBackendPlugin({
pluginId: '{{id}}',
register(env) {
env.registerInit({
deps: {
logger: coreServices.logger,
config: coreServices.rootConfig,
http: coreServices.httpRouter,
},
async init({ config, logger, http }) {
http.use(() => createRouter({...config, logger: loggerToWinstonLogger(logger)}));
},
});
},
});

1 change: 1 addition & 0 deletions packages/cli/templates/scaffolder-module/src/alpha.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { {{id}}ActionScaffolderModule as default } from './module';
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import {
coreServices,
createBackendModule,
} from '@backstage/backend-plugin-api';
import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager';
import { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';
import { createAcmeExampleAction } from './actions';

import { createAcmeExampleAction } from '../actions';

export const dynamicPluginInstaller: BackendDynamicPluginInstaller = {
kind: 'new',
install: createBackendModule({
/***/
/**
* The {{id}} module for @backstage/plugin-scaffolder-backend.
*
* @alpha
*/
export const {{id}}ActionScaffolderModule = createBackendModule({
moduleId: 'scaffolder-backend-{{id}}',
pluginId: 'scaffolder',
register(env) {
Expand All @@ -23,5 +25,4 @@ export const dynamicPluginInstaller: BackendDynamicPluginInstaller = {
},
});
},
}),
};
})
26 changes: 20 additions & 6 deletions plugins/3scale-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ yarn workspace backend add @janus-idp/backstage-plugin-3scale-backend

3scale Backstage provider allows configuration of one or multiple providers using the `app-config.yaml` configuration file of Backstage.

### Procedure
#### Legacy Backend Procedure

1. Use a `threeScaleApiEntity` marker to start configuring the `app-config.yaml` file of Backstage:

Expand All @@ -29,12 +29,12 @@ yarn workspace backend add @janus-idp/backstage-plugin-3scale-backend
accessToken: <ACCESS_TOKEN>
schedule: # optional; same options as in TaskScheduleDefinition
# supports cron, ISO duration, "human duration" as used in code
frequency: { minutes: 1 }
frequency: { minutes: 30 }
# supports ISO duration, "human duration" as used in code
timeout: { minutes: 1 }
timeout: { minutes: 3 }
```
2. Configure the scheduler for the entity provider using one of the following methods:
2. If installing into the _legacy_ backend, configure the scheduler for the entity provider using one of the following methods:
- **Method 1**: If the scheduler is configured inside the `app-config.yaml` using the schedule config key mentioned previously, add the following code to `packages/backend/src/plugins/catalog.ts` file:

Expand Down Expand Up @@ -88,8 +88,8 @@ yarn workspace backend add @janus-idp/backstage-plugin-3scale-backend
ThreeScaleApiEntityProvider.fromConfig(env.config, {
logger: env.logger,
schedule: env.scheduler.createScheduledTaskRunner({
frequency: { minutes: 1 },
timeout: { minutes: 1 },
frequency: { minutes: 30 },
timeout: { minutes: 3 },
}),
}),
);
Expand All @@ -109,6 +109,20 @@ yarn workspace backend add @janus-idp/backstage-plugin-3scale-backend

***

#### New Backend Procedure

1. If installing into the new backend system, make the same configurations to the `app=config.yaml` as in the [Legacy Backend Installation Procedure](#legacy-backend-installation-procedure). Make sure to configure the schedule inside the `app-config.yaml` file. The default schedule is a frequency of 30 minutes and a timeout of 3 minutes.
2. Add the following code to the `packages/backend/src/index.ts` file:

```ts title="packages/backend/src/index.ts"
const backend = createBackend();
/* highlight-add-next-line */
backend.add(import('@janus-idp/backstage-plugin-3scale-backend/alpha'));
backend.start();
```

### Troubleshooting

When you start your Backstage application, you can see some log lines as follows:
Expand Down
14 changes: 13 additions & 1 deletion plugins/3scale-backend/dist-dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
"backstage": {
"role": "backend-plugin"
},
"exports": {
".": {
"require": "./dist/index.cjs.js",
"default": "./dist/index.cjs.js"
},
"./alpha": {
"require": "./dist/alpha.cjs.js",
"default": "./dist/alpha.cjs.js"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "backstage-cli package build",
"clean": "backstage-cli package clean",
Expand All @@ -31,7 +42,8 @@
"files": [
"dist",
"config.d.ts",
"app-config.janus-idp.yaml"
"app-config.janus-idp.yaml",
"alpha"
],
"configSchema": "config.d.ts",
"repository": "github:janus-idp/backstage-plugins",
Expand Down
15 changes: 15 additions & 0 deletions plugins/3scale-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
"backstage": {
"role": "backend-plugin"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"scripts": {
"build": "backstage-cli package build",
"clean": "backstage-cli package clean",
Expand Down
22 changes: 22 additions & 0 deletions plugins/3scale-backend/src/alpha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 The Janus IDP 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.
*/

/**
* The 3Scale backend plugin integrates 3Scale into Backstage
*
* @packageDocumentation
*/
export { catalogModule3ScaleEntityProvider as default } from './module';
40 changes: 0 additions & 40 deletions plugins/3scale-backend/src/dynamic/alpha.ts

This file was deleted.

15 changes: 15 additions & 0 deletions plugins/3scale-backend/src/dynamic/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 The Janus IDP 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 { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager';

import { ThreeScaleApiEntityProvider } from '../providers';
Expand Down
50 changes: 50 additions & 0 deletions plugins/3scale-backend/src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 The Janus IDP 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-common';
import {
coreServices,
createBackendModule,
} from '@backstage/backend-plugin-api';
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';

import { ThreeScaleApiEntityProvider } from './providers';

export const catalogModule3ScaleEntityProvider = createBackendModule({
moduleId: 'catalog-backend-module-3scale',
pluginId: 'catalog',
register(env) {
env.registerInit({
deps: {
catalog: catalogProcessingExtensionPoint,
config: coreServices.rootConfig,
logger: coreServices.logger,
scheduler: coreServices.scheduler,
},
async init({ catalog, config, logger, scheduler }) {
catalog.addEntityProvider(
ThreeScaleApiEntityProvider.fromConfig(config, {
logger: loggerToWinstonLogger(logger),
scheduler: scheduler,
schedule: scheduler.createScheduledTaskRunner({
frequency: { minutes: 30 },
timeout: { minutes: 3 },
}),
}),
);
},
});
},
});
Loading

0 comments on commit 06e16fd

Please sign in to comment.