1 from sfatables.runtime import SFATablesRules
3 def fetch_context(slice_hrn, user_hrn, contexts):
5 Returns the request context required by sfatables. At some point, this
6 mechanism should be changed to refer to "contexts", which is the
7 information that sfatables is requesting. But for now, we just return
8 the basic information needed in a dict.
10 slice_hrn = urn_to_hrn(slice_xrn)[0]
11 user_hrn = urn_to_hrn(user_xrn)[0]
12 base_context = {'sfa':{'user':{'hrn':user_hrn}, 'slice':{'hrn':slice_hrn}}}
15 def run_sfatables(chain, hrn, origin_hrn, rspec, context_callback = None ):
17 Run the rspec through sfatables
18 @param chain Name of rule chain
19 @param hrn Object's hrn
20 @param origin_hrn Original caller's hrn
21 @param rspec Incoming rspec
22 @param context_callback Callback used to generate the request context
26 if not context_callback:
27 context_callback = fetch_context
30 rules = SFATablesRules(chain)
31 if rules.sorted_rule_list:
32 contexts = rules.contexts
33 request_context = context_callback(hrn, origin_hrn, contexts)
34 rules.set_context(request_context)
35 newrspec = rules.apply(rspec)