@backstage/plugin-events-backend-module-github 0.1.22 → 0.2.0-next.0

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 CHANGED
@@ -1,20 +1,83 @@
1
1
  # @backstage/plugin-events-backend-module-github
2
2
 
3
- ## 0.1.22
3
+ ## 0.2.0-next.0
4
4
 
5
- ### Patch Changes
6
-
7
- - Updated dependencies
8
- - @backstage/backend-plugin-api@0.6.12
9
- - @backstage/plugin-events-node@0.2.21
10
-
11
- ## 0.1.21
12
-
13
- ### Patch Changes
5
+ ### Minor Changes
14
6
 
15
- - Updated dependencies
16
- - @backstage/backend-plugin-api@0.6.11
17
- - @backstage/plugin-events-node@0.2.20
7
+ - eff3ca9: BREAKING CHANGE: Migrate `EventRouter` implementations from `EventBroker` to `EventsService`.
8
+
9
+ `EventRouter` uses the new `EventsService` instead of the `EventBroker` now,
10
+ causing a breaking change to its signature.
11
+
12
+ All of its extensions and implementations got adjusted accordingly.
13
+ (`SubTopicEventRouter`, `AzureDevOpsEventRouter`, `BitbucketCloudEventRouter`,
14
+ `GerritEventRouter`, `GithubEventRouter`, `GitlabEventRouter`)
15
+
16
+ Required adjustments were made to all backend modules for the new backend system,
17
+ now also making use of the `eventsServiceRef` instead of the `eventsExtensionPoint`.
18
+
19
+ **Migration:**
20
+
21
+ Example for implementations of `SubTopicEventRouter`:
22
+
23
+ ```diff
24
+ import {
25
+ EventParams,
26
+ + EventsService,
27
+ SubTopicEventRouter,
28
+ } from '@backstage/plugin-events-node';
29
+
30
+ export class GithubEventRouter extends SubTopicEventRouter {
31
+ - constructor() {
32
+ - super('github');
33
+ + constructor(options: { events: EventsService }) {
34
+ + super({
35
+ + events: options.events,
36
+ + topic: 'github',
37
+ + });
38
+ }
39
+
40
+ + protected getSubscriberId(): string {
41
+ + return 'GithubEventRouter';
42
+ + }
43
+ +
44
+ // ...
45
+ }
46
+ ```
47
+
48
+ Example for a direct extension of `EventRouter`:
49
+
50
+ ```diff
51
+ class MyEventRouter extends EventRouter {
52
+ - constructor(/* ... */) {
53
+ + constructor(options: {
54
+ + events: EventsService;
55
+ + // ...
56
+ + }) {
57
+ - super();
58
+ // ...
59
+ + super({
60
+ + events: options.events,
61
+ + topics: topics,
62
+ + });
63
+ }
64
+ +
65
+ + protected getSubscriberId(): string {
66
+ + return 'MyEventRouter';
67
+ + }
68
+ -
69
+ - supportsEventTopics(): string[] {
70
+ - return this.topics;
71
+ - }
72
+ }
73
+ ```
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies
78
+ - @backstage/plugin-events-node@0.3.0-next.0
79
+ - @backstage/backend-plugin-api@0.6.13-next.0
80
+ - @backstage/config@1.1.2-next.0
18
81
 
19
82
  ## 0.1.20
20
83
 
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # events-backend-module-github
2
2
 
3
- Welcome to the `events-backend-module-github` backend plugin!
3
+ Welcome to the `events-backend-module-github` backend module!
4
4
 
5
- This plugin is a module for the `events-backend` backend plugin
6
- and extends it with an `GithubEventRouter`.
5
+ This package is a module for the `events-backend` backend plugin
6
+ and extends the event system with an `GithubEventRouter`.
7
7
 
8
8
  The event router will subscribe to the topic `github`
9
9
  and route the events to more concrete topics based on the value
@@ -22,37 +22,49 @@ Please find all possible webhook event types at the
22
22
 
23
23
  ## Installation
24
24
 
