source: examples/python_tests/payraise_rt1/query.py @ 7211a95

mei_rt2mei_rt2_fix_1
Last change on this file since 7211a95 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: 1.8 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
22alphaID=ABAC.ID("Alpha_ID.pem");
23alphaID.id_load_privkey_file("Alpha_private.pem");
24alpha=alphaID.id_keyid()
25
26bobID=ABAC.ID("Bob_ID.pem");
27bobID.id_load_privkey_file("Bob_private.pem");
28bob=bobID.id_keyid()
29
30maryannID=ABAC.ID("Maryann_ID.pem");
31maryannID.id_load_privkey_file("Maryann_private.pem");
32maryann=maryannID.id_keyid()
33
34joeID=ABAC.ID("Joe_ID.pem");
35joeID.id_load_privkey_file("Joe_private.pem");
36joe=joeID.id_keyid()
37
38##########################################################################
39# role=[keyid:alpha].role:payRaise
40# p=[keyid:Joe]
41role = ABAC.Role(alpha,"payRaise")
42p = ABAC.Role(joe)
43print "\n===bad============ alpha.payRaise <- Joe"
44out = ctxt.query(role, p)
45for c in out[1]:
46    print "%s <- %s" % (c.head_string(), c.tail_string())
47
48
49
50##########################################################################
51# role=[keyid:alpha].role:payRaise
52# p=[keyid:Maryann]
53role = ABAC.Role(alpha,"payRaise")
54p = ABAC.Role(maryann)
55print "\n===good============ alpha.payRaise <- Maryann"
56out = ctxt.query(role, p)
57for c in out[1]:
58    print "%s <- %s" % (c.head_string(), c.tail_string())
59
60
61##########################################################################
62# dump the loaded principals/policies
63#
64out = ctxt.context_principals()
65print "\n...final principal set..."
66for x in out[1]:
67    print "%s " % x.string()
68print "\n"
69out = ctxt.context_credentials()
70print "\n...final policy attribute set..."
71for c in out[1]:
72    print "%s <- %s" % (c.head_string(), c.tail_string())
73print "\n"
74
75
Note: See TracBrowser for help on using the repository browser.