I am looking to write a pre-receive
githook in Python. It is my understanding that no arguments are passed into pre-receive
scripts but rather each reference is passed in using standard input on separate lines. I have been able to read the reference changes via:
!/usr/bin/env python
import sys
import fileinput
for line in fileinput.input():
print "pre-receive: Trying to push ref: %s" % line
However, for this hook, I am mainly concerned with making sure that the user pushing code has the correct privileges to push to the branch of which they are trying to. Through my research, I have been unable to find a way to seek the committer's user credentials. It was my goal to compare their creds against a whitelist in order to grant access.
How can I change my pre-receive
code to authenticate the committing user and verify that they are whitelisted to push to their attempted branch? And what, if any, changes do I have to make on the git repository to make the code function?