source: examples/python_tests/leader_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: 2.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
22geniID=ABAC.ID("Geni_ID.pem");
23geniID.id_load_privkey_file("Geni_private.pem");
24geni=geniID.id_keyid()
25
26bobID=ABAC.ID("Bob_ID.pem");
27bobID.id_load_privkey_file("Bob_private.pem");
28bob=bobID.id_keyid()
29
30jackID=ABAC.ID("Jack_ID.pem");
31jackID.id_load_privkey_file("Jack_private.pem");
32jack=jackID.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:geni].role:leader
40# p=[keyid:Bob]
41role = ABAC.Role(geni,"leader")
42p = ABAC.Role(bob)
43print "\n===good============ geni.leader <- Bob"
44out = ctxt.query(role, p)
45for c in out[1]:
46    print "%s <- %s" % (c.head_string(), c.tail_string())
47
48##########################################################################
49# role=[keyid:geni].role:leader
50# p=[keyid:Jack]
51role = ABAC.Role(geni,"leader")
52p = ABAC.Role(jack)
53print "\n===bad============ geni.leader <- Jack"
54out = ctxt.query(role, p)
55for c in out[1]:
56    print "%s <- %s" % (c.head_string(), c.tail_string())
57
58##########################################################################
59# role=[keyid:geni].role:leader
60# p=[keyid:Joe]
61role = ABAC.Role(geni,"leader")
62p = ABAC.Role(joe)
63print "\n===good============ geni.leader <- Joe"
64out = ctxt.query(role, p)
65for c in out[1]:
66    print "%s <- %s" % (c.head_string(), c.tail_string())
67
68
69##########################################################################
70# dump the loaded principals/policies
71#
72out = ctxt.context_principals()
73print "\n...final principal set..."
74for x in out[1]:
75    print "%s " % x.string()
76print "\n"
77out = ctxt.context_credentials()
78print "\n...final policy attribute set..."
79for c in out[1]:
80    print "%s <- %s" % (c.head_string(), c.tail_string())
81print "\n"
82
83
Note: See TracBrowser for help on using the repository browser.