@backstage/plugin-events-backend-module-gitlab 0.1.5 → 0.1.6-next.1
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 +18 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +4 -29
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/cjs/GitlabEventRouter-0fd716a9.cjs.js +33 -0
- package/dist/cjs/GitlabEventRouter-0fd716a9.cjs.js.map +1 -0
- package/dist/index.cjs.js +4 -27
- package/dist/index.cjs.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @backstage/plugin-events-backend-module-gitlab
|
|
2
2
|
|
|
3
|
+
## 0.1.6-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/backend-plugin-api@0.5.1-next.1
|
|
9
|
+
- @backstage/config@1.0.7
|
|
10
|
+
- @backstage/plugin-events-node@0.2.5-next.1
|
|
11
|
+
|
|
12
|
+
## 0.1.6-next.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @backstage/config@1.0.7
|
|
18
|
+
- @backstage/backend-plugin-api@0.5.1-next.0
|
|
19
|
+
- @backstage/plugin-events-node@0.2.5-next.0
|
|
20
|
+
|
|
3
21
|
## 0.1.5
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/alpha.cjs.js
CHANGED
|
@@ -4,20 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
6
|
var alpha = require('@backstage/plugin-events-node/alpha');
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
class GitlabEventRouter extends pluginEventsNode.SubTopicEventRouter {
|
|
10
|
-
constructor() {
|
|
11
|
-
super("gitlab");
|
|
12
|
-
}
|
|
13
|
-
determineSubTopic(params) {
|
|
14
|
-
if ("event_name" in params.eventPayload) {
|
|
15
|
-
const payload = params.eventPayload;
|
|
16
|
-
return payload.event_name;
|
|
17
|
-
}
|
|
18
|
-
return void 0;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
7
|
+
var GitlabEventRouter = require('./cjs/GitlabEventRouter-0fd716a9.cjs.js');
|
|
8
|
+
require('@backstage/plugin-events-node');
|
|
21
9
|
|
|
22
10
|
const eventsModuleGitlabEventRouter = backendPluginApi.createBackendModule({
|
|
23
11
|
pluginId: "events",
|
|
@@ -28,7 +16,7 @@ const eventsModuleGitlabEventRouter = backendPluginApi.createBackendModule({
|
|
|
28
16
|
events: alpha.eventsExtensionPoint
|
|
29
17
|
},
|
|
30
18
|
async init({ events }) {
|
|
31
|
-
const eventRouter = new GitlabEventRouter();
|
|
19
|
+
const eventRouter = new GitlabEventRouter.GitlabEventRouter();
|
|
32
20
|
events.addPublishers(eventRouter);
|
|
33
21
|
events.addSubscribers(eventRouter);
|
|
34
22
|
}
|
|
@@ -36,19 +24,6 @@ const eventsModuleGitlabEventRouter = backendPluginApi.createBackendModule({
|
|
|
36
24
|
}
|
|
37
25
|
});
|
|
38
26
|
|
|
39
|
-
function createGitlabTokenValidator(config) {
|
|
40
|
-
const secret = config.getString("events.modules.gitlab.webhookSecret");
|
|
41
|
-
return async (request, context) => {
|
|
42
|
-
const token = request.headers["x-gitlab-token"];
|
|
43
|
-
if (secret !== token) {
|
|
44
|
-
context.reject({
|
|
45
|
-
status: 403,
|
|
46
|
-
payload: { message: "invalid token" }
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
27
|
const eventsModuleGitlabWebhook = backendPluginApi.createBackendModule({
|
|
53
28
|
pluginId: "events",
|
|
54
29
|
moduleId: "gitlabWebhook",
|
|
@@ -61,7 +36,7 @@ const eventsModuleGitlabWebhook = backendPluginApi.createBackendModule({
|
|
|
61
36
|
async init({ config, events }) {
|
|
62
37
|
events.addHttpPostIngress({
|
|
63
38
|
topic: "gitlab",
|
|
64
|
-
validator: createGitlabTokenValidator(config)
|
|
39
|
+
validator: GitlabEventRouter.createGitlabTokenValidator(config)
|
|
65
40
|
});
|
|
66
41
|
}
|
|
67
42
|
});
|
package/dist/alpha.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alpha.cjs.js","sources":["../src/
|
|
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: 'gitlabEventRouter',\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: 'gitlabWebhook',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.config,\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,mBAAA;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,eAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQG,6BAAa,CAAA,MAAA;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;;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pluginEventsNode = require('@backstage/plugin-events-node');
|
|
4
|
+
|
|
5
|
+
function createGitlabTokenValidator(config) {
|
|
6
|
+
const secret = config.getString("events.modules.gitlab.webhookSecret");
|
|
7
|
+
return async (request, context) => {
|
|
8
|
+
const token = request.headers["x-gitlab-token"];
|
|
9
|
+
if (secret !== token) {
|
|
10
|
+
context.reject({
|
|
11
|
+
status: 403,
|
|
12
|
+
payload: { message: "invalid token" }
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class GitlabEventRouter extends pluginEventsNode.SubTopicEventRouter {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("gitlab");
|
|
21
|
+
}
|
|
22
|
+
determineSubTopic(params) {
|
|
23
|
+
if ("event_name" in params.eventPayload) {
|
|
24
|
+
const payload = params.eventPayload;
|
|
25
|
+
return payload.event_name;
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.GitlabEventRouter = GitlabEventRouter;
|
|
32
|
+
exports.createGitlabTokenValidator = createGitlabTokenValidator;
|
|
33
|
+
//# sourceMappingURL=GitlabEventRouter-0fd716a9.cjs.js.map
|
|
@@ -0,0 +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;;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,34 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var GitlabEventRouter = require('./cjs/GitlabEventRouter-0fd716a9.cjs.js');
|
|
6
|
+
require('@backstage/plugin-events-node');
|
|
6
7
|
|
|
7
|
-
function createGitlabTokenValidator(config) {
|
|
8
|
-
const secret = config.getString("events.modules.gitlab.webhookSecret");
|
|
9
|
-
return async (request, context) => {
|
|
10
|
-
const token = request.headers["x-gitlab-token"];
|
|
11
|
-
if (secret !== token) {
|
|
12
|
-
context.reject({
|
|
13
|
-
status: 403,
|
|
14
|
-
payload: { message: "invalid token" }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
8
|
|
|
20
|
-
class GitlabEventRouter extends pluginEventsNode.SubTopicEventRouter {
|
|
21
|
-
constructor() {
|
|
22
|
-
super("gitlab");
|
|
23
|
-
}
|
|
24
|
-
determineSubTopic(params) {
|
|
25
|
-
if ("event_name" in params.eventPayload) {
|
|
26
|
-
const payload = params.eventPayload;
|
|
27
|
-
return payload.event_name;
|
|
28
|
-
}
|
|
29
|
-
return void 0;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
9
|
|
|
33
|
-
exports.GitlabEventRouter = GitlabEventRouter;
|
|
34
|
-
exports.createGitlabTokenValidator = createGitlabTokenValidator;
|
|
10
|
+
exports.GitlabEventRouter = GitlabEventRouter.GitlabEventRouter;
|
|
11
|
+
exports.createGitlabTokenValidator = GitlabEventRouter.createGitlabTokenValidator;
|
|
35
12
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-events-backend-module-gitlab",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6-next.1",
|
|
4
4
|
"main": "./dist/index.cjs.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"postpack": "backstage-cli package postpack"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@backstage/backend-plugin-api": "^0.5.
|
|
36
|
+
"@backstage/backend-plugin-api": "^0.5.1-next.1",
|
|
37
37
|
"@backstage/config": "^1.0.7",
|
|
38
|
-
"@backstage/plugin-events-node": "^0.2.
|
|
38
|
+
"@backstage/plugin-events-node": "^0.2.5-next.1",
|
|
39
39
|
"winston": "^3.2.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@backstage/backend-test-utils": "^0.1.
|
|
43
|
-
"@backstage/cli": "^0.22.
|
|
44
|
-
"@backstage/plugin-events-backend-test-utils": "^0.1.
|
|
42
|
+
"@backstage/backend-test-utils": "^0.1.36-next.1",
|
|
43
|
+
"@backstage/cli": "^0.22.6-next.1",
|
|
44
|
+
"@backstage/plugin-events-backend-test-utils": "^0.1.6-next.1",
|
|
45
45
|
"supertest": "^6.1.3"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|