From 72a08e758bc529b23ab54c351d13f496dc19a75a Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Sun, 19 Jun 2016 03:35:36 -0500 Subject: [PATCH] Initial commit --- config.py | 6 ++++++ gitlab-listener | 31 +++++++++++++++++++++++++++++++ gitlab-shell | 14 ++++++++++++++ setup | 5 +++++ update-keys | 12 ++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 config.py create mode 100755 gitlab-listener create mode 100755 gitlab-shell create mode 100755 setup create mode 100755 update-keys diff --git a/config.py b/config.py new file mode 100644 index 0000000..9f7bd03 --- /dev/null +++ b/config.py @@ -0,0 +1,6 @@ +GITLAB_HOST = "leviathan.local" +GITLAB_KEY = "Escape-Anything-These-Company-3" +GITLAB_SSH_PORT = 2200 + +LISTENER_ADDRESS = "0.0.0.0" +LISTENER_PORT = 9001 diff --git a/gitlab-listener b/gitlab-listener new file mode 100755 index 0000000..ef8518e --- /dev/null +++ b/gitlab-listener @@ -0,0 +1,31 @@ +#!/usr/bin/env python +import os +import sys +import time +from subprocess import call + +import config + +MY_DIR = os.path.dirname(os.path.abspath(__file__)) + +try: + from flask import Flask, request +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) diff --git a/gitlab-shell b/gitlab-shell new file mode 100755 index 0000000..8ce5d11 --- /dev/null +++ b/gitlab-shell @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +import os +import sys +import subprocess + +import config + +command = " ".join(sys.argv) + +if 'SSH_ORIGINAL_COMMAND' in os.environ: + command = "SSH_ORIGINAL_COMMAND='" + os.environ['SSH_ORIGINAL_COMMAND'] + "' " + command + +subprocess.call(["ssh", "git@{}".format(config.GITLAB_HOST), "-p", "{}".format(config.GITLAB_SSH_PORT), command]) diff --git a/setup b/setup new file mode 100755 index 0000000..6af4e1c --- /dev/null +++ b/setup @@ -0,0 +1,5 @@ +#!/bin/bash + +virtualenv venv +. venv/bin/activate +pip install Flask diff --git a/update-keys b/update-keys new file mode 100755 index 0000000..967e5d7 --- /dev/null +++ b/update-keys @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import os +import sys +import subprocess + +import config + +keys = subprocess.check_output(["ssh", "git@{}".format(config.GITLAB_HOST), "-p", "{}".format(config.GITLAB_SSH_PORT), "cat", ".ssh/authorized_keys"]) + +with open("/home/git/.ssh/authorized_keys", "w") as ak: + ak.write(keys)