Exemplo n.º 1
0
def authorized_committers(repo_name):
    writers = set()

    # Read the static file to get admin and bot names.
    parser = ConfigParser.SafeConfigParser()
    with open(cfg.auth_file) as handle:
        parser.readfp(handle)

    for admin in parser.get("groups", "gitadmins").split(","):
        writers.add(util.decode(admin.strip()))

    if parser.has_option("groups", repo_name):
        dn = parser.get("groups", repo_name).strip()
    else:
        # drop subproject name if present
        repo_name = SUBPROJECT_RE.sub("", repo_name)
        dn = GROUP_DN % {"group": repo_name}
        pdn = PGROUP_DN % {"group": repo_name}

    # Individually granted access
    if parser.has_option("individuals", repo_name):
        for person in parser.get("individuals", repo_name).split(","):
            writers.add(util.decode(person.strip()))

    # Add the committers listed in ldap for the project.
    lh = ldap.initialize("ldaps://ldap-us-ro.apache.org")
    numldap = 0  # ldap entries fetched
    attrs = ["memberUid", "member"]
    # check new style ldap groups DN first
    try:
        for ldapresult, attrs in lh.search_s(pdn,
                                             ldap.SCOPE_BASE,
                                             attrlist=attrs):
            numldap += 1
            for availid in attrs.get("memberUid", []):
                writers.add(availid)
            for result in attrs.get("member", []):
                writers.add(DN_RE.match(result).group(1))
    except:
        log.exception()

    # If new style doesn't exist, default to old style DN
    if numldap == 0:
        try:
            for ldapresult, attrs in lh.search_s(dn,
                                                 ldap.SCOPE_BASE,
                                                 attrlist=attrs):
                numldap += 1
                for availid in attrs.get("memberUid", []):
                    writers.add(availid)
                for result in attrs.get("member", []):
                    writers.add(DN_RE.match(result).group(1))
        except:
            log.exception()

    # Add per-repository exceptions
    map(writers.add, cfg.extra_writers)

    return writers
Exemplo n.º 2
0
def _repo_name():
    path = filter(None, os.environ["PATH_INFO"].split("/"))
    path = filter(lambda p: p != "git-receive-pack", path)
    if len(path) != 1:
        raise ValueError("Invalid PATH_INFO: %s" % os.environ["PATH_INFO"])
    path = path[0]
    if path[-4:] == ".git":
        return util.decode(path[:-4])
    return util.decode(path)
Exemplo n.º 3
0
def cmd(comm, input=None, capture=False, decode=True, check=True, **kwargs):
    stdin, stdout, stderr = None, None, None
    if input is not None:
        stdin = sp.PIPE
    if capture:
        stdout, stderr = sp.PIPE, sp.PIPE
    pipe = sp.Popen(comm, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs)
    (stdout, stderr) = pipe.communicate(input=input)
    exitcode = pipe.wait()
    if check and exitcode != 0:
        raise sp.CalledProcessError(exitcode, comm)
    if decode:
        stdout = util.decode(stdout)
        stderr = util.decode(stderr)
    return (exitcode, stdout, stderr)
        print "Invalid server configuration."
        exit(1)
    sys.path.append(os.environ["ASFGIT_ADMIN"])

    import asfgit.log as log
    import asfgit.git_multimail as git_multimail
    import asfgit.util as util

    path = filter(None, os.environ["PATH_INFO"].split("/"))
    path = filter(lambda p: p != "git-receive-pack", path)
    if len(path) != 1:
        raise ValueError("Invalid PATH_INFO: %s" % os.environ["PATH_INFO"])
    path = path[0]
    repo = ""
    if path[-4:] == ".git":
        repo = util.decode(path[:-4])
    else:
        repo = util.decode(path)

    try:
        config = git_multimail.Config('multimailhook')
        try:
            environment = git_multimail.GenericEnvironment(config=config)
        except git_multimail.ConfigurationException:
            sys.stderr.write('*** %s\n' % sys.exc_info()[1])
            sys.exit(1)

        mailer = git_multimail.SendMailer(
            os.environ,
            command=['/usr/local/sbin/sendmail', '-oi', '-t'],
            envelopesender='*****@*****.**',