42 lines
1.0 KiB
Python
Executable File
42 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
import time
|
|
import json
|
|
from subprocess import call
|
|
|
|
import config
|
|
|
|
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)
|