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 ] 17
18 - def __init__(self, 19 default_action=False, 20 auth=None, 21 **kwargs):
22 self.auth = auth 23 if auth: 24 assert IAuth.providedBy(auth) 25 26 self.config = dict( (a, default_action) for a in self.knownActions ) 27 for act in self.knownActions: 28 if act in kwargs: 29 self.config[act] = kwargs[act] 30 del kwargs[act] 31 32 if kwargs: 33 raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
34
35 - def advertiseAction(self, action):
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
44 - def needAuthForm(self, action):
45 """Does this action require an authentication form?""" 46 if action not in self.knownActions: 47 raise KeyError("unknown action") 48 cfg = self.config.get(action, False) 49 if cfg == 'auth' or callable(cfg): 50 return True 51 return False
52
53 - def actionAllowed(self, action, request, *args):
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 # anyone can do this..
73