Package buildbot :: Package status :: Package web :: Module authz
[frames] | no frames]

Source Code for Module buildbot.status.web.authz

 1  from buildbot.status.web.auth import IAuth 
 2   
3 -class Authz(object):
4 """Decide who can do what.""" 5 6 knownActions = [ 7 # If you add a new action here, be sure to also update the documentation 8 # at docs/cfg-statustargets.texinfo 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):
24 self.auth = auth 25 if auth: 26 assert IAuth.providedBy(auth) 27 28 self.config = dict( (a, default_action) for a in self.knownActions ) 29 for act in self.knownActions: 30 if act in kwargs: 31 self.config[act] = kwargs[act] 32 del kwargs[act] 33 34 if kwargs: 35 raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
36
37 - def advertiseAction(self, action):
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
46 - def needAuthForm(self, action):
47 """Does this action require an authentication form?""" 48 if action not in self.knownActions: 49 raise KeyError("unknown action") 50 cfg = self.config.get(action, False) 51 if cfg == 'auth' or callable(cfg): 52 return True 53 return False
54
55 - def actionAllowed(self, action, request, *args):
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 # anyone can do this..
75