source: examples/scaling_tests/haystack/fruit_python/base/QUERY.py @ 373bf68

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

1) add the scaling test suite

  • Property mode set to 100755
File size: 3.5 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
26ralphsID=ABAC.ID("Ralphs_ID.pem");
27ralphs=ralphsID.id_keyid()
28
29bobID=ABAC.ID("Bob_ID.pem");
30bob=bobID.id_keyid()
31
32maryID=ABAC.ID("Mary_ID.pem");
33mary=maryID.id_keyid()
34
35##########################################################################
36# dump the loaded principals/policies
37#
38
39fd=os.open("creds_dump",os.O_WRONLY|os.O_CREAT)
40out = ctxt.context_principals()
41for x in out[1]:
42    os.write(fd, x.string())
43    os.write(fd,"\n")
44out = ctxt.context_credentials()
45for c in out[1]:
46    string="%s <- %s\n" % (c.head_string(), c.tail_string())
47    os.write(fd,string) 
48os.close(fd)
49
50##########################################################################
51# Would Mary eat navel orange ?
52# oset = [keyid:mary].oset:what2eat
53# p [string:'navel orange']
54oset = ABAC.Oset(mary,"what2eat")
55term=ABAC.DataTerm("string", "'navel orange'")
56p = ABAC.Oset(term)
57
58print "\n===good============ mary.what2eat <- navel orange"
59out = ctxt.query(oset, p)
60for c in out[1]:
61    print "%s <- %s" % (c.head_string(), c.tail_string())
62
63##########################################################################
64# Would Mary eat kiwi ?
65# oset = [keyid:mary].oset:what2eat
66# p [string:'kiwi']
67oset = ABAC.Oset(mary,"what2eat")
68term=ABAC.DataTerm("string", "'kiwi'")
69p = ABAC.Oset(term)
70
71print "\n===good============ mary.what2eat <- kiwi"
72out = ctxt.query(oset, p)
73for c in out[1]:
74    print "%s <- %s" % (c.head_string(), c.tail_string())
75
76##########################################################################
77# Would Bob eat navel orange ?
78# oset = [keyid:bob].oset:what2eat
79# p [string:'navel orange']
80oset = ABAC.Oset(bob,"what2eat")
81term=ABAC.DataTerm("string", "'navel orange'")
82p = ABAC.Oset(term)
83
84print "\n===bad============ bob.what2eat <- navel orange"
85out = ctxt.query(oset, p)
86for c in out[1]:
87    print "%s <- %s" % (c.head_string(), c.tail_string())
88
89##########################################################################
90# Is Apple 1.50 at Ralphs ?
91# oset = [keyid:$ralphs].oset:fruitprice([float:1.50])
92# p = [string:'apple']
93param=ABAC.DataTerm("float", "1.50")
94oset = ABAC.Oset(ralphs,"fruitprice")
95oset.oset_add_data_term(param)
96term=ABAC.DataTerm("string", "'apple'")
97p = ABAC.Oset(term)
98
99print "\n===good============ ralphs.fruitprice(1.50) <- apple"
100out = ctxt.query(oset, p)
101for c in out[1]:
102    print "%s <- %s" % (c.head_string(), c.tail_string())
103
104##########################################################################
105# Is green apple 1.50 at Ralphs ?
106# oset = [keyid:$ralphs].oset:fruitprice([float:1.50])
107# p = [string:'green apple']
108param=ABAC.DataTerm("float", "1.50")
109oset = ABAC.Oset(ralphs,"fruitprice")
110oset.oset_add_data_term(param)
111term=ABAC.DataTerm("string", "'green apple'")
112p = ABAC.Oset(term)
113
114print "\n===bad============ ralphs.fruitprice(1.50) <- green apple"
115out = ctxt.query(oset, p)
116for c in out[1]:
117    print "%s <- %s" % (c.head_string(), c.tail_string())
118
119##########################################################################
120# dump the yap dB
121#
122#ctxt.dump_yap_db()
123
Note: See TracBrowser for help on using the repository browser.