1 from buildbot.status.web.auth import IAuth
2
4 """Decide who can do what."""
5
6 knownActions = [
7
8
9 'gracefulShutdown',
10 'forceBuild',
11 'forceAllBuilds',
12 'pingBuilder',
13 'stopBuild',
14 'stopAllBuilds',
15 'cancelPendingBuild',
16 ]
17
18 - def __init__(self,
19 default_action=False,
20 auth=None,
21 **kwargs):
34
36 """Should the web interface even show the form for ACTION?"""
37 if action not in self.knownActions:
38 raise KeyError("unknown action")
39 cfg = self.config.get(action, False)
40 if cfg:
41 return True
42 return False
43
52
54 """Is this ACTION allowed, given this http REQUEST?"""
55 if action not in self.knownActions:
56 raise KeyError("unknown action")
57 cfg = self.config.get(action, False)
58 if cfg:
59 if cfg == 'auth' or callable(cfg):
60 if not self.auth:
61 return False
62 user = request.args.get("username", ["<unknown>"])[0]
63 passwd = request.args.get("passwd", ["<no-password>"])[0]
64 if user == "<unknown>" or passwd == "<no-password>":
65 return False
66 if self.auth.authenticate(user, passwd):
67 if callable(cfg) and not cfg(user, *args):
68 return False
69 return True
70 return False
71 else:
72 return True
73