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 'stopChange',
17 'cleanShutdown',
18 ]
19
20 - def __init__(self,
21 default_action=False,
22 auth=None,
23 **kwargs):
36
38 """Should the web interface even show the form for ACTION?"""
39 if action not in self.knownActions:
40 raise KeyError("unknown action")
41 cfg = self.config.get(action, False)
42 if cfg:
43 return True
44 return False
45
54
56 """Is this ACTION allowed, given this http REQUEST?"""
57 if action not in self.knownActions:
58 raise KeyError("unknown action")
59 cfg = self.config.get(action, False)
60 if cfg:
61 if cfg == 'auth' or callable(cfg):
62 if not self.auth:
63 return False
64 user = request.args.get("username", ["<unknown>"])[0]
65 passwd = request.args.get("passwd", ["<no-password>"])[0]
66 if user == "<unknown>" or passwd == "<no-password>":
67 return False
68 if self.auth.authenticate(user, passwd):
69 if callable(cfg) and not cfg(user, *args):
70 return False
71 return True
72 return False
73 else:
74 return True
75