@backstage/plugin-signals-backend 0.0.0-nightly-20240228021022 → 0.0.0-nightly-20240229020904
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -7
- package/dist/index.cjs.js +53 -26
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
# @backstage/plugin-signals-backend
|
|
2
2
|
|
|
3
|
-
## 0.0.0-nightly-
|
|
3
|
+
## 0.0.0-nightly-20240229020904
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- 0fb419b: Updated dependency `uuid` to `^9.0.0`.
|
|
8
8
|
Updated dependency `@types/uuid` to `^9.0.0`.
|
|
9
|
+
- df45710: Improved error logging and fixed authentication
|
|
9
10
|
- Updated dependencies
|
|
10
|
-
- @backstage/plugin-events-node@0.0.0-nightly-
|
|
11
|
-
- @backstage/backend-common@0.0.0-nightly-
|
|
12
|
-
- @backstage/plugin-auth-node@0.0.0-nightly-
|
|
13
|
-
- @backstage/backend-plugin-api@0.0.0-nightly-
|
|
14
|
-
- @backstage/plugin-signals-node@0.0.0-nightly-
|
|
15
|
-
- @backstage/config@0.0.0-nightly-
|
|
11
|
+
- @backstage/plugin-events-node@0.0.0-nightly-20240229020904
|
|
12
|
+
- @backstage/backend-common@0.0.0-nightly-20240229020904
|
|
13
|
+
- @backstage/plugin-auth-node@0.0.0-nightly-20240229020904
|
|
14
|
+
- @backstage/backend-plugin-api@0.0.0-nightly-20240229020904
|
|
15
|
+
- @backstage/plugin-signals-node@0.0.0-nightly-20240229020904
|
|
16
|
+
- @backstage/config@0.0.0-nightly-20240229020904
|
|
16
17
|
- @backstage/types@1.1.1
|
|
17
18
|
|
|
18
19
|
## 0.0.4-next.0
|
package/dist/index.cjs.js
CHANGED
|
@@ -40,16 +40,16 @@ class SignalManager {
|
|
|
40
40
|
const id = uuid.v4();
|
|
41
41
|
const conn = {
|
|
42
42
|
id,
|
|
43
|
-
user: (_a = identity == null ? void 0 : identity.
|
|
43
|
+
user: (_a = identity == null ? void 0 : identity.userEntityRef) != null ? _a : "user:default/guest",
|
|
44
44
|
ws,
|
|
45
|
-
ownershipEntityRefs: (_b = identity == null ? void 0 : identity.
|
|
45
|
+
ownershipEntityRefs: (_b = identity == null ? void 0 : identity.ownershipEntityRefs) != null ? _b : [
|
|
46
46
|
"user:default/guest"
|
|
47
47
|
],
|
|
48
48
|
subscriptions: /* @__PURE__ */ new Set()
|
|
49
49
|
};
|
|
50
50
|
this.connections.set(id, conn);
|
|
51
51
|
ws.on("error", (err) => {
|
|
52
|
-
this.logger.
|
|
52
|
+
this.logger.error(
|
|
53
53
|
`Error occurred with connection ${id}: ${err}, closing connection`
|
|
54
54
|
);
|
|
55
55
|
ws.close();
|
|
@@ -120,35 +120,46 @@ class SignalManager {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
async function createRouter(options) {
|
|
123
|
-
const { logger,
|
|
123
|
+
const { logger, discovery } = options;
|
|
124
|
+
const { auth, userInfo } = backendCommon.createLegacyAuthAdapters(options);
|
|
124
125
|
const manager = SignalManager.create(options);
|
|
125
126
|
let subscribedToUpgradeRequests = false;
|
|
127
|
+
let apiUrl = void 0;
|
|
126
128
|
const webSocketServer = new ws.WebSocketServer({
|
|
127
129
|
noServer: true,
|
|
128
130
|
clientTracking: false
|
|
129
131
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
webSocketServer.on("error", (error) => {
|
|
133
|
+
logger.error("WebSocket server error", error);
|
|
134
|
+
});
|
|
135
|
+
webSocketServer.on("close", () => {
|
|
136
|
+
logger.info("WebSocket server closed");
|
|
137
|
+
});
|
|
138
|
+
const handleUpgrade = async (request, socket, head) => {
|
|
139
|
+
if (!apiUrl) {
|
|
140
|
+
apiUrl = await discovery.getBaseUrl("signals");
|
|
141
|
+
}
|
|
142
|
+
if (!request.url || !apiUrl || !apiUrl.endsWith(request.url)) {
|
|
135
143
|
return;
|
|
136
144
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (!request.url || !apiUrl.endsWith(request.url)) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
let userIdentity = void 0;
|
|
144
|
-
const token = req.headers["sec-websocket-protocol"];
|
|
145
|
+
let userIdentity = void 0;
|
|
146
|
+
try {
|
|
147
|
+
const token = request.headers["sec-websocket-protocol"];
|
|
145
148
|
if (token) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
149
|
+
const credentials = await auth.authenticate(token);
|
|
150
|
+
if (auth.isPrincipal(credentials, "user")) {
|
|
151
|
+
userIdentity = await userInfo.getUserInfo(credentials);
|
|
152
|
+
}
|
|
151
153
|
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
logger.error("Failed to authenticate WebSocket connection", e);
|
|
156
|
+
socket.write(
|
|
157
|
+
"HTTP/1.1 401 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\n\r\n"
|
|
158
|
+
);
|
|
159
|
+
socket.destroy();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
152
163
|
webSocketServer.handleUpgrade(
|
|
153
164
|
request,
|
|
154
165
|
socket,
|
|
@@ -157,7 +168,19 @@ async function createRouter(options) {
|
|
|
157
168
|
manager.addConnection(ws, userIdentity);
|
|
158
169
|
}
|
|
159
170
|
);
|
|
160
|
-
})
|
|
171
|
+
} catch (e) {
|
|
172
|
+
logger.error("Failed to handle WebSocket upgrade", e);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const upgradeMiddleware = async (req, _, next) => {
|
|
176
|
+
var _a;
|
|
177
|
+
const server = (_a = req.socket) == null ? void 0 : _a.server;
|
|
178
|
+
if (subscribedToUpgradeRequests || !server || !req.headers || req.headers.upgrade === void 0 || req.headers.upgrade.toLowerCase() !== "websocket") {
|
|
179
|
+
next();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
subscribedToUpgradeRequests = true;
|
|
183
|
+
server.on("upgrade", handleUpgrade);
|
|
161
184
|
};
|
|
162
185
|
const router = Router__default["default"]();
|
|
163
186
|
router.use(express__default["default"].json());
|
|
@@ -178,16 +201,20 @@ const signalsPlugin = backendPluginApi.createBackendPlugin({
|
|
|
178
201
|
httpRouter: backendPluginApi.coreServices.httpRouter,
|
|
179
202
|
logger: backendPluginApi.coreServices.logger,
|
|
180
203
|
identity: backendPluginApi.coreServices.identity,
|
|
181
|
-
discovery: backendPluginApi.coreServices.discovery
|
|
204
|
+
discovery: backendPluginApi.coreServices.discovery,
|
|
205
|
+
userInfo: backendPluginApi.coreServices.userInfo,
|
|
206
|
+
auth: backendPluginApi.coreServices.auth
|
|
182
207
|
// TODO: EventBroker. It is optional for now but it's actually required so waiting for the new backend system
|
|
183
208
|
// for the events-backend for this to work.
|
|
184
209
|
},
|
|
185
|
-
async init({ httpRouter, logger, identity, discovery }) {
|
|
210
|
+
async init({ httpRouter, logger, identity, discovery, userInfo, auth }) {
|
|
186
211
|
httpRouter.use(
|
|
187
212
|
await createRouter({
|
|
188
213
|
logger,
|
|
189
214
|
identity,
|
|
190
|
-
discovery
|
|
215
|
+
discovery,
|
|
216
|
+
userInfo,
|
|
217
|
+
auth
|
|
191
218
|
})
|
|
192
219
|
);
|
|
193
220
|
}
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/service/SignalManager.ts","../src/service/router.ts","../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { EventBroker, EventParams } from '@backstage/plugin-events-node';\nimport { SignalPayload } from '@backstage/plugin-signals-node';\nimport { RawData, WebSocket } from 'ws';\nimport { v4 as uuid } from 'uuid';\nimport { JsonObject } from '@backstage/types';\nimport { BackstageIdentityResponse } from '@backstage/plugin-auth-node';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\n/**\n * @internal\n */\nexport type SignalConnection = {\n id: string;\n user: string;\n ws: WebSocket;\n ownershipEntityRefs: string[];\n subscriptions: Set<string>;\n};\n\n/**\n * @internal\n */\nexport type SignalManagerOptions = {\n // TODO: Remove optional when events-backend can offer this service\n eventBroker?: EventBroker;\n logger: LoggerService;\n};\n\n/** @internal */\nexport class SignalManager {\n private connections: Map<string, SignalConnection> = new Map<\n string,\n SignalConnection\n >();\n private eventBroker?: EventBroker;\n private logger: LoggerService;\n\n static create(options: SignalManagerOptions) {\n return new SignalManager(options);\n }\n\n private constructor(options: SignalManagerOptions) {\n ({ eventBroker: this.eventBroker, logger: this.logger } = options);\n\n this.eventBroker?.subscribe({\n supportsEventTopics: () => ['signals'],\n onEvent: (params: EventParams<SignalPayload>) =>\n this.onEventBrokerEvent(params),\n });\n }\n\n addConnection(ws: WebSocket, identity?: BackstageIdentityResponse) {\n const id = uuid();\n\n const conn = {\n id,\n user: identity?.identity.userEntityRef ?? 'user:default/guest',\n ws,\n ownershipEntityRefs: identity?.identity.ownershipEntityRefs ?? [\n 'user:default/guest',\n ],\n subscriptions: new Set<string>(),\n };\n\n this.connections.set(id, conn);\n\n ws.on('error', (err: Error) => {\n this.logger.info(\n `Error occurred with connection ${id}: ${err}, closing connection`,\n );\n ws.close();\n this.connections.delete(id);\n });\n\n ws.on('close', (code: number, reason: Buffer) => {\n this.logger.info(\n `Connection ${id} closed with code ${code}, reason: ${reason}`,\n );\n this.connections.delete(id);\n });\n\n ws.on('message', (data: RawData, isBinary: boolean) => {\n this.logger.debug(`Received message from connection ${id}: ${data}`);\n if (isBinary) {\n return;\n }\n try {\n const json = JSON.parse(data.toString()) as JsonObject;\n this.handleMessage(conn, json);\n } catch (err: any) {\n this.logger.error(\n `Invalid message received from connection ${id}: ${err}`,\n );\n }\n });\n }\n\n private handleMessage(connection: SignalConnection, message: JsonObject) {\n if (message.action === 'subscribe' && message.channel) {\n this.logger.info(\n `Connection ${connection.id} subscribed to ${message.channel}`,\n );\n connection.subscriptions.add(message.channel as string);\n } else if (message.action === 'unsubscribe' && message.channel) {\n this.logger.info(\n `Connection ${connection.id} unsubscribed from ${message.channel}`,\n );\n connection.subscriptions.delete(message.channel as string);\n }\n }\n\n private async onEventBrokerEvent(\n params: EventParams<SignalPayload>,\n ): Promise<void> {\n const { eventPayload } = params;\n if (!eventPayload.channel || !eventPayload.message) {\n return;\n }\n\n const { channel, recipients, message } = eventPayload;\n const jsonMessage = JSON.stringify({ channel, message });\n let users: string[] = [];\n if (recipients !== null) {\n users = Array.isArray(recipients) ? recipients : [recipients];\n }\n\n // Actual websocket message sending\n this.connections.forEach(conn => {\n if (!conn.subscriptions.has(channel)) {\n return;\n }\n // Sending to all users can be done with null\n if (\n recipients !== null &&\n !conn.ownershipEntityRefs.some((ref: string) => users.includes(ref))\n ) {\n return;\n }\n\n if (conn.ws.readyState !== WebSocket.OPEN) {\n return;\n }\n\n conn.ws.send(jsonMessage, err => {\n if (err) {\n this.logger.error(`Failed to send message to ${conn.id}: ${err}`);\n }\n });\n });\n }\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n errorHandler,\n PluginEndpointDiscovery,\n} from '@backstage/backend-common';\nimport express, { NextFunction, Request, Response } from 'express';\nimport Router from 'express-promise-router';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport * as https from 'https';\nimport http, { IncomingMessage } from 'http';\nimport { SignalManager } from './SignalManager';\nimport {\n BackstageIdentityResponse,\n IdentityApi,\n IdentityApiGetIdentityRequest,\n} from '@backstage/plugin-auth-node';\nimport { EventBroker } from '@backstage/plugin-events-node';\nimport { WebSocket, WebSocketServer } from 'ws';\n\n/** @public */\nexport interface RouterOptions {\n logger: LoggerService;\n eventBroker?: EventBroker;\n identity: IdentityApi;\n discovery: PluginEndpointDiscovery;\n}\n\n/** @public */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { logger, identity, discovery } = options;\n const manager = SignalManager.create(options);\n let subscribedToUpgradeRequests = false;\n\n const webSocketServer = new WebSocketServer({\n noServer: true,\n clientTracking: false,\n });\n\n const upgradeMiddleware = async (\n req: Request,\n _: Response,\n next: NextFunction,\n ) => {\n const server: https.Server | http.Server = (req.socket as any)?.server;\n if (\n subscribedToUpgradeRequests ||\n !server ||\n !req.headers ||\n req.headers.upgrade === undefined ||\n req.headers.upgrade.toLowerCase() !== 'websocket'\n ) {\n next();\n return;\n }\n\n subscribedToUpgradeRequests = true;\n const apiUrl = await discovery.getBaseUrl('signals');\n server.on('upgrade', async (request, socket, head) => {\n if (!request.url || !apiUrl.endsWith(request.url)) {\n return;\n }\n\n let userIdentity: BackstageIdentityResponse | undefined = undefined;\n\n // Authentication token is passed in Sec-WebSocket-Protocol header as there\n // is no other way to pass the token with plain websockets\n const token = req.headers['sec-websocket-protocol'];\n if (token) {\n userIdentity = await identity.getIdentity({\n request: {\n headers: { authorization: token },\n },\n } as IdentityApiGetIdentityRequest);\n }\n\n webSocketServer.handleUpgrade(\n request,\n socket,\n head,\n (ws: WebSocket, __: IncomingMessage) => {\n manager.addConnection(ws, userIdentity);\n },\n );\n });\n };\n\n const router = Router();\n router.use(express.json());\n router.use(upgradeMiddleware);\n\n router.get('/health', (_, response) => {\n logger.info('PONG!');\n response.json({ status: 'ok' });\n });\n\n router.use(errorHandler());\n return router;\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './service/router';\n\n/**\n * Signals backend plugin\n *\n * @public\n */\nexport const signalsPlugin = createBackendPlugin({\n pluginId: 'signals',\n register(env) {\n env.registerInit({\n deps: {\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n identity: coreServices.identity,\n discovery: coreServices.discovery,\n // TODO: EventBroker. It is optional for now but it's actually required so waiting for the new backend system\n // for the events-backend for this to work.\n },\n async init({ httpRouter, logger, identity, discovery }) {\n httpRouter.use(\n await createRouter({\n logger,\n identity,\n discovery,\n }),\n );\n },\n });\n },\n});\n"],"names":["uuid","WebSocket","WebSocketServer","Router","express","errorHandler","createBackendPlugin","coreServices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4CO,MAAM,aAAc,CAAA;AAAA,EAYjB,YAAY,OAA+B,EAAA;AAXnD,IAAQ,aAAA,CAAA,IAAA,EAAA,aAAA,sBAAiD,GAGvD,EAAA,CAAA,CAAA;AACF,IAAQ,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,C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ASC,0BAAO,EAAA,CAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,2BAAQ,CAAA,IAAA,EAAM,CAAA,CAAA;AACzB,EAAA,MAAA,CAAO,IAAI,iBAAiB,CAAA,CAAA;AAE5B,EAAA,MAAA,CAAO,GAAI,CAAA,SAAA,EAAW,CAAC,CAAA,EAAG,QAAa,KAAA;AACrC,IAAA,MAAA,CAAO,KAAK,OAAO,CAAA,CAAA;AACnB,IAAA,QAAA,CAAS,IAAK,CAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA,CAAA;AAAA,GAC/B,CAAA,CAAA;AAED,EAAO,MAAA,CAAA,GAAA,CAAIC,4BAAc,CAAA,CAAA;AACzB,EAAO,OAAA,MAAA,CAAA;AACT;;ACvFO,MAAM,gBAAgBC,oCAAoB,CAAA;AAAA,EAC/C,QAAU,EAAA,SAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,YAAYC,6BAAa,CAAA,UAAA;AAAA,QACzB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,WAAWA,6BAAa,CAAA,SAAA;AAAA;AAAA;AAAA,OAG1B;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,YAAY,MAAQ,EAAA,QAAA,EAAU,WAAa,EAAA;AACtD,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAM,YAAa,CAAA;AAAA,YACjB,MAAA;AAAA,YACA,QAAA;AAAA,YACA,SAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/service/SignalManager.ts","../src/service/router.ts","../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { EventBroker, EventParams } from '@backstage/plugin-events-node';\nimport { SignalPayload } from '@backstage/plugin-signals-node';\nimport { RawData, WebSocket } from 'ws';\nimport { v4 as uuid } from 'uuid';\nimport { JsonObject } from '@backstage/types';\nimport {\n BackstageUserInfo,\n LoggerService,\n} from '@backstage/backend-plugin-api';\n\n/**\n * @internal\n */\nexport type SignalConnection = {\n id: string;\n user: string;\n ws: WebSocket;\n ownershipEntityRefs: string[];\n subscriptions: Set<string>;\n};\n\n/**\n * @internal\n */\nexport type SignalManagerOptions = {\n // TODO: Remove optional when events-backend can offer this service\n eventBroker?: EventBroker;\n logger: LoggerService;\n};\n\n/** @internal */\nexport class SignalManager {\n private connections: Map<string, SignalConnection> = new Map<\n string,\n SignalConnection\n >();\n private eventBroker?: EventBroker;\n private logger: LoggerService;\n\n static create(options: SignalManagerOptions) {\n return new SignalManager(options);\n }\n\n private constructor(options: SignalManagerOptions) {\n ({ eventBroker: this.eventBroker, logger: this.logger } = options);\n\n this.eventBroker?.subscribe({\n supportsEventTopics: () => ['signals'],\n onEvent: (params: EventParams<SignalPayload>) =>\n this.onEventBrokerEvent(params),\n });\n }\n\n addConnection(ws: WebSocket, identity?: BackstageUserInfo) {\n const id = uuid();\n\n const conn = {\n id,\n user: identity?.userEntityRef ?? 'user:default/guest',\n ws,\n ownershipEntityRefs: identity?.ownershipEntityRefs ?? [\n 'user:default/guest',\n ],\n subscriptions: new Set<string>(),\n };\n\n this.connections.set(id, conn);\n\n ws.on('error', (err: Error) => {\n this.logger.error(\n `Error occurred with connection ${id}: ${err}, closing connection`,\n );\n ws.close();\n this.connections.delete(id);\n });\n\n ws.on('close', (code: number, reason: Buffer) => {\n this.logger.info(\n `Connection ${id} closed with code ${code}, reason: ${reason}`,\n );\n this.connections.delete(id);\n });\n\n ws.on('message', (data: RawData, isBinary: boolean) => {\n this.logger.debug(`Received message from connection ${id}: ${data}`);\n if (isBinary) {\n return;\n }\n try {\n const json = JSON.parse(data.toString()) as JsonObject;\n this.handleMessage(conn, json);\n } catch (err: any) {\n this.logger.error(\n `Invalid message received from connection ${id}: ${err}`,\n );\n }\n });\n }\n\n private handleMessage(connection: SignalConnection, message: JsonObject) {\n if (message.action === 'subscribe' && message.channel) {\n this.logger.info(\n `Connection ${connection.id} subscribed to ${message.channel}`,\n );\n connection.subscriptions.add(message.channel as string);\n } else if (message.action === 'unsubscribe' && message.channel) {\n this.logger.info(\n `Connection ${connection.id} unsubscribed from ${message.channel}`,\n );\n connection.subscriptions.delete(message.channel as string);\n }\n }\n\n private async onEventBrokerEvent(\n params: EventParams<SignalPayload>,\n ): Promise<void> {\n const { eventPayload } = params;\n if (!eventPayload.channel || !eventPayload.message) {\n return;\n }\n\n const { channel, recipients, message } = eventPayload;\n const jsonMessage = JSON.stringify({ channel, message });\n let users: string[] = [];\n if (recipients !== null) {\n users = Array.isArray(recipients) ? recipients : [recipients];\n }\n\n // Actual websocket message sending\n this.connections.forEach(conn => {\n if (!conn.subscriptions.has(channel)) {\n return;\n }\n // Sending to all users can be done with null\n if (\n recipients !== null &&\n !conn.ownershipEntityRefs.some((ref: string) => users.includes(ref))\n ) {\n return;\n }\n\n if (conn.ws.readyState !== WebSocket.OPEN) {\n return;\n }\n\n conn.ws.send(jsonMessage, err => {\n if (err) {\n this.logger.error(`Failed to send message to ${conn.id}: ${err}`);\n }\n });\n });\n }\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n createLegacyAuthAdapters,\n errorHandler,\n PluginEndpointDiscovery,\n} from '@backstage/backend-common';\nimport express, { NextFunction, Request, Response } from 'express';\nimport Router from 'express-promise-router';\nimport {\n AuthService,\n BackstageUserInfo,\n LoggerService,\n UserInfoService,\n} from '@backstage/backend-plugin-api';\nimport * as https from 'https';\nimport http, { IncomingMessage } from 'http';\nimport { SignalManager } from './SignalManager';\nimport { IdentityApi } from '@backstage/plugin-auth-node';\nimport { EventBroker } from '@backstage/plugin-events-node';\nimport { WebSocket, WebSocketServer } from 'ws';\nimport { Duplex } from 'stream';\n\n/** @public */\nexport interface RouterOptions {\n logger: LoggerService;\n eventBroker?: EventBroker;\n identity: IdentityApi;\n discovery: PluginEndpointDiscovery;\n auth?: AuthService;\n userInfo?: UserInfoService;\n}\n\n/** @public */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { logger, discovery } = options;\n const { auth, userInfo } = createLegacyAuthAdapters(options);\n\n const manager = SignalManager.create(options);\n let subscribedToUpgradeRequests = false;\n let apiUrl: string | undefined = undefined;\n\n const webSocketServer = new WebSocketServer({\n noServer: true,\n clientTracking: false,\n });\n\n webSocketServer.on('error', (error: Error) => {\n logger.error('WebSocket server error', error);\n });\n\n webSocketServer.on('close', () => {\n logger.info('WebSocket server closed');\n });\n\n const handleUpgrade = async (\n request: Request<any, any, any, any, any>,\n socket: Duplex,\n head: Buffer,\n ) => {\n if (!apiUrl) {\n apiUrl = await discovery.getBaseUrl('signals');\n }\n\n if (!request.url || !apiUrl || !apiUrl.endsWith(request.url)) {\n return;\n }\n\n let userIdentity: BackstageUserInfo | undefined = undefined;\n\n // Authentication token is passed in Sec-WebSocket-Protocol header as there\n // is no other way to pass the token with plain websockets\n try {\n const token = request.headers['sec-websocket-protocol'];\n if (token) {\n const credentials = await auth.authenticate(token);\n if (auth.isPrincipal(credentials, 'user')) {\n userIdentity = await userInfo.getUserInfo(credentials);\n }\n }\n } catch (e) {\n logger.error('Failed to authenticate WebSocket connection', e);\n socket.write(\n 'HTTP/1.1 401 Web Socket Protocol Handshake\\r\\n' +\n 'Upgrade: WebSocket\\r\\n' +\n 'Connection: Upgrade\\r\\n' +\n '\\r\\n',\n );\n socket.destroy();\n return;\n }\n\n try {\n webSocketServer.handleUpgrade(\n request,\n socket,\n head,\n (ws: WebSocket, __: IncomingMessage) => {\n manager.addConnection(ws, userIdentity);\n },\n );\n } catch (e) {\n logger.error('Failed to handle WebSocket upgrade', e);\n }\n };\n\n const upgradeMiddleware = async (\n req: Request,\n _: Response,\n next: NextFunction,\n ) => {\n const server: https.Server | http.Server = (req.socket as any)?.server;\n if (\n subscribedToUpgradeRequests ||\n !server ||\n !req.headers ||\n req.headers.upgrade === undefined ||\n req.headers.upgrade.toLowerCase() !== 'websocket'\n ) {\n next();\n return;\n }\n\n subscribedToUpgradeRequests = true;\n server.on('upgrade', handleUpgrade);\n };\n\n const router = Router();\n router.use(express.json());\n router.use(upgradeMiddleware);\n\n router.get('/health', (_, response) => {\n logger.info('PONG!');\n response.json({ status: 'ok' });\n });\n\n router.use(errorHandler());\n return router;\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './service/router';\n\n/**\n * Signals backend plugin\n *\n * @public\n */\nexport const signalsPlugin = createBackendPlugin({\n pluginId: 'signals',\n register(env) {\n env.registerInit({\n deps: {\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n identity: coreServices.identity,\n discovery: coreServices.discovery,\n userInfo: coreServices.userInfo,\n auth: coreServices.auth,\n // TODO: EventBroker. It is optional for now but it's actually required so waiting for the new backend system\n // for the events-backend for this to work.\n },\n async init({ httpRouter, logger, identity, discovery, userInfo, auth }) {\n httpRouter.use(\n await createRouter({\n logger,\n identity,\n discovery,\n userInfo,\n auth,\n }),\n );\n },\n });\n },\n});\n"],"names":["uuid","WebSocket","createLegacyAuthAdapters","WebSocketServer","Router","express","errorHandler","createBackendPlugin","coreServices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8CO,MAAM,aAAc,CAAA;AAAA,EAYjB,YAAY,OAA+B,EAAA;AAXnD,IAAQ,aAAA,CAAA,IAAA,EAAA,aAAA,sBAAiD,GAGvD,EAAA,CAAA,CAAA;AACF,IAAQ,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AApDV,IAAA,IAAA,EAAA,CAAA;AA2DI,IAAA,CAAC,EAAE,WAAa,EAAA,IAAA,CAAK,aAAa,MAAQ,EAAA,IAAA,CAAK,QAAW,GAAA,OAAA,EAAA;AAE1D,IAAK,CAAA,EAAA,GAAA,IAAA,CAAA,WAAA,KAAL,mBAAkB,SAAU,CAAA;AAAA,MAC1B,mBAAA,EAAqB,MAAM,CAAC,SAAS,CAAA;AAAA,MACrC,OAAS,EAAA,CAAC,MACR,KAAA,IAAA,CAAK,mBAAmB,MAAM,CAAA;AAAA,KAClC,CAAA,CAAA;AAAA,GACF;AAAA,EAZA,OAAO,OAAO,OAA+B,EAAA;AAC3C,IAAO,OAAA,IAAI,cAAc,OAAO,CAAA,CAAA;AAAA,GAClC;AAAA,EAYA,aAAA,CAAc,IAAe,QAA8B,EAAA;AApE7D,IAAA,IAAA,EAAA,EAA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AA;AAAA,OAGrB;AAAA,MACA,MAAM,KAAK,EAAE,UAAA,EAAY,QAAQ,QAAU,EAAA,SAAA,EAAW,QAAU,EAAA,IAAA,EAAQ,EAAA;AACtE,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAM,YAAa,CAAA;AAAA,YACjB,MAAA;AAAA,YACA,QAAA;AAAA,YACA,SAAA;AAAA,YACA,QAAA;AAAA,YACA,IAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
4
|
-
import { LoggerService } from '@backstage/backend-plugin-api';
|
|
4
|
+
import { LoggerService, AuthService, UserInfoService } from '@backstage/backend-plugin-api';
|
|
5
5
|
import { IdentityApi } from '@backstage/plugin-auth-node';
|
|
6
6
|
import { EventBroker } from '@backstage/plugin-events-node';
|
|
7
7
|
|
|
@@ -11,6 +11,8 @@ interface RouterOptions {
|
|
|
11
11
|
eventBroker?: EventBroker;
|
|
12
12
|
identity: IdentityApi;
|
|
13
13
|
discovery: PluginEndpointDiscovery;
|
|
14
|
+
auth?: AuthService;
|
|
15
|
+
userInfo?: UserInfoService;
|
|
14
16
|
}
|
|
15
17
|
/** @public */
|
|
16
18
|
declare function createRouter(options: RouterOptions): Promise<express.Router>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-signals-backend",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20240229020904",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"postpack": "backstage-cli package postpack"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@backstage/backend-common": "^0.0.0-nightly-
|
|
31
|
-
"@backstage/backend-plugin-api": "^0.0.0-nightly-
|
|
32
|
-
"@backstage/config": "^0.0.0-nightly-
|
|
33
|
-
"@backstage/plugin-auth-node": "^0.0.0-nightly-
|
|
34
|
-
"@backstage/plugin-events-node": "^0.0.0-nightly-
|
|
35
|
-
"@backstage/plugin-signals-node": "^0.0.0-nightly-
|
|
30
|
+
"@backstage/backend-common": "^0.0.0-nightly-20240229020904",
|
|
31
|
+
"@backstage/backend-plugin-api": "^0.0.0-nightly-20240229020904",
|
|
32
|
+
"@backstage/config": "^0.0.0-nightly-20240229020904",
|
|
33
|
+
"@backstage/plugin-auth-node": "^0.0.0-nightly-20240229020904",
|
|
34
|
+
"@backstage/plugin-events-node": "^0.0.0-nightly-20240229020904",
|
|
35
|
+
"@backstage/plugin-signals-node": "^0.0.0-nightly-20240229020904",
|
|
36
36
|
"@backstage/types": "^1.1.1",
|
|
37
37
|
"@types/express": "*",
|
|
38
38
|
"express": "^4.17.1",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"yn": "^4.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@backstage/cli": "^0.0.0-nightly-
|
|
48
|
+
"@backstage/cli": "^0.0.0-nightly-20240229020904",
|
|
49
49
|
"@types/supertest": "^2.0.8",
|
|
50
50
|
"msw": "^1.0.0",
|
|
51
51
|
"supertest": "^6.2.4"
|