~edwargix/git.sr.ht

dca420d00917ae74338f453b989b2ea969728b7f — Drew DeVault 7 years ago 3965edd
Add authorization endpoint for HTTP clones
1 files changed, 12 insertions(+), 0 deletions(-)

M gitsrht/blueprints/repo.py
M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +12 -0
@@ 24,6 24,18 @@ from srht.markdown import markdown

repo = Blueprint('repo', __name__)

@repo.route("/authorize")
def authorize_http_access():
    original_uri = request.headers.get("X-Original-URI")
    original_uri = original_uri.split("/")
    owner, repo = original_url[1], original_uri[2]
    owner, repo = get_repo(owner, repo)
    if not repo:
        return "authorized", 200
    if not has_access(repo, UserAccess.read):
        return "unauthorized", 403
    return "authorized", 200

def get_readme(repo, tip):
    if not tip or not "README.md" in tip.tree:
        return None