@backstage/plugin-events-backend-module-gitlab 0.1.21 → 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,12 +1,83 @@
1
1
  # @backstage/plugin-events-backend-module-gitlab
2
2
 
3
- ## 0.1.21
3
+ ## 0.2.0-next.0
4
4
 
5
- ### Patch Changes
5
+ ### Minor Changes
6
6
 
7
- - Updated dependencies
8
- - @backstage/backend-plugin-api@0.6.11
9
- - @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
10
81
 
11
82
  ## 0.1.20
12
83
 
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # events-backend-module-gitlab
2
2
 
3
- Welcome to the `events-backend-module-gitlab` backend plugin!
3
+ Welcome to the `events-backend-module-gitlab` backend module!
4
4
 
5
- This plugin is a module for the `events-backend` backend plugin
6
- and extends it with an `GitlabEventRouter`.
5
+ This package is a module for the `events-backend` backend plugin
6
+ and extends the event system with an `GitlabEventRouter`.
7
7
 
8
8
  The event router will subscribe to the topic `gitlab`
9
9
  and route the events to more concrete topics based on the value
@@ -21,37 +21,49 @@ Please find all possible webhook event types at the
21
21
 
22
22
  ## Installation
23
23
 
24
- Install the [`events-backend` plugin](../events-backend/README.md).
25
-
26
- Install this module:
27
-
28
24
  ```bash
29
25
  # From your Backstage root directory
30
26
  yarn --cwd packages/backend add @backstage/plugin-events-backend-module-gitlab
31
27
  ```
32
28
 
33
- Add the event router to the `EventsBackend` instance in `packages/backend/src/plugins/events.ts`:
29
+ ### Event Router
34
30
 
35
- ```diff
36
- +const gitlabEventRouter = new GitlabEventRouter();
31
+ ```ts
32
+ // packages/backend/src/index.ts
33
+ import { eventsModuleGitlabEventRouter } from '@backstage/plugin-events-backend-module-gitlab/alpha';
34
+ // ...
35
+ backend.add(eventsModuleGitlabEventRouter());
36
+ ```
37
37
 
38
- new EventsBackend(env.logger)
39
- + .addPublishers(gitlabEventRouter)
40
- + .addSubscribers(gitlabEventRouter);
41
- // [...]
38
+ #### Legacy Backend System
39
+
40
+ ```ts
41
+ // packages/backend/src/plugins/events.ts
42
+ const eventRouter = new GitlabEventRouter({ events: env.events });
43
+ await eventRouter.subscribe();
42
44
  ```
43
45
 
44
46
  ### Token Validator
45
47
 
48
+ ```ts
49
+ // packages/backend/src/index.ts
50
+ import { eventsModuleGitlabWebhook } from '@backstage/plugin-events-backend-module-gitlab/alpha';
51
+ // ...
52
+ backend.add(eventsModuleGitlabWebhook());
53
+ ```
54
+
55
+ #### Legacy Backend System
56
+
46
57
  Add the token validator for the topic `gitlab`:
47
58
 
48
59
  ```diff
49
- // at packages/backend/src/plugins/events.ts
60
+ // packages/backend/src/plugins/events.ts
50
61
  + import { createGitlabTokenValidator } from '@backstage/plugin-events-backend-module-gitlab';
