diff options
Diffstat (limited to 'python/mapping_app.py')
-rwxr-xr-x | python/mapping_app.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/python/mapping_app.py b/python/mapping_app.py new file mode 100755 index 0000000..c590061 --- /dev/null +++ b/python/mapping_app.py @@ -0,0 +1,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 = '/home/jdennis/src/misc/federation_mapping/rules-python-01.json' +assertion_filename = '/home/jdennis/src/misc/federation_mapping/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() |