Skip to content

Commit f8cfe06

Browse files
committed
Refactor Taiga actions to utilize parseObject utility
- Added parseObject utility for tags, watchers, and points in update-issue, update-task, and update-userstory actions. - Removed the update-project action as it is no longer needed. - Enhanced base source to include secret key validation for webhook security.
1 parent 65a6c07 commit f8cfe06

File tree

7 files changed

+48
-81
lines changed

7 files changed

+48
-81
lines changed

components/taiga/actions/update-issue/update-issue.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { cleanObj } from "../../common/utils.mjs";
1+
import {
2+
cleanObj, parseObject,
3+
} from "../../common/utils.mjs";
24
import taiga from "../../taiga.app.mjs";
35

46
export default {
@@ -151,11 +153,11 @@ export default {
151153
status: this.status,
152154
type: this.type,
153155
assigned_to: this.assignedTo,
154-
tags: this.tags,
156+
tags: parseObject(this.tags),
155157
blocked_note: this.blockedNote,
156158
is_blocked: this.isBlocked,
157159
milestone: this.milestone,
158-
watchers: this.watchers,
160+
watchers: parseObject(this.watchers),
159161
project: this.projectId,
160162
}),
161163
});

components/taiga/actions/update-project/update-project.mjs

Lines changed: 0 additions & 66 deletions
This file was deleted.

components/taiga/actions/update-task/update-task.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { cleanObj } from "../../common/utils.mjs";
1+
import {
2+
cleanObj, parseObject,
3+
} from "../../common/utils.mjs";
24
import taiga from "../../taiga.app.mjs";
35

46
export default {
@@ -140,8 +142,8 @@ export default {
140142
status: this.status,
141143
assigned_to: this.assignedTo,
142144
user_story: this.userStoryId,
143-
tags: this.tags,
144-
watchers: this.watchers,
145+
tags: parseObject(this.tags),
146+
watchers: parseObject(this.watchers),
145147
is_blocked: this.isBlocked,
146148
milestone: this.milestone,
147149
us_order: this.usOrder,

components/taiga/actions/update-userstory/update-userstory.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { cleanObj } from "../../common/utils.mjs";
1+
import {
2+
cleanObj, parseObject,
3+
} from "../../common/utils.mjs";
24
import taiga from "../../taiga.app.mjs";
35

46
export default {
@@ -156,14 +158,14 @@ export default {
156158
description: this.description,
157159
status: this.status,
158160
assigned_to: this.assignedTo,
159-
tags: this.tags,
161+
tags: parseObject(this.tags),
160162
backlog_order: this.backlogOrder,
161163
client_requirement: this.clientRequirement,
162164
is_blocked: this.isBlocked,
163165
milestone: this.milestone,
164-
points: this.points,
166+
points: parseObject(this.points),
165167
team_requirement: this.teamRequirement,
166-
watchers: this.watchers,
168+
watchers: parseObject(this.watchers),
167169
}),
168170
});
169171

components/taiga/sources/changed-issue-instant/changed-issue-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
...common,
66
key: "taiga-changed-issue-instant",
77
name: "Changed Issue (Instant)",
8-
description: "Emit new event when a issue is updated in the selected project. [See the documentation](https://docs.taiga.io/api.html#webhooks-create)",
8+
description: "Emit new event when an issue is updated in the selected project. [See the documentation](https://docs.taiga.io/api.html#webhooks-create)",
99
version: "0.0.1",
1010
type: "source",
1111
dedupe: "unique",

components/taiga/sources/changed-issue-status-instant/changed-issue-status-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
...common,
66
key: "taiga-changed-issue-status-instant",
77
name: "Changed Issue Status (Instant)",
8-
description: "Emit new event when a issue status is changed in the selected project. [See the documentation](https://docs.taiga.io/api.html#webhooks-create)",
8+
description: "Emit new event when an issue status is changed in the selected project. [See the documentation](https://docs.taiga.io/api.html#webhooks-create)",
99
version: "0.0.1",
1010
type: "source",
1111
dedupe: "unique",

components/taiga/sources/common/base.mjs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ export default {
55
props: {
66
taiga,
77
db: "$.service.db",
8-
http: "$.interface.http",
8+
http: {
9+
type: "$.interface.http",
10+
customResponse: true,
11+
},
912
projectId: {
1013
propDefinition: [
1114
taiga,
@@ -25,26 +28,50 @@ export default {
2528
_getWebhookId() {
2629
return this.db.get("webhookId");
2730
},
31+
_getSecretKey() {
32+
return this.db.get("secretKey");
33+
},
34+
_setSecretKey(secretKey) {
35+
this.db.set("secretKey", secretKey);
36+
},
37+
validateSecretKey(headers, bodyRaw) {
38+
const secretKey = this._getSecretKey();
39+
const signature = headers["x-taiga-webhook-signature"];
40+
const hmac = crypto.createHmac("sha1", secretKey);
41+
hmac.update(bodyRaw);
42+
const signedMessage = hmac.digest("hex");
43+
44+
if (signature !== signedMessage) {
45+
return this.http.respond({
46+
status: 401,
47+
});
48+
}
49+
},
2850
},
2951
hooks: {
3052
async activate() {
53+
const secretKey = crypto.randomUUID();
3154
const response = await this.taiga.createHook({
3255
data: {
33-
key: crypto.randomUUID(),
56+
key: secretKey,
3457
name: this.name,
3558
url: this.http.endpoint,
3659
project: this.projectId,
3760
},
3861
});
3962
this._setWebhookId(response.id);
63+
this._setSecretKey(secretKey);
4064
},
4165
async deactivate() {
4266
const webhookId = this._getWebhookId();
4367
await this.taiga.deleteHook(webhookId);
4468
},
4569
},
46-
async run({ body }) {
70+
async run({
71+
body, headers, bodyRaw,
72+
}) {
4773
if (!this.filterEvent(body)) return;
74+
this.validateSecretKey(headers, bodyRaw);
4875

4976
const ts = body.created || Date.now();
5077
this.$emit(body, {

0 commit comments

Comments
 (0)