source: examples/python_tests/acme_rockets_intersection_rt0/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
22acmeID=ABAC.ID("Acme_ID.pem");
23acmeID.id_load_privkey_file("Acme_private.pem");
24acme=acmeID.id_keyid()
25
26coyoteID=ABAC.ID("Coyote_ID.pem");
27coyoteID.id_load_privkey_file("Coyote_private.pem");
28coyote=coyoteID.id_keyid()
29
30warnerbrosID=ABAC.ID("WarnerBros_ID.pem");
31warnerbrosID.id_load_privkey_file("WarnerBros_private.pem");
32warnerbros=warnerbrosID.id_keyid()
33
34batmanID=ABAC.ID("Batman_ID.pem");
35batmanID.id_load_privkey_file("Batman_private.pem");
36batman=batmanID.id_keyid()
37
38##########################################################################
39# role = "[keyid:Acme].role:buy_rockets"
40# p = "[keyid:coyote]"
41role = ABAC.Role(acme,"buy_rockets")
42p = ABAC.Role(coyote)
43
44print "\n===good============ Acme.buy_rockets <- Coyote"
45out = ctxt.query(role, p)
46
47for c in out[1]:
48    print "%s <- %s" % (c.head_string(), c.tail_string())
49
50
51##########################################################################
52# role = "[keyid:Acme].role:buy_rockets"
53# p = "[keyid:batman]"
54role = ABAC.Role(acme,"buy_rockets")
55p = ABAC.Role(batman)
56
57print "\n===bad============ Acme.buy_rockets <- Batman"
58out = ctxt.query(role, p)
59
60for c in out[1]:
61    print "%s <- %s" % (c.head_string(), c.tail_string())
62
63
64##########################################################################
65# dump the loaded principals/policies
66#
67out = ctxt.context_principals()
68print "\n...final principal set..."
69for x in out[1]:
70    print "%s " % x.string()
71print "\n"
72out = ctxt.context_credentials()
73print "\n...final policy attribute set..."
74for c in out[1]:
75    print "%s <- %s" % (c.head_string(), c.tail_string())
76print "\n"
77
78
79
Note: See TracBrowser for help on using the repository browser.