1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from twisted.internet import defer
19 from twisted.python import util
20
21 from flumotion.common import keycards, watched
22 from flumotion.common import messages, errors, documentation
23 from flumotion.common.i18n import N_, gettexter
24 from flumotion.component.bouncers import base, plug, combinator
25
26 T_ = gettexter()
27
28
30
31 logCategory = 'multibouncerplug'
32
33 - def start(self, component):
49
50
51
52 entries = component.config['plugs'].get(base.BOUNCER_ALGORITHM_SOCKET,
53 [])
54 algorithms = component.plugs.get(base.BOUNCER_ALGORITHM_SOCKET, [])
55
56 if not algorithms:
57 m = messages.Error(T_(N_(
58 "The multibouncerplug requires at least one bouncer "
59 "algorithm plug to be present")), mid='no-algorithm')
60 component.addMessage(m)
61 raise errors.ComponentSetupHandledError()
62
63 for entry, algorithm in zip(entries, algorithms):
64
65 name = add_entry(entry, algorithm)
66
67 algorithm.set_keycard_store(self.watchable_keycards)
68
69
70 expire = lambda ids: self.algorithm_expire_keycard_ids(ids, name)
71 algorithm.set_expire_function(expire)
72
73 self.debug("configured with algorithms %r", self.algorithms.keys())
74
75
76 props = self.args['properties']
77 self.combinator = combinator.AlgorithmCombinator(self.algorithms)
78
79 if 'combination' in props and combinator.pyparsing is None:
80 m = messages.Error(T_(N_(
81 "To use the 'combination' property you need to "
82 "have the 'pyparsing' module installed.\n")),
83 mid='missing-pyparsing')
84 documentation.messageAddPythonInstall(m, 'pyparsing')
85 component.addMessage(m)
86 raise errors.ComponentSetupHandledError()
87
88
89 spec = props.get('combination', ' and '.join(self.algorithms.keys()))
90 self.debug("using combination %s", spec)
91 try:
92 self.combinator.create_combination(spec)
93 except combinator.ParseException, e:
94 m = messages.Error(T_(N_(
95 "Invalid algorithms combination: %s"), str(e)),
96 mid='wrong-combination')
97
98 component.addMessage(m)
99 raise errors.ComponentSetupHandledError()
100
101 return plug.BouncerPlug.start(self, component)
102
125
126 d.addCallback(authenticated, keycard)
127
128 return d
129
131
132 del self.contexts[keycard.id]
133 del self.watchable_keycards[keycard.id]
134
136
137
138 to_expire = []
139
140 self.debug("algorithm %r requested expiration of keycards %r",
141 name, keycard_ids)
142
143 for keycard_id in keycard_ids:
144
145 context = self.contexts[keycard_id]
146 context[name] = False
147
148
149
150
151 if not self.combinator.synchronous_evaluate(context):
152 self.log("keycard with id %r will be expired", keycard_id)
153 to_expire.append(keycard_id)
154
155 return self.expireKeycardIds(to_expire)
156