Skip to content

Commit 42b896e

Browse files
authored
Fixing zombie issue (#11)
1 parent 41f4563 commit 42b896e

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed
File renamed without changes.

src/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def webhooks(repo):
1212
if request.is_json:
1313
if 'X-Hub-Signature-256' in request.headers.keys():
1414
data = await request.data
15-
header = request.headers['X-Hub-Signature-256'].split('=')[1]
15+
header = request.headers['X-Hub-Signature-256']
1616
if auth(header, data):
1717
payload = await request.get_json()
1818
parse(repo, payload)

src/auth.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import asyncio
12
import hmac
23
import hashlib
34
import os
45
import sys
56

67

78
async def auth(header, data):
8-
token = os.environ.get("API_TOKEN")
9-
tokenb = bytes(token, 'utf-8')
10-
11-
signature = 'sha256=' + hmac.new(tokenb, data, hashlib.sha256).hexdigest()
9+
token = os.environ.get("API_TOKEN").strip().encode('utf-8')
10+
signature = 'sha256=' + \
11+
hmac.new(token, str(data).encode(), hashlib.sha256).hexdigest()
1212
if hmac.compare_digest(signature, header):
1313
return True
1414
return False
@@ -18,14 +18,14 @@ async def auth(header, data):
1818
if len(sys.argv) == 3:
1919
body = sys.argv[1]
2020
header = sys.argv[2]
21-
if auth(header, body):
21+
if asyncio.run(auth(header, body)):
2222
print('true')
2323
else:
2424
print('false')
2525
elif len(sys.argv) == 2:
2626
body = sys.argv[0]
2727
header = sys.argv[1]
28-
if auth(header, body):
28+
if asyncio.run(auth(header, body)):
2929
print('true')
3030
else:
3131
print('false')

src/parse.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import asyncio
12
from multiprocessing import Process
23
from release import processRelease
34
import sys
5+
import json
46

57

68
async def parse(repo, payload):
@@ -15,8 +17,8 @@ async def parse(repo, payload):
1517
if len(sys.argv) == 3:
1618
repo = sys.argv[1]
1719
payload = sys.argv[2]
18-
parse(repo, payload)
20+
asyncio.run(parse(repo, json.loads(payload)))
1921
elif len(sys.argv) == 2:
2022
repo = sys.argv[0]
2123
payload = sys.argv[1]
22-
parse(repo, payload)
24+
asyncio.run(parse(repo, json.loads(payload)))

src/release.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import json
22
import subprocess
3-
4-
from os import environ
3+
import os
54
from pybars import Compiler
65

76
compiler = Compiler()
87

98

109
def processRelease(repo, payload):
11-
base_path = environ.get("SITES")
10+
base_path = os.environ.get("SITES")
1211
file_name = repo + '.json'
13-
file_path = (base_path / file_name).resolve()
12+
file_path = base_path + '/' + file_name
1413

1514
with open(file_path) as f:
1615
data = json.load(f)
@@ -38,13 +37,13 @@ def processRelease(repo, payload):
3837
['git', 'checkout', 'tags/' + payload['release']['tag_name']], cwd=data['path'])
3938

4039
with subprocess.Popen(' && '.join(commands), cwd=data['path'], executable='/bin/bash', shell=True) as process:
40+
print('Runing process: ' + process.pid)
4141
try:
4242
process.communicate(timeout=300)
4343
except subprocess.TimeoutExpired:
4444
print('Process was killed by timeout: 300 seconds')
4545
raise
4646
finally:
47-
print('Process complete')
4847
process.kill()
4948
process.communicate()
5049
print('Release complete!')

0 commit comments

Comments
 (0)