fix: initial review finding fixes

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2023-12-08 15:33:42 +02:00
parent aaa4e910e2
commit f3575bc34c
12 changed files with 107 additions and 3 deletions
+4 -1
View File
@@ -20,6 +20,7 @@ import {
createBackendPlugin,
} from '@backstage/backend-plugin-api';
import { createRouter } from './service/router';
import { signalService } from '@backstage/plugin-signals-node';
/**
* DevTools backend plugin
@@ -35,13 +36,15 @@ export const devtoolsPlugin = createBackendPlugin({
logger: coreServices.logger,
permissions: coreServices.permissions,
httpRouter: coreServices.httpRouter,
signals: signalService,
},
async init({ config, logger, permissions, httpRouter }) {
async init({ config, logger, permissions, httpRouter, signals }) {
httpRouter.use(
await createRouter({
config,
logger: loggerToWinstonLogger(logger),
permissions,
signalService: signals,
}),
);
},
+18
View File
@@ -24,3 +24,21 @@ export default async function createPlugin(
});
}
```
Now add the signals to `packages/backend/src/index.ts`:
```ts
// ...
import signals from './plugins/sonarqube';
async function main() {
// ...
const signalsEnv = useHotMemoize(module, () => createEnv('signals'));
const apiRouter = Router();
// ...
apiRouter.use('/signals', await signals(signalsEnv));
apiRouter.use(notFoundHandler());
// ...
}
```
+5
View File
@@ -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 express from 'express';
import { Logger } from 'winston';
import { SignalService } from '@backstage/plugin-signals-node';
@@ -18,5 +19,9 @@ export interface RouterOptions {
service: SignalService;
}
// @public
const signalsPlugin: () => BackendFeature;
export default signalsPlugin;
// (No @packageDocumentation comment for this package)
```
+1
View File
@@ -23,6 +23,7 @@
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-events-node": "workspace:^",
+1
View File
@@ -14,3 +14,4 @@
* limitations under the License.
*/
export * from './service/router';
export { signalsPlugin as default } from './plugin';
+48
View File
@@ -0,0 +1,48 @@
/*
* Copyright 2023 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-common';
import {
coreServices,
createBackendPlugin,
} from '@backstage/backend-plugin-api';
import { createRouter } from './service/router';
import { signalService } from '@backstage/plugin-signals-node';
/**
* Signals backend plugin
*
* @public
*/
export const signalsPlugin = createBackendPlugin({
pluginId: 'devtools',
register(env) {
env.registerInit({
deps: {
httpRouter: coreServices.httpRouter,
logger: coreServices.logger,
service: signalService,
},
async init({ httpRouter, logger, service }) {
httpRouter.use(
await createRouter({
logger: loggerToWinstonLogger(logger),
service,
}),
);
},
});
},
});
@@ -33,7 +33,6 @@ export async function createRouter(
): Promise<express.Router> {
const { logger, service } = options;
let subscribed = false;
const upgradeMiddleware = (req: Request, _: Response, next: NextFunction) => {
const server: https.Server | http.Server = (
(req.socket ?? req.connection) as any
@@ -49,10 +48,10 @@ export async function createRouter(
}
if (!subscribed) {
subscribed = true;
server.on('upgrade', async (request, socket, head) => {
await service.handleUpgrade(request, socket, head);
});
subscribed = true;
}
};
+4
View File
@@ -13,6 +13,7 @@ import { IdentityApi } from '@backstage/plugin-auth-node';
import { IncomingMessage } from 'http';
import { JsonObject } from '@backstage/types';
import { Logger } from 'winston';
import { ServiceRef } from '@backstage/backend-plugin-api';
// @public (undocumented)
export type ServiceOptions = {
@@ -49,5 +50,8 @@ export class SignalService implements EventSubscriber {
supportsEventTopics(): string[];
}
// @public (undocumented)
export const signalService: ServiceRef<SignalService, 'plugin'>;
// (No @packageDocumentation comment for this package)
```
+1
View File
@@ -30,6 +30,7 @@
],
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-events-node": "workspace:^",
+1
View File
@@ -14,5 +14,6 @@
* limitations under the License.
*/
export * from './lib';
export * from './SignalService';
export * from './types';
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2023 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 { createServiceRef } from '@backstage/backend-plugin-api';
/** @public */
export const signalService = createServiceRef<
import('./SignalService').SignalService
>({ id: 'signals.service', scope: 'plugin' });
+2
View File
@@ -8839,6 +8839,7 @@ __metadata:
resolution: "@backstage/plugin-signals-backend@workspace:plugins/signals-backend"
dependencies:
"@backstage/backend-common": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/config": "workspace:^"
"@backstage/plugin-auth-node": "workspace:^"
@@ -8865,6 +8866,7 @@ __metadata:
resolution: "@backstage/plugin-signals-node@workspace:plugins/signals-node"
dependencies:
"@backstage/backend-common": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/config": "workspace:^"
"@backstage/plugin-auth-node": "workspace:^"