Update gitlab-listener to correctly handle gitlab events
This commit is contained in:
parent
d6b6f84ff6
commit
cb318bfc8c
@ -4,3 +4,4 @@ GITLAB_SSH_PORT = 2200
|
||||
|
||||
LISTENER_ADDRESS = "0.0.0.0"
|
||||
LISTENER_PORT = 9001
|
||||
LISTENER_DELAY = 5
|
||||
|
@ -2,6 +2,7 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
from subprocess import call
|
||||
|
||||
import config
|
||||
@ -10,22 +11,31 @@ MY_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
try:
|
||||
from flask import Flask, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
COMMAND = os.path.join(MY_DIR, "update-keys")
|
||||
EVENTS = ["key_create", "key_destroy"]
|
||||
|
||||
@app.route("/", methods=['POST'])
|
||||
def commit ():
|
||||
key = request.headers.get('X-Gitlab-Token', '')
|
||||
if not key == config.GITLAB_KEY:
|
||||
return "wrong key"
|
||||
|
||||
event = json.loads(request.data)
|
||||
print ">> received event: {}".format(event['event_name'])
|
||||
|
||||
if not event['event_name'] in EVENTS:
|
||||
return "wrong event"
|
||||
|
||||
time.sleep(config.LISTENER_DELAY)
|
||||
print ">> updating keys"
|
||||
call([COMMAND])
|
||||
return "ok"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host=config.LISTENER_ADDRESS, port=config.LISTENER_PORT)
|
||||
|
||||
except ImportError:
|
||||
call(". " + os.path.join(MY_DIR, "venv", "bin", "activate") + "; " + " ".join(sys.argv), shell=True)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
COMMAND = os.path.join(MY_DIR, "update-keys")
|
||||
|
||||
@app.route("/", methods=['POST'])
|
||||
def commit ():
|
||||
key = request.args.get('key', '')
|
||||
if not key == config.GITLAB_KEY:
|
||||
return "not ok"
|
||||
|
||||
time.sleep(1)
|
||||
call([COMMAND])
|
||||
return "ok"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host=config.LISTENER_ADDRESS, port=config.LISTENER_PORT)
|
||||
|
Loading…
x
Reference in New Issue
Block a user