Auth version of remote git pull script

Username and password admin/go123456, change in code.

from flask import Flask
import subprocess
app = Flask(__name__)
import os
from functools import wraps
from flask import request, Response

def check_auth(username, password):
    return username == 'admin' and password == 'go123456'

def authenticate():
    return Response(
    'Wrong credentials,
    {'WWW-Authenticate': 'Basic realm="Login Required"'})

def requires_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            return authenticate()
        return f(*args, **kwargs)
    return decorated

@app.route('/pullstaging')
@requires_auth
def main():
    os.chdir('/srv/someurl/')
    try:
        output = subprocess.check_output(["git", "pull"])
        return output
    except subprocess.CalledProcessError as exc:
        return "Status : FAIL errcode: {}, output: {}".format(exc.returncode, exc.output)

app.run(host="0.0.0.0", port=int("8080"))
#flask #git
0
Ivan Borshchov profile picture
May 05, 2017
by Ivan Borshchov
Did it help you?
Yes !
No

Best related