source: examples/python_tests/alumni3_rt1/query.py @ 669b481

mei_rt2mei_rt2_fix_1
Last change on this file since 669b481 was 7211a95, checked in by Mei <mei@…>, 12 years ago

1) add more python examples
2) add the missing linking role and linking oset api calls
3) fix the output of time typed data term/oset obj in typed_string format

(transform back from yap time format to our ddddddddTdddddd format

  • Property mode set to 100755
File size: 3.0 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd1:env keystore=`pwd` ./query.py
7cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
8
9"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15
16# print "ABAC version %s" % ctxt.version()
17
18keystore=os.environ["keystore"]
19
20ctxt.load_directory(keystore)
21
22stateUID=ABAC.ID("StateU_ID.pem")
23stateUID.id_load_privkey_file("StateU_private.pem")
24stateU=stateUID.id_keyid()
25
26bobID=ABAC.ID("Bob_ID.pem")
27bobID.id_load_privkey_file("Bob_private.pem")
28bob=bobID.id_keyid()
29
30markID=ABAC.ID("Mark_ID.pem")
31markID.id_load_privkey_file("Mark_private.pem")
32mark=markID.id_keyid()
33
34joeID=ABAC.ID("Joe_ID.pem")
35joeID.id_load_privkey_file("Joe_private.pem")
36joe=joeID.id_keyid()
37
38maryannID=ABAC.ID("Maryann_ID.pem")
39maryannID.id_load_privkey_file("Maryann_private.pem")
40maryann=maryannID.id_keyid()
41
42janID=ABAC.ID("Jan_ID.pem")
43janID.id_load_privkey_file("Jan_private.pem")
44jan=janID.id_keyid()
45
46##########################################################################
47# role=[keyid:stateU].role:foundingAlumni
48# p=[keyid:Bob]
49role = ABAC.Role(stateU,"foundingAlumni")
50p = ABAC.Role(bob)
51print "\n===good============ stateU.foundingAlumni <- Bob"
52out = ctxt.query(role, p)
53for c in out[1]:
54    print "%s <- %s" % (c.head_string(), c.tail_string())
55
56##########################################################################
57# role=[keyid:stateU].role:foundingAlumni
58# p=[keyid:Mark]
59role = ABAC.Role(stateU,"foundingAlumni")
60p = ABAC.Role(mark)
61print "\n===bad============ stateU.foundingAlumni <- Mark"
62out = ctxt.query(role, p)
63for c in out[1]:
64    print "%s <- %s" % (c.head_string(), c.tail_string())
65
66##########################################################################
67# role=[keyid:stateU].role:foundingAlumni
68# p=[keyid:Joe]
69role = ABAC.Role(stateU,"foundingAlumni")
70p = ABAC.Role(joe)
71print "\n===bad============ stateU.foundingAlumni <- Joe"
72out = ctxt.query(role, p)
73for c in out[1]:
74    print "%s <- %s" % (c.head_string(), c.tail_string())
75
76##########################################################################
77# role=[keyid:stateU].role:foundingAlumni
78# p=[keyid:Maryann]
79role = ABAC.Role(stateU,"foundingAlumni")
80p = ABAC.Role(maryann)
81print "\n===bad============ stateU.foundingAlumni <- Maryann"
82out = ctxt.query(role, p)
83for c in out[1]:
84    print "%s <- %s" % (c.head_string(), c.tail_string())
85
86##########################################################################
87# role=[keyid:stateU].role:foundingAlumni
88# p=[keyid:Jan]
89role = ABAC.Role(stateU,"foundingAlumni")
90p = ABAC.Role(jan)
91print "\n===good============ stateU.foundingAlumni <- Jan"
92out = ctxt.query(role, p)
93for c in out[1]:
94    print "%s <- %s" % (c.head_string(), c.tail_string())
95
96
97##########################################################################
98# dump the loaded principals/policies
99#
100out = ctxt.context_principals()
101print "\n...final principal set..."
102for x in out[1]:
103    print "%s " % x.string()
104print "\n"
105out = ctxt.context_credentials()
106print "\n...final policy attribute set..."
107for c in out[1]:
108    print "%s <- %s" % (c.head_string(), c.tail_string())
109print "\n"
110
111
Note: See TracBrowser for help on using the repository browser.