Skip to content

Commit 0c5b528

Browse files
author
Ybrin
committed
Initial Commit
0 parents  commit 0c5b528

File tree

7 files changed

+467
-0
lines changed

7 files changed

+467
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules/

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:12.10.0-alpine
2+
3+
LABEL "version"="0.1.0"
4+
LABEL "repository"="https://github.com/Ybrin/secure-actions-webhook"
5+
LABEL "homepage"="https://github.com/Ybrin/secure-actions-webhook"
6+
LABEL "maintainer"="Koray Koska <[email protected]>"
7+
LABEL "com.github.actions.name"="Secure Actions Webhook"
8+
LABEL "com.github.actions.description"="Post data and an hmac signature to an endpoint"
9+
LABEL "com.github.actions.icon"="message-square"
10+
LABEL "com.github.actions.color"="gray-dark"
11+
12+
# Add the entry point
13+
ADD main.js /main.js
14+
ADD package.json /package.json
15+
ADD entrypoint.sh /entrypoint.sh
16+
RUN chmod +x /entrypoint.sh
17+
18+
WORKDIR /
19+
20+
RUN npm install
21+
22+
# Load the entry point
23+
ENTRYPOINT ["/entrypoint.sh"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Koray Koska
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
node main.js

main.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const request = require("request");
2+
const crypto = require("crypto");
3+
4+
const hmacSecret = process.env.HMAC_SECRET;
5+
if (!hmacSecret || hmacSecret === "" || hmacSecret.trim() === "") {
6+
console.warn(
7+
"The hmac secret seems empty. This doesn't seem like what you want."
8+
);
9+
}
10+
if (hmacSecret.length < 32) {
11+
console.warn(
12+
"The hmac secret seems week. You should use at least 32 secure random hex chars."
13+
);
14+
}
15+
16+
const createHmacSignature = body => {
17+
const hmac = crypto.createHmac("sha1", hmacSecret);
18+
const bodySignature = hmac.update(JSON.stringify(body)).digest("hex");
19+
20+
return `sha1=${bodySignature}`;
21+
};
22+
23+
function isJsonString(str) {
24+
try {
25+
const json = JSON.parse(str);
26+
return typeof json === "object";
27+
} catch (e) {
28+
return false;
29+
}
30+
}
31+
32+
const url = process.env.REQUEST_URL;
33+
const data = {
34+
data: isJsonString(process.env.REQUEST_DATA) ? JSON.parse(process.env.REQUEST_DATA) : process.env.REQUEST_DATA
35+
};
36+
37+
const signature = createHmacSignature(data);
38+
39+
request(
40+
{
41+
method: "POST",
42+
uri: "https://kube-cd.volkncloud.com/",
43+
44+
json: true,
45+
body: data,
46+
headers: {
47+
"X-Hub-Signature": signature
48+
}
49+
},
50+
(error, response, body) => {
51+
if (error || response.statusCode < 200 || response.statusCode > 299) {
52+
// Something went wrong
53+
console.error(`Request failed with status code ${response.statusCode}!`);
54+
console.error(response.body);
55+
56+
process.exit(1);
57+
} else {
58+
// Success
59+
process.exit();
60+
}
61+
}
62+
);

0 commit comments

Comments
 (0)