source: examples/python_tests/alice_rt1/query.py @ 519e487

mei_rt2mei_rt2_fix_1
Last change on this file since 519e487 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.3 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"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15
16# Keystore is the directory containing the principal credentials.
17# Load existing principals and/or policy credentials
18if (os.environ.has_key("keystore")) :
19    keystore=os.environ["keystore"]
20    ctxt.load_directory(keystore)
21else:
22    print("keystore is not set...")
23    exit(1)
24
25# retrieve principals' keyid value from local credential files
26aliceID=ABAC.ID("Alice_ID.pem")
27aliceID.id_load_privkey_file("Alice_private.pem")
28alice=aliceID.id_keyid()
29
30partyID=ABAC.ID("Party_ID.pem")
31partyID.id_load_privkey_file("Party_private.pem")
32party=partyID.id_keyid()
33
34teaID=ABAC.ID("Tea_ID.pem")
35teaID.id_load_privkey_file("Tea_private.pem")
36tea=teaID.id_keyid()
37
38hatterID=ABAC.ID("Hatter_ID.pem")
39hatterID.id_load_privkey_file("Hatter_private.pem")
40hatter=hatterID.id_keyid()
41
42marchhareID=ABAC.ID("Marchhare_ID.pem")
43marchhareID.id_load_privkey_file("Marchhare_private.pem")
44marchhare=marchhareID.id_keyid()
45
46dormouseID=ABAC.ID("Dormouse_ID.pem")
47dormouseID.id_load_privkey_file("Dormouse_private.pem")
48dormouse=dormouseID.id_keyid()
49
50##########################################################################
51# dump the loaded principals/policies
52#
53out = ctxt.context_principals()
54print "\n...final principal set..."
55for x in out[1]:
56    print "%s " % x.string()
57out = ctxt.context_credentials()
58print "\n...final policy attribute set..."
59for c in out[1]:
60    print "%s <- %s" % (c.head_string(), c.tail_string())
61
62##########################################################################
63# can dormouse be a guest at the party ?
64# role=[keyid:Party].role:guests
65# p=[keyid:dormouse]
66role = ABAC.Role(party,"guests")
67p = ABAC.Role(dormouse)
68print "\n===good============ Party.guests <- dourmouse"
69out = ctxt.query(role, p)
70for c in out[1]:
71    print "%s <- %s" % (c.head_string(), c.tail_string())
72
73##########################################################################
74# can hatter be a guest at the party ?
75# role=[keyid:Party].role:guests
76# p=[keyid:hatter]
77role = ABAC.Role(party,"guests")
78p = ABAC.Role(hatter)
79print "\n===bad============ Party.guests <- hatter"
80out = ctxt.query(role, p)
81for c in out[1]:
82    print "%s <- %s" % (c.head_string(), c.tail_string())
83
Note: See TracBrowser for help on using the repository browser.