Skip to content

Commit 1a45fcf

Browse files
committed
Use request data directly
1 parent 5c56ca2 commit 1a45fcf

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:12.10.0-alpine
22

3-
LABEL "version"="0.1.3"
3+
LABEL "version"="0.1.4"
44
LABEL "repository"="https://github.com/Greenlight-Simulation/secure-actions-webhook"
55
LABEL "homepage"="https://github.com/Greenlight-Simulation/secure-actions-webhook"
66
LABEL "maintainer"="Dan Marcucci <[email protected]>"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Sending a string:
88

99
```yaml
1010
- name: Webhook
11-
uses: Greenlight-Simulation/[email protected].3
11+
uses: Greenlight-Simulation/[email protected].4
1212
env:
1313
REQUEST_URI: ${{ secrets.REQUEST_URI }}
1414
REQUEST_DATA: "something_interesting"
@@ -19,7 +19,7 @@ Sending a json string:
1919
2020
```yaml
2121
- name: Webhook
22-
uses: Greenlight-Simulation/[email protected].3
22+
uses: Greenlight-Simulation/[email protected].4
2323
env:
2424
REQUEST_URI: ${{ secrets.REQUEST_URI }}
2525
REQUEST_DATA: '{ "something": "interesting" }'

main.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ const createHmacSignature = body => {
1313
return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(JSON.stringify(body), hmacSecret));
1414
};
1515

16-
function isJsonString(str) {
17-
try {
18-
const json = JSON.parse(str);
19-
return typeof json === "object";
20-
} catch (e) {
21-
return false;
22-
}
16+
try {
17+
JSON.parse(process.env.REQUEST_DATA);
18+
} catch (e) {
19+
console.error(`REQUEST_DATA (${process.env.REQUEST_DATA}) is not a valid JSON string.`);
20+
process.exit(1);
2321
}
2422

2523
const uri = process.env.REQUEST_URI;
26-
const data = {
27-
data: isJsonString(process.env.REQUEST_DATA) ? JSON.parse(process.env.REQUEST_DATA) : process.env.REQUEST_DATA
28-
};
29-
24+
const data = JSON.parse(process.env.REQUEST_DATA);
3025
const signature = createHmacSignature(data);
3126

3227
request(
@@ -42,7 +37,6 @@ request(
4237
// Something went wrong
4338
console.error(`Request failed with status code ${response.statusCode}!`);
4439
console.error(response.body);
45-
4640
process.exit(1);
4741
} else {
4842
// Success

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "secure-actions-webhook",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Github Actions secure webhook",
55
"main": "main.js",
66
"dependencies": {

0 commit comments

Comments
 (0)