source: examples/python_tests/acme_rockets_intersection_rt0/query.py @ f824a9e

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

1) add more doc to python_tests

  • Property mode set to 100755
File size: 2.1 KB
Line 
1#!/usr/bin/env python
2
3"""
4Run the queries described in README
5
6cmd1:env keystore=`pwd` ./query.py
7cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
8"""
9
10import os
11import ABAC
12
13ctxt = ABAC.Context()
14
15# Keystore is the directory containing the principal credentials.
16# Load existing principals and/or policy credentials
17if (os.environ.has_key("keystore")) :
18    keystore=os.environ["keystore"]
19    ctxt.load_directory(keystore)
20else:
21    print("keystore is not set...")
22    exit(1)
23
24# retrieve principals' keyid value from local credential files
25acmeID=ABAC.ID("Acme_ID.pem");
26acmeID.id_load_privkey_file("Acme_private.pem");
27acme=acmeID.id_keyid()
28
29coyoteID=ABAC.ID("Coyote_ID.pem");
30coyoteID.id_load_privkey_file("Coyote_private.pem");
31coyote=coyoteID.id_keyid()
32
33warnerbrosID=ABAC.ID("WarnerBros_ID.pem");
34warnerbrosID.id_load_privkey_file("WarnerBros_private.pem");
35warnerbros=warnerbrosID.id_keyid()
36
37batmanID=ABAC.ID("Batman_ID.pem");
38batmanID.id_load_privkey_file("Batman_private.pem");
39batman=batmanID.id_keyid()
40
41##########################################################################
42# dump the loaded principals/policies
43#
44out = ctxt.context_principals()
45print "\n...final principal set..."
46for x in out[1]:
47    print "%s " % x.string()
48out = ctxt.context_credentials()
49print "\n...final policy attribute set..."
50for c in out[1]:
51    print "%s <- %s" % (c.head_string(), c.tail_string())
52
53##########################################################################
54# can coyote buy rockets from Acme ?
55# role = "[keyid:Acme].role:buy_rockets"
56# p = "[keyid:coyote]"
57role = ABAC.Role(acme,"buy_rockets")
58p = ABAC.Role(coyote)
59
60print "\n===good============ Acme.buy_rockets <- Coyote"
61out = ctxt.query(role, p)
62
63for c in out[1]:
64    print "%s <- %s" % (c.head_string(), c.tail_string())
65
66
67##########################################################################
68# can batman buy rockets from Acme ?
69# role = "[keyid:Acme].role:buy_rockets"
70# p = "[keyid:batman]"
71role = ABAC.Role(acme,"buy_rockets")
72p = ABAC.Role(batman)
73
74print "\n===bad============ Acme.buy_rockets <- Batman"
75out = ctxt.query(role, p)
76
77for c in out[1]:
78    print "%s <- %s" % (c.head_string(), c.tail_string())
79
Note: See TracBrowser for help on using the repository browser.