25
- Install the [`events-backend` plugin](../events-backend/README.md).
26
-
27
- Install this module:
28
-
29
25
  ```bash
30
26
  # From your Backstage root directory
31
27
  yarn --cwd packages/backend add @backstage/plugin-events-backend-module-github
32
28
  ```
33
29
 
34
- Add the event router to the `EventsBackend` instance in `packages/backend/src/plugins/events.ts`:
30
+ ### Event Router
35
31
 
36
- ```diff
37
- +const githubEventRouter = new GithubEventRouter();
32
+ ```ts
33
+ // packages/backend/src/index.ts
34
+ import { eventsModuleGithubEventRouter } from '@backstage/plugin-events-backend-module-github/alpha';
35
+ // ...
36
+ backend.add(eventsModuleGithubEventRouter());
37
+ ```
38
38
 
39
- new EventsBackend(env.logger)
40
- + .addPublishers(githubEventRouter)
41
- + .addSubscribers(githubEventRouter);
42
- // [...]
39
+ #### Legacy Backend System
40
+
41
+ ```ts
42
+ // packages/backend/src/plugins/events.ts
43
+ const eventRouter = new GithubEventRouter({ events: env.events });
44
+ await eventRouter.subscribe();
43
45
  ```
44
46
 
45
47
  ### Signature Validator
46
48
 
49
+ ```ts
50
+ // packages/backend/src/index.ts
51
+ import { eventsModuleGithubWebhook } from '@backstage/plugin-events-backend-module-github/alpha';
52
+ // ...
53
+ backend.add(eventsModuleGithubWebhook());
54
+ ```
55
+
56
+ #### Legacy Backend System
57
+
47
58
  Add the signature validator for the topic `github`:
48
59
 
49
60
  ```diff
50
- // at packages/backend/src/plugins/events.ts
61
+ // packages/backend/src/plugins/events.ts
51
62
  + import { createGithubSignatureValidator } from '@backstage/plugin-events-backend-module-github';
