blob: 1d1950e6aab9049599eecc813c84e1b958d2fad9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/usr/bin/python
import json
import logging
from idp_mapping import RuleProcessor
import sys
import traceback
LOG = logging.getLogger()
logging.basicConfig(level=logging.INFO, format='%(message)s')
rule_filename = 'rules-python-01.json'
assertion_filename = 'assertion-01.json'
def assertion_from_file(filename):
with open(filename) as stream:
assertion = json.load(stream)
return assertion
def assertion_from_string(string):
assertion = json.loads(string)
return assertion
def main():
if True:
rule_processor = RuleProcessor.from_file(rule_filename)
if False:
with open(rule_filename) as stream:
rule_processor = RuleProcessor.from_stream(stream)
if False:
with open(rule_filename) as stream:
string = stream.read()
rule_processor = RuleProcessor.from_string(string)
assertion = assertion_from_file(assertion_filename)
try:
mapped = rule_processor.process(assertion)
if mapped is None:
print "no rules matched"
else:
for k, v in mapped.iteritems():
print "%s: %s" % (k, v)
mapped_json = json.dumps(mapped, indent=4)
print "\nmapped JSON"
print mapped_json
except Exception as exc:
print "FAIL: %s" % exc
traceback.print_exc()
sys.exit(1)
sys.exit(0)
main()
|