#!/usr/bin/env python """ s1_query.py using python api """ print("=====================s1_query.py==================") import os import ABAC ctxt = ABAC.Context() # Keystore is the directory containing the principal credentials. # Load existing principals and/or policy credentials if (os.environ.has_key("keystore")) : keystore=os.environ["keystore"] ctxt.load_directory(keystore) else: print("keystore is not set, using current directory...") ctxt.load_directory(".") ########################################################################## def get_next(CTXT) : while( 1 ) : print ("\nnext proof:") (success, out) = CTXT.next_proof() if(success) : for c in out: print "%s <- %s" % (c.head_string(), c.tail_string()) else: print("no more..\n") return # dump the loaded principals/policies def dump_all(CTXT,msg) : out = CTXT.context_principals() print "\n...%s principal set..." % msg for x in out[1]: print "#PP# %s " % x.string() out = CTXT.context_credentials() print "\n...%s policy attribute set..." %msg for c in out[1]: print "#CC# %s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # retrieve principals' keyid value from local credential files gID=ABAC.ID("G_ID.pem"); g=gID.id_keyid() paID=ABAC.ID("PA_ID.pem"); pa=paID.id_keyid() drdID=ABAC.ID("Drd_ID.pem"); drd=drdID.id_keyid() ########################################################################## #dump_all(ctxt,"initial") #ctxt.set_no_partial_proof() ########################################################################## # [keyid:G].oset:qualifiedProject <-?- [string:'proj1'] (yes) # oset=[keyid:G].oset:qualifiedProject # p =[string:'proj1'] oset = ABAC.Oset(g,"qualifiedProject") term=ABAC.DataTerm("string", "'proj1'") p = ABAC.Oset(term) print "\n===good============ G.qualifiedProject <-?- proj1" out = ctxt.query(oset, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # [keyid:PA].oset:std_ops <-?- [string:'info'] oset = ABAC.Oset(pa,"std_ops") term=ABAC.DataTerm("string", "'info'") p = ABAC.Oset(term) print "\n===good============ PA.std_ops <-?- info" out = ctxt.query(oset, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) #get_next(ctxt) print("\n\n")