52
- // [...]
53
- const http = HttpPostIngressEventPublisher.fromConfig({
54
- config: env.config,
55
- ingresses: {
63
+ // [...]
64
+ const http = HttpPostIngressEventPublisher.fromConfig({
65
+ config: env.config,
66
+ events: env.events,
67
+ ingresses: {
56
68
  + github: {
57
69
  + validator: createGithubSignatureValidator(env.config),
58
70
  + },
@@ -61,7 +73,7 @@ Add the signature validator for the topic `github`:
61
73
  });
62
74
  ```
63
75
 
64
- Additionally, you need to add the configuration:
76
+ ## Configuration
65
77
 
66
78
  ```yaml
67
79
  events:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend-module-github",
3
- "version": "0.1.22",
3
+ "version": "0.2.0-next.0",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
+ var pluginEventsNode = require('@backstage/plugin-events-node');
7
+ var GithubEventRouter = require('./cjs/GithubEventRouter-a54f8eae.cjs.js');
6
8
  var alpha = require('@backstage/plugin-events-node/alpha');
7
- var GithubEventRouter = require('./cjs/GithubEventRouter-21610cd1.cjs.js');
8
9
  require('@octokit/webhooks-methods');
9
- require('@backstage/plugin-events-node');
10
10
 
11
11
  const eventsModuleGithubEventRouter = backendPluginApi.createBackendModule({
12
12
  pluginId: "events",
@@ -14,12 +14,11 @@ const eventsModuleGithubEventRouter = backendPluginApi.createBackendModule({
14
14
  register(env) {
15
15
  env.registerInit({
16
16
  deps: {
17
- events: alpha.eventsExtensionPoint
17
+ events: pluginEventsNode.eventsServiceRef
18
18
  },
19
19
  async init({ events }) {
20
- const eventRouter = new GithubEventRouter.GithubEventRouter();
21
- events.addPublishers(eventRouter);
22
- events.addSubscribers(eventRouter);
20
+ const eventRouter = new GithubEventRouter.GithubEventRouter({ events });
21
+ await eventRouter.subscribe();
23
22
  }
24
23
  });
25
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/service/eventsModuleGithubEventRouter.ts","../src/service/eventsModuleGithubWebhook.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport { eventsExtensionPoint } from '@backstage/plugin-events-node/alpha';\nimport { GithubEventRouter } from '../router/GithubEventRouter';\n\n/**\n * Module for the events-backend plugin, adding an event router for GitHub.\n *\n * Registers the `GithubEventRouter`.\n *\n * @alpha\n */\nexport const eventsModuleGithubEventRouter = createBackendModule({\n pluginId: 'events',\n moduleId: 'github-event-router',\n register(env) {\n env.registerInit({\n deps: {\n events: eventsExtensionPoint,\n },\n async init({ events }) {\n const eventRouter = new GithubEventRouter();\n\n events.addPublishers(eventRouter);\n events.addSubscribers(eventRouter);\n },\n });\n },\n});\n","/*\n * Copyright 2022 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 */\n\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { eventsExtensionPoint } from '@backstage/plugin-events-node/alpha';\nimport { createGithubSignatureValidator } from '../http/createGithubSignatureValidator';\n\n/**\n * Module for the events-backend plugin,\n * registering an HTTP POST ingress with request validator\n * which verifies the webhook signature based on a secret.\n *\n * @alpha\n */\nexport const eventsModuleGithubWebhook = createBackendModule({\n pluginId: 'events',\n moduleId: 'github-webhook',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsExtensionPoint,\n },\n async init({ config, events }) {\n events.addHttpPostIngress({\n topic: 'github',\n validator: createGithubSignatureValidator(config),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","eventsExtensionPoint","GithubEventRouter","coreServices","createGithubSignatureValidator"],"mappings":";;;;;;;;;;AA2BO,MAAM,gCAAgCA,oCAAoB,CAAA;AAAA,EAC/D,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,qBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,MAAQ,EAAAC,0BAAA;AAAA,OACV;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAU,EAAA;AACrB,QAAM,MAAA,WAAA,GAAc,IAAIC,mCAAkB,EAAA,CAAA;AAE1C,QAAA,MAAA,CAAO,cAAc,WAAW,CAAA,CAAA;AAChC,QAAA,MAAA,CAAO,eAAe,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;ACbM,MAAM,4BAA4BF,oCAAoB,CAAA;AAAA,EAC3D,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,gBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQG,6BAAa,CAAA,UAAA;AAAA,QACrB,MAAQ,EAAAF,0BAAA;AAAA,OACV;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,QAAU,EAAA;AAC7B,QAAA,MAAA,CAAO,kBAAmB,CAAA;AAAA,UACxB,KAAO,EAAA,QAAA;AAAA,UACP,SAAA,EAAWG,iDAA+B,MAAM,CAAA;AAAA,SACjD,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/service/eventsModuleGithubEventRouter.ts","../src/service/eventsModuleGithubWebhook.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport { eventsServiceRef } from '@backstage/plugin-events-node';\nimport { GithubEventRouter } from '../router/GithubEventRouter';\n\n/**\n * Module for the events-backend plugin, adding an event router for GitHub.\n *\n * Registers the `GithubEventRouter`.\n *\n * @alpha\n */\nexport const eventsModuleGithubEventRouter = createBackendModule({\n pluginId: 'events',\n moduleId: 'github-event-router',\n register(env) {\n env.registerInit({\n deps: {\n events: eventsServiceRef,\n },\n async init({ events }) {\n const eventRouter = new GithubEventRouter({ events });\n await eventRouter.subscribe();\n },\n });\n },\n});\n","/*\n * Copyright 2022 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 */\n\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { eventsExtensionPoint } from '@backstage/plugin-events-node/alpha';\nimport { createGithubSignatureValidator } from '../http/createGithubSignatureValidator';\n\n/**\n * Module for the events-backend plugin,\n * registering an HTTP POST ingress with request validator\n * which verifies the webhook signature based on a secret.\n *\n * @alpha\n */\nexport const eventsModuleGithubWebhook = createBackendModule({\n pluginId: 'events',\n moduleId: 'github-webhook',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n events: eventsExtensionPoint,\n },\n async init({ config, events }) {\n events.addHttpPostIngress({\n topic: 'github',\n validator: createGithubSignatureValidator(config),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","eventsServiceRef","GithubEventRouter","coreServices","eventsExtensionPoint","createGithubSignatureValidator"],"mappings":";;;;;;;;;;AA2BO,MAAM,gCAAgCA,oCAAoB,CAAA;AAAA,EAC/D,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,qBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,MAAQ,EAAAC,iCAAA;AAAA,OACV;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAU,EAAA;AACrB,QAAA,MAAM,WAAc,GAAA,IAAIC,mCAAkB,CAAA,EAAE,QAAQ,CAAA,CAAA;AACpD,QAAA,MAAM,YAAY,SAAU,EAAA,CAAA;AAAA,OAC9B;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;ACXM,MAAM,4BAA4BF,oCAAoB,CAAA;AAAA,EAC3D,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,gBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQG,6BAAa,CAAA,UAAA;AAAA,QACrB,MAAQ,EAAAC,0BAAA;AAAA,OACV;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,QAAU,EAAA;AAC7B,QAAA,MAAA,CAAO,kBAAmB,CAAA;AAAA,UACxB,KAAO,EAAA,QAAA;AAAA,UACP,SAAA,EAAWC,iDAA+B,MAAM,CAAA;AAAA,SACjD,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
@@ -17,8 +17,14 @@ function createGithubSignatureValidator(config) {
17
17
  }
18
18
 
19
19
  class GithubEventRouter extends pluginEventsNode.SubTopicEventRouter {
20
- constructor() {
21
- super("github");
20
+ constructor(options) {
21
+ super({
22
+ events: options.events,
23
+ topic: "github"
24
+ });
25
+ }
26
+ getSubscriberId() {
27
+ return "GithubEventRouter";
22
28
  }
23
29
  determineSubTopic(params) {
24
30
  var _a;
@@ -28,4 +34,4 @@ class GithubEventRouter extends pluginEventsNode.SubTopicEventRouter {
28
34
 
29
35
  exports.GithubEventRouter = GithubEventRouter;
30
36
  exports.createGithubSignatureValidator = createGithubSignatureValidator;
31
- //# sourceMappingURL=GithubEventRouter-21610cd1.cjs.js.map
37
+ //# sourceMappingURL=GithubEventRouter-a54f8eae.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GithubEventRouter-21610cd1.cjs.js","sources":["../../src/http/createGithubSignatureValidator.ts","../../src/router/GithubEventRouter.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { Config } from '@backstage/config';\nimport {\n RequestDetails,\n RequestValidationContext,\n RequestValidator,\n} from '@backstage/plugin-events-node';\nimport { verify } from '@octokit/webhooks-methods';\n\n/**\n * Validates that the request received is the expected GitHub request\n * using the signature received with the `x-hub-signature-256` header\n * which is based on a secret token configured at GitHub and here.\n *\n * See https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks\n * for more details.\n *\n * @param config - root config\n * @public\n */\nexport function createGithubSignatureValidator(\n config: Config,\n): RequestValidator {\n const secret = config.getString('events.modules.github.webhookSecret');\n\n return async (\n request: RequestDetails,\n context: RequestValidationContext,\n ): Promise<void> => {\n const signature = request.headers['x-hub-signature-256'] as\n | string\n | undefined;\n\n if (\n !signature ||\n !(await verify(secret, JSON.stringify(request.body), signature))\n ) {\n context.reject({\n status: 403,\n payload: { message: 'invalid signature' },\n });\n }\n };\n}\n","/*\n * Copyright 2022 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 */\n\nimport {\n EventParams,\n SubTopicEventRouter,\n} from '@backstage/plugin-events-node';\n\n/**\n * Subscribes to the generic `github` topic\n * and publishes the events under the more concrete sub-topic\n * depending on the `x-github-event` provided.\n *\n * @public\n */\nexport class GithubEventRouter extends SubTopicEventRouter {\n constructor() {\n super('github');\n }\n\n protected determineSubTopic(params: EventParams): string | undefined {\n return params.metadata?.['x-github-event'] as string | undefined;\n }\n}\n"],"names":["verify","SubTopicEventRouter"],"mappings":";;;;;AAmCO,SAAS,+BACd,MACkB,EAAA;AAClB,EAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,qCAAqC,CAAA,CAAA;AAErE,EAAO,OAAA,OACL,SACA,OACkB,KAAA;AAClB,IAAM,MAAA,SAAA,GAAY,OAAQ,CAAA,OAAA,CAAQ,qBAAqB,CAAA,CAAA;AAIvD,IAAA,IACE,CAAC,SAAA,IACD,CAAE,MAAMA,sBAAO,CAAA,MAAA,EAAQ,IAAK,CAAA,SAAA,CAAU,OAAQ,CAAA,IAAI,CAAG,EAAA,SAAS,CAC9D,EAAA;AACA,MAAA,OAAA,CAAQ,MAAO,CAAA;AAAA,QACb,MAAQ,EAAA,GAAA;AAAA,QACR,OAAA,EAAS,EAAE,OAAA,EAAS,mBAAoB,EAAA;AAAA,OACzC,CAAA,CAAA;AAAA,KACH;AAAA,GACF,CAAA;AACF;;AC9BO,MAAM,0BAA0BC,oCAAoB,CAAA;AAAA,EACzD,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,QAAQ,CAAA,CAAA;AAAA,GAChB;AAAA,EAEU,kBAAkB,MAAyC,EAAA;AAjCvE,IAAA,IAAA,EAAA,CAAA;AAkCI,IAAO,OAAA,CAAA,EAAA,GAAA,MAAA,CAAO,aAAP,IAAkB,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,gBAAA,CAAA,CAAA;AAAA,GAC3B;AACF;;;;;"}
1
+ {"version":3,"file":"GithubEventRouter-a54f8eae.cjs.js","sources":["../../src/http/createGithubSignatureValidator.ts","../../src/router/GithubEventRouter.ts"],"sourcesContent":["/*\n * Copyright 2022 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 */\n\nimport { Config } from '@backstage/config';\nimport {\n RequestDetails,\n RequestValidationContext,\n RequestValidator,\n} from '@backstage/plugin-events-node';\nimport { verify } from '@octokit/webhooks-methods';\n\n/**\n * Validates that the request received is the expected GitHub request\n * using the signature received with the `x-hub-signature-256` header\n * which is based on a secret token configured at GitHub and here.\n *\n * See https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks\n * for more details.\n *\n * @param config - root config\n * @public\n */\nexport function createGithubSignatureValidator(\n config: Config,\n): RequestValidator {\n const secret = config.getString('events.modules.github.webhookSecret');\n\n return async (\n request: RequestDetails,\n context: RequestValidationContext,\n ): Promise<void> => {\n const signature = request.headers['x-hub-signature-256'] as\n | string\n | undefined;\n\n if (\n !signature ||\n !(await verify(secret, JSON.stringify(request.body), signature))\n ) {\n context.reject({\n status: 403,\n payload: { message: 'invalid signature' },\n });\n }\n };\n}\n","/*\n * Copyright 2022 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 */\n\nimport {\n EventParams,\n EventsService,\n SubTopicEventRouter,\n} from '@backstage/plugin-events-node';\n\n/**\n * Subscribes to the generic `github` topic\n * and publishes the events under the more concrete sub-topic\n * depending on the `x-github-event` provided.\n *\n * @public\n */\nexport class GithubEventRouter extends SubTopicEventRouter {\n constructor(options: { events: EventsService }) {\n super({\n events: options.events,\n topic: 'github',\n });\n }\n\n protected getSubscriberId(): string {\n return 'GithubEventRouter';\n }\n\n protected determineSubTopic(params: EventParams): string | undefined {\n return params.metadata?.['x-github-event'] as string | undefined;\n }\n}\n"],"names":["verify","SubTopicEventRouter"],"mappings":";;;;;AAmCO,SAAS,+BACd,MACkB,EAAA;AAClB,EAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,qCAAqC,CAAA,CAAA;AAErE,EAAO,OAAA,OACL,SACA,OACkB,KAAA;AAClB,IAAM,MAAA,SAAA,GAAY,OAAQ,CAAA,OAAA,CAAQ,qBAAqB,CAAA,CAAA;AAIvD,IAAA,IACE,CAAC,SAAA,IACD,CAAE,MAAMA,sBAAO,CAAA,MAAA,EAAQ,IAAK,CAAA,SAAA,CAAU,OAAQ,CAAA,IAAI,CAAG,EAAA,SAAS,CAC9D,EAAA;AACA,MAAA,OAAA,CAAQ,MAAO,CAAA;AAAA,QACb,MAAQ,EAAA,GAAA;AAAA,QACR,OAAA,EAAS,EAAE,OAAA,EAAS,mBAAoB,EAAA;AAAA,OACzC,CAAA,CAAA;AAAA,KACH;AAAA,GACF,CAAA;AACF;;AC7BO,MAAM,0BAA0BC,oCAAoB,CAAA;AAAA,EACzD,YAAY,OAAoC,EAAA;AAC9C,IAAM,KAAA,CAAA;AAAA,MACJ,QAAQ,OAAQ,CAAA,MAAA;AAAA,MAChB,KAAO,EAAA,QAAA;AAAA,KACR,CAAA,CAAA;AAAA,GACH;AAAA,EAEU,eAA0B,GAAA;AAClC,IAAO,OAAA,mBAAA,CAAA;AAAA,GACT;AAAA,EAEU,kBAAkB,MAAyC,EAAA;AAzCvE,IAAA,IAAA,EAAA,CAAA;AA0CI,IAAO,OAAA,CAAA,EAAA,GAAA,MAAA,CAAO,aAAP,IAAkB,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,gBAAA,CAAA,CAAA;AAAA,GAC3B;AACF;;;;;"}
package/dist/index.cjs.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var GithubEventRouter = require('./cjs/GithubEventRouter-21610cd1.cjs.js');
5
+ var GithubEventRouter = require('./cjs/GithubEventRouter-a54f8eae.cjs.js');
6
6
  require('@octokit/webhooks-methods');
7
7
  require('@backstage/plugin-events-node');
8
8
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Config } from '@backstage/config';
2
- import { RequestValidator, SubTopicEventRouter, EventParams } from '@backstage/plugin-events-node';
2
+ import { RequestValidator, SubTopicEventRouter, EventsService, EventParams } from '@backstage/plugin-events-node';
3
3
 
4
4
  /**
5
5
  * Validates that the request received is the expected GitHub request
@@ -22,7 +22,10 @@ declare function createGithubSignatureValidator(config: Config): RequestValidato
22
22
  * @public
23
23
  */
24
24
  declare class GithubEventRouter extends SubTopicEventRouter {
25
- constructor();
25
+ constructor(options: {
26
+ events: EventsService;
27
+ });
28
+ protected getSubscriberId(): string;
26
29
  protected determineSubTopic(params: EventParams): string | undefined;
27
30
  }
28
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend-module-github",
3
- "version": "0.1.22",
3
+ "version": "0.2.0-next.0",
4
4
  "main": "./dist/index.cjs.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -39,16 +39,15 @@
39
39
  "postpack": "backstage-cli package postpack"
40
40
  },
41
41
  "dependencies": {
42
- "@backstage/backend-plugin-api": "^0.6.12",
43
- "@backstage/config": "^1.1.1",
44
- "@backstage/plugin-events-node": "^0.2.21",
45
- "@octokit/webhooks-methods": "^3.0.0",
46
- "winston": "^3.2.1"
42
+ "@backstage/backend-plugin-api": "^0.6.13-next.0",
43
+ "@backstage/config": "^1.1.2-next.0",
44
+ "@backstage/plugin-events-node": "^0.3.0-next.0",
45
+ "@octokit/webhooks-methods": "^3.0.0"
47
46
  },
48
47
  "devDependencies": {
49
- "@backstage/backend-test-utils": "^0.3.2",
50
- "@backstage/cli": "^0.25.2",
51
- "@backstage/plugin-events-backend-test-utils": "^0.1.22"
48
+ "@backstage/backend-test-utils": "^0.3.3-next.0",
49
+ "@backstage/cli": "^0.25.3-next.0",
50
+ "@backstage/plugin-events-backend-test-utils": "^0.1.23-next.0"
52
51
  },
53
52
  "files": [
54
53
  "config.d.ts",