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