Skip to content

Commit e73c2ad

Browse files
authored
Merge pull request #1 from tmcolby/dev
On branch dev
2 parents 759b67e + 56b7279 commit e73c2ad

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
venv*
2+
config.json
3+
__pycache__/

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM python:2.7-alpine
2-
MAINTAINER "Matjaž Finžgar" <matjaz@finzgar.net>
1+
FROM python:3.8-alpine
2+
3+
ARG PORT=5000
34

45
WORKDIR /app
6+
COPY . .
57

6-
COPY requirements.txt /app
78
RUN pip install -r requirements.txt
89

9-
COPY . /app
1010

11-
EXPOSE 5000
12-
CMD ["python", "webhooks.py"]
11+
EXPOSE ${PORT}
12+
CMD python webhooks.py $PORT

docker_cmds

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
docker build . -t github-webhook
2+
docker run -d --name github-webhook -p 5000:5000 -v /home/tyson/dev/python-github-webhooks/hooks:/app/hooks -v /home/tyson/dev/python-github-webhooks/config.json:/app/config.json github-webhook

webhooks.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -*- coding: utf-8 -*-
23
#
34
# Copyright (C) 2014, 2015, 2016 Carlos Jenkins <carlos@jenkins.co.cr>
@@ -16,6 +17,7 @@
1617
# under the License.
1718

1819
import logging
20+
import sys
1921
from sys import stderr, hexversion
2022
logging.basicConfig(stream=stderr)
2123

@@ -70,7 +72,7 @@ def index():
7072
abort(403)
7173

7274
# Enforce secret
73-
secret = config.get('enforce_secret', '')
75+
secret = config.get('enforce_secret', '').encode('utf-8')
7476
if secret:
7577
# Only SHA1 is supported
7678
header_signature = request.headers.get('X-Hub-Signature')
@@ -82,7 +84,7 @@ def index():
8284
abort(501)
8385

8486
# HMAC requires the key to be bytes, but data is string
85-
mac = hmac.new(str(secret), msg=request.data, digestmod='sha1')
87+
mac = hmac.new(secret, msg=request.data, digestmod='sha1')
8688

8789
# Python prior to 2.7.7 does not have hmac.compare_digest
8890
if hexversion >= 0x020707F0:
@@ -203,4 +205,7 @@ def index():
203205

204206

205207
if __name__ == '__main__':
206-
application.run(debug=True, host='0.0.0.0')
208+
port=5000
209+
if sys.argv[1:]:
210+
port=int(sys.argv[1])
211+
application.run(host='0.0.0.0', port=port)

0 commit comments

Comments
 (0)