51
- // [...]
52
- const http = HttpPostIngressEventPublisher.fromConfig({
53
- config: env.config,
54
- ingresses: {
62
+ // [...]
63
+ const http = HttpPostIngressEventPublisher.fromConfig({
64
+ config: env.config,
65
+ events: env.events,
66
+ ingresses: {
55
67
  + gitlab: {
56
68
  + validator: createGitlabTokenValidator(env.config),
57
69
  + },
@@ -60,7 +72,7 @@ Add the token validator for the topic `gitlab`:
60
72
  });
61
73
  ```
62
74
 
63
- Additionally, you need to add the configuration:
75
+ ## Configuration
64
76
 
65
77
  ```yaml
66
78
  events:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend-module-gitlab",
3
- "version": "0.1.21",
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,9 +3,9 @@
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 GitlabEventRouter = require('./cjs/GitlabEventRouter-7ebbf591.cjs.js');
6
8
  var alpha = require('@backstage/plugin-events-node/alpha');
7
- var GitlabEventRouter = require('./cjs/GitlabEventRouter-0fd716a9.cjs.js');
8
- require('@backstage/plugin-events-node');
9
9
 
10
10
  const eventsModuleGitlabEventRouter = backendPluginApi.createBackendModule({
11
11
  pluginId: "events",
@@ -13,12 +13,11 @@ const eventsModuleGitlabEventRouter = backendPluginApi.createBackendModule({
13
13
  register(env) {
14
14
  env.registerInit({
15
15
  deps: {
16
- events: alpha.eventsExtensionPoint
16
+ events: pluginEventsNode.eventsServiceRef
17
17
  },
18
18
  async init({ events }) {
19
- const eventRouter = new GitlabEventRouter.GitlabEventRouter();
20
- events.addPublishers(eventRouter);
21
- events.addSubscribers(eventRouter);
19
+ const eventRouter = new GitlabEventRouter.GitlabEventRouter({ events });
20
+ await eventRouter.subscribe();
22
21
  }
23
22
  });
24
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/service/eventsModuleGitlabEventRouter.ts","../src/service/eventsModuleGitlabWebhook.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 { GitlabEventRouter } from '../router/GitlabEventRouter';\n\n/**\n * Module for the events-backend plugin, adding an event router for GitLab.\n *\n * Registers the `GitlabEventRouter`.\n *\n * @alpha\n */\nexport const eventsModuleGitlabEventRouter = createBackendModule({\n pluginId: 'events',\n moduleId: 'gitlab-event-router',\n register(env) {\n env.registerInit({\n deps: {\n events: eventsExtensionPoint,\n },\n async init({ events }) {\n const eventRouter = new GitlabEventRouter();\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 { createGitlabTokenValidator } from '../http/createGitlabTokenValidator';\n\n/**\n * Module for the events-backend plugin,\n * registering an HTTP POST ingress with request validator\n * which verifies the webhook token based on a secret.\n *\n * Registers the `GitlabEventRouter`.\n *\n * @alpha\n */\nexport const eventsModuleGitlabWebhook = createBackendModule({\n pluginId: 'events',\n moduleId: 'gitlab-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: 'gitlab',\n validator: createGitlabTokenValidator(config),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","eventsExtensionPoint","GitlabEventRouter","coreServices","createGitlabTokenValidator"],"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;;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,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,6CAA2B,MAAM,CAAA;AAAA,SAC7C,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/service/eventsModuleGitlabEventRouter.ts","../src/service/eventsModuleGitlabWebhook.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 { GitlabEventRouter } from '../router/GitlabEventRouter';\n\n/**\n * Module for the events-backend plugin, adding an event router for GitLab.\n *\n * Registers the `GitlabEventRouter`.\n *\n * @alpha\n */\nexport const eventsModuleGitlabEventRouter = createBackendModule({\n pluginId: 'events',\n moduleId: 'gitlab-event-router',\n register(env) {\n env.registerInit({\n deps: {\n events: eventsServiceRef,\n },\n async init({ events }) {\n const eventRouter = new GitlabEventRouter({ events: 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 { createGitlabTokenValidator } from '../http/createGitlabTokenValidator';\n\n/**\n * Module for the events-backend plugin,\n * registering an HTTP POST ingress with request validator\n * which verifies the webhook token based on a secret.\n *\n * Registers the `GitlabEventRouter`.\n *\n * @alpha\n */\nexport const eventsModuleGitlabWebhook = createBackendModule({\n pluginId: 'events',\n moduleId: 'gitlab-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: 'gitlab',\n validator: createGitlabTokenValidator(config),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","eventsServiceRef","GitlabEventRouter","coreServices","eventsExtensionPoint","createGitlabTokenValidator"],"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,QAAgB,CAAA,CAAA;AAC5D,QAAA,MAAM,YAAY,SAAU,EAAA,CAAA;AAAA,OAC9B;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;ACTM,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,6CAA2B,MAAM,CAAA;AAAA,SAC7C,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
@@ -16,8 +16,14 @@ function createGitlabTokenValidator(config) {
16
16
  }
17
17
 
18
18
  class GitlabEventRouter extends pluginEventsNode.SubTopicEventRouter {
19
- constructor() {
20
- super("gitlab");
19
+ constructor(options) {
20
+ super({
21
+ events: options.events,
22
+ topic: "gitlab"
23
+ });
24
+ }
25
+ getSubscriberId() {
26
+ return "GitlabEventRouter";
21
27
  }
22
28
  determineSubTopic(params) {
23
29
  if ("event_name" in params.eventPayload) {
@@ -30,4 +36,4 @@ class GitlabEventRouter extends pluginEventsNode.SubTopicEventRouter {
30
36
 
31
37
  exports.GitlabEventRouter = GitlabEventRouter;
32
38
  exports.createGitlabTokenValidator = createGitlabTokenValidator;
33
- //# sourceMappingURL=GitlabEventRouter-0fd716a9.cjs.js.map
39
+ //# sourceMappingURL=GitlabEventRouter-7ebbf591.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GitlabEventRouter-0fd716a9.cjs.js","sources":["../../src/http/createGitlabTokenValidator.ts","../../src/router/GitlabEventRouter.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';\n\n/**\n * Validates a configured secret token against the token received with the `x-gitlab-token` header.\n *\n * See https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#validate-payloads-by-using-a-secret-token\n * for more details.\n *\n * @param config - root config\n * @public\n */\nexport function createGitlabTokenValidator(config: Config): RequestValidator {\n const secret = config.getString('events.modules.gitlab.webhookSecret');\n\n return async (\n request: RequestDetails,\n context: RequestValidationContext,\n ): Promise<void> => {\n const token = request.headers['x-gitlab-token'] as string | undefined;\n\n if (secret !== token) {\n context.reject({\n status: 403,\n payload: { message: 'invalid token' },\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 `gitlab` topic\n * and publishes the events under the more concrete sub-topic\n * depending on the `$.event_name` field provided.\n *\n * @public\n */\nexport class GitlabEventRouter extends SubTopicEventRouter {\n constructor() {\n super('gitlab');\n }\n\n protected determineSubTopic(params: EventParams): string | undefined {\n if ('event_name' in (params.eventPayload as object)) {\n const payload = params.eventPayload as { event_name: string };\n return payload.event_name;\n }\n\n return undefined;\n }\n}\n"],"names":["SubTopicEventRouter"],"mappings":";;;;AAgCO,SAAS,2BAA2B,MAAkC,EAAA;AAC3E,EAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,qCAAqC,CAAA,CAAA;AAErE,EAAO,OAAA,OACL,SACA,OACkB,KAAA;AAClB,IAAM,MAAA,KAAA,GAAQ,OAAQ,CAAA,OAAA,CAAQ,gBAAgB,CAAA,CAAA;AAE9C,IAAA,IAAI,WAAW,KAAO,EAAA;AACpB,MAAA,OAAA,CAAQ,MAAO,CAAA;AAAA,QACb,MAAQ,EAAA,GAAA;AAAA,QACR,OAAA,EAAS,EAAE,OAAA,EAAS,eAAgB,EAAA;AAAA,OACrC,CAAA,CAAA;AAAA,KACH;AAAA,GACF,CAAA;AACF;;ACpBO,MAAM,0BAA0BA,oCAAoB,CAAA;AAAA,EACzD,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,QAAQ,CAAA,CAAA;AAAA,GAChB;AAAA,EAEU,kBAAkB,MAAyC,EAAA;AACnE,IAAI,IAAA,YAAA,IAAiB,OAAO,YAAyB,EAAA;AACnD,MAAA,MAAM,UAAU,MAAO,CAAA,YAAA,CAAA;AACvB,MAAA,OAAO,OAAQ,CAAA,UAAA,CAAA;AAAA,KACjB;AAEA,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AACF;;;;;"}
1
+ {"version":3,"file":"GitlabEventRouter-7ebbf591.cjs.js","sources":["../../src/http/createGitlabTokenValidator.ts","../../src/router/GitlabEventRouter.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';\n\n/**\n * Validates a configured secret token against the token received with the `x-gitlab-token` header.\n *\n * See https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#validate-payloads-by-using-a-secret-token\n * for more details.\n *\n * @param config - root config\n * @public\n */\nexport function createGitlabTokenValidator(config: Config): RequestValidator {\n const secret = config.getString('events.modules.gitlab.webhookSecret');\n\n return async (\n request: RequestDetails,\n context: RequestValidationContext,\n ): Promise<void> => {\n const token = request.headers['x-gitlab-token'] as string | undefined;\n\n if (secret !== token) {\n context.reject({\n status: 403,\n payload: { message: 'invalid token' },\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 `gitlab` topic\n * and publishes the events under the more concrete sub-topic\n * depending on the `$.event_name` field provided.\n *\n * @public\n */\nexport class GitlabEventRouter extends SubTopicEventRouter {\n constructor(options: { events: EventsService }) {\n super({\n events: options.events,\n topic: 'gitlab',\n });\n }\n\n protected getSubscriberId(): string {\n return 'GitlabEventRouter';\n }\n\n protected determineSubTopic(params: EventParams): string | undefined {\n if ('event_name' in (params.eventPayload as object)) {\n const payload = params.eventPayload as { event_name: string };\n return payload.event_name;\n }\n\n return undefined;\n }\n}\n"],"names":["SubTopicEventRouter"],"mappings":";;;;AAgCO,SAAS,2BAA2B,MAAkC,EAAA;AAC3E,EAAM,MAAA,MAAA,GAAS,MAAO,CAAA,SAAA,CAAU,qCAAqC,CAAA,CAAA;AAErE,EAAO,OAAA,OACL,SACA,OACkB,KAAA;AAClB,IAAM,MAAA,KAAA,GAAQ,OAAQ,CAAA,OAAA,CAAQ,gBAAgB,CAAA,CAAA;AAE9C,IAAA,IAAI,WAAW,KAAO,EAAA;AACpB,MAAA,OAAA,CAAQ,MAAO,CAAA;AAAA,QACb,MAAQ,EAAA,GAAA;AAAA,QACR,OAAA,EAAS,EAAE,OAAA,EAAS,eAAgB,EAAA;AAAA,OACrC,CAAA,CAAA;AAAA,KACH;AAAA,GACF,CAAA;AACF;;ACnBO,MAAM,0BAA0BA,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;AACnE,IAAI,IAAA,YAAA,IAAiB,OAAO,YAAyB,EAAA;AACnD,MAAA,MAAM,UAAU,MAAO,CAAA,YAAA,CAAA;AACvB,MAAA,OAAO,OAAQ,CAAA,UAAA,CAAA;AAAA,KACjB;AAEA,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;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 GitlabEventRouter = require('./cjs/GitlabEventRouter-0fd716a9.cjs.js');
5
+ var GitlabEventRouter = require('./cjs/GitlabEventRouter-7ebbf591.cjs.js');
6
6
  require('@backstage/plugin-events-node');
7
7
 
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 a configured secret token against the token received with the `x-gitlab-token` header.
@@ -20,7 +20,10 @@ declare function createGitlabTokenValidator(config: Config): RequestValidator;
20
20
  * @public
21
21
  */
22
22
  declare class GitlabEventRouter extends SubTopicEventRouter {
23
- constructor();
23
+ constructor(options: {
24
+ events: EventsService;
25
+ });
26
+ protected getSubscriberId(): string;
24
27
  protected determineSubTopic(params: EventParams): string | undefined;
25
28
  }
26
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-events-backend-module-gitlab",
3
- "version": "0.1.21",
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,15 +39,14 @@
39
39
  "postpack": "backstage-cli package postpack"
40
40
  },
41
41
  "dependencies": {
42
- "@backstage/backend-plugin-api": "^0.6.11",
43
- "@backstage/config": "^1.1.1",
44
- "@backstage/plugin-events-node": "^0.2.20",
45
- "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"
46
45
  },
47
46
  "devDependencies": {
48
- "@backstage/backend-test-utils": "^0.3.1",
49
- "@backstage/cli": "^0.25.2",
50
- "@backstage/plugin-events-backend-test-utils": "^0.1.21"
47
+ "@backstage/backend-test-utils": "^0.3.3-next.0",
48
+ "@backstage/cli": "^0.25.3-next.0",
49
+ "@backstage/plugin-events-backend-test-utils": "^0.1.23-next.0"
51
50
  },
52
51
  "files": [
53
52
  "config.d.ts",