aboutsummaryrefslogtreecommitdiff
path: root/flakes/private/buildbot/common/master.cfg
blob: 0357f2aa27397bc14fbe2a4c4de73cf70f04efd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- python -*-
# ex: set filetype=python:

from buildbot.plugins import secrets, util, webhooks
from buildbot.util import bytes2unicode
import re
import os
from buildbot_config import E, configure
import json

class CustomBase(webhooks.base):
    def getChanges(self, request):
        try:
            content = request.content.read()
            args = json.loads(bytes2unicode(content))
        except Exception as e:
            raise ValueError("Error loading JSON: " + str(e))

        args.setdefault("comments", "")
        args.setdefault("repository", "")
        args.setdefault("author", args.get("who"))

        return ([args], None)

class GitoliteHook(webhooks.base):
    def getChanges(self, request):
        try:
            branch  = request.args[b"branch"][0].decode("utf-8")
            project = request.args[b"project"][0].decode("utf-8")
            repository = request.args[b"repository"][0].decode("utf-8")
            author = request.args[b"author"][0].decode("utf-8")
        except Exception as e:
            raise ValueError("Error missing key in request: " + str(e))

        args = {
                "author": "gitolite for " + author,
                "category": "gitolite-hooks",
                "comments": "gitolite post-receive hook",
                "branch": branch,
                "project": project,
                "repository": repository,
                }

        return ([args], None)

userInfoProvider = util.LdapUserInfo(
        uri=E.LDAP_URL,
        bindUser=E.LDAP_ADMIN_USER,
        bindPw=open(E.SECRETS_FILE + "/ldap", "r").read().rstrip(),
        accountBase=E.LDAP_BASE,
        accountPattern=E.LDAP_PATTERN,
        accountFullName='cn',
        accountEmail='mail',
        avatarData="jpegPhoto",
        groupBase=E.LDAP_BASE,
        groupName="cn",
        groupMemberPattern=E.LDAP_GROUP_PATTERN,
        )

c = BuildmasterConfig = {
        "title": E.TITLE,
        "titleURL": E.TITLE_URL,
        "db": {
            "db_url": "sqlite:///state.sqlite"
            },
        "protocols": { "pb": { "port": E.PB_SOCKET } },
        "workers": [],
        "change_source": [],
        "schedulers": [],
        "builders": [],
        "services": [],
        "secretsProviders": [
            secrets.SecretInAFile(E.SECRETS_FILE),
            ],
        "www": {
            "change_hook_dialects": {
                "base": { "custom_class": CustomBase },
                "gitolite": { "custom_class": GitoliteHook },
                },
            "plugins": {
                "waterfall_view": {},
                "console_view": {},
                "grid_view": {},
                "buildslist": {},
                },
            "auth": util.RemoteUserAuth(
                header=b"X-Remote-User",
                userInfoProvider=userInfoProvider,
                headerRegex=re.compile(br"(?P<username>[^ @]+)")),
            }
        }

configure(c)