1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | s1_query.py |
---|
5 | using python api |
---|
6 | |
---|
7 | """ |
---|
8 | |
---|
9 | print("=====================s1_query.py==================") |
---|
10 | |
---|
11 | import os |
---|
12 | import ABAC |
---|
13 | |
---|
14 | ctxt = ABAC.Context() |
---|
15 | |
---|
16 | # Keystore is the directory containing the principal credentials. |
---|
17 | # Load existing principals and/or policy credentials |
---|
18 | if (os.environ.has_key("keystore")) : |
---|
19 | keystore=os.environ["keystore"] |
---|
20 | ctxt.load_directory(keystore) |
---|
21 | else: |
---|
22 | print("keystore is not set, using current directory...") |
---|
23 | ctxt.load_directory(".") |
---|
24 | |
---|
25 | ########################################################################## |
---|
26 | def get_next(CTXT) : |
---|
27 | while( 1 ) : |
---|
28 | print ("\nnext proof:") |
---|
29 | (success, out) = CTXT.next_proof() |
---|
30 | if(success) : |
---|
31 | for c in out: |
---|
32 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
33 | else: |
---|
34 | print("no more..\n") |
---|
35 | return |
---|
36 | |
---|
37 | # dump the loaded principals/policies |
---|
38 | def dump_all(CTXT,msg) : |
---|
39 | out = CTXT.context_principals() |
---|
40 | print "\n...%s principal set..." % msg |
---|
41 | for x in out[1]: |
---|
42 | print "#PP# %s " % x.string() |
---|
43 | out = CTXT.context_credentials() |
---|
44 | print "\n...%s policy attribute set..." %msg |
---|
45 | for c in out[1]: |
---|
46 | print "#CC# %s <- %s" % (c.head_string(), c.tail_string()) |
---|
47 | |
---|
48 | ########################################################################## |
---|
49 | # retrieve principals' keyid value from local credential files |
---|
50 | gID=ABAC.ID("G_ID.pem"); |
---|
51 | g=gID.id_keyid() |
---|
52 | |
---|
53 | paID=ABAC.ID("PA_ID.pem"); |
---|
54 | pa=paID.id_keyid() |
---|
55 | |
---|
56 | drdID=ABAC.ID("Drd_ID.pem"); |
---|
57 | drd=drdID.id_keyid() |
---|
58 | |
---|
59 | ########################################################################## |
---|
60 | #dump_all(ctxt,"initial") |
---|
61 | #ctxt.set_no_partial_proof() |
---|
62 | |
---|
63 | ########################################################################## |
---|
64 | # [keyid:G].oset:qualifiedProject <-?- [string:'proj1'] (yes) |
---|
65 | # oset=[keyid:G].oset:qualifiedProject |
---|
66 | # p =[string:'proj1'] |
---|
67 | oset = ABAC.Oset(g,"qualifiedProject") |
---|
68 | term=ABAC.DataTerm("string", "'proj1'") |
---|
69 | p = ABAC.Oset(term) |
---|
70 | |
---|
71 | print "\n===good============ G.qualifiedProject <-?- proj1" |
---|
72 | out = ctxt.query(oset, p) |
---|
73 | for c in out[1]: |
---|
74 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
75 | |
---|
76 | ########################################################################## |
---|
77 | # [keyid:PA].oset:std_ops <-?- [string:'info'] |
---|
78 | oset = ABAC.Oset(pa,"std_ops") |
---|
79 | term=ABAC.DataTerm("string", "'info'") |
---|
80 | p = ABAC.Oset(term) |
---|
81 | |
---|
82 | print "\n===good============ PA.std_ops <-?- info" |
---|
83 | out = ctxt.query(oset, p) |
---|
84 | for c in out[1]: |
---|
85 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
86 | |
---|
87 | #get_next(ctxt) |
---|
88 | |
---|
89 | print("\n\n") |
---|