source: examples/python_tests/fruits_rt2/query.py @ 47d5cf9

mei_rt2mei_rt2_fix_1
Last change on this file since 47d5cf9 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: 3.2 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
22ralphsID=ABAC.ID("Ralphs_ID.pem");
23ralphsID.id_load_privkey_file("Ralphs_private.pem");
24ralphs=ralphsID.id_keyid()
25
26bobID=ABAC.ID("Bob_ID.pem");
27bobID.id_load_privkey_file("Bob_private.pem");
28bob=bobID.id_keyid()
29
30maryID=ABAC.ID("Mary_ID.pem");
31maryID.id_load_privkey_file("Mary_private.pem");
32mary=maryID.id_keyid()
33
34##########################################################################
35# oset = [keyid:mary].oset:what2eat
36# p [string:'navel orange']
37oset = ABAC.Oset(mary,"what2eat")
38term=ABAC.DataTerm("string", "'navel orange'")
39p = ABAC.Oset(term)
40
41print "\n===good============ mary.what2eat <- navel orange"
42out = ctxt.query(oset, p)
43for c in out[1]:
44    print "%s <- %s" % (c.head_string(), c.tail_string())
45
46##########################################################################
47# oset = [keyid:mary].oset:what2eat
48# p [string:'kiwi']
49oset = ABAC.Oset(mary,"what2eat")
50term=ABAC.DataTerm("string", "'kiwi'")
51p = ABAC.Oset(term)
52
53print "\n===good============ mary.what2eat <- kiwi"
54out = ctxt.query(oset, p)
55for c in out[1]:
56    print "%s <- %s" % (c.head_string(), c.tail_string())
57
58##########################################################################
59# oset = [keyid:bob].oset:what2eat
60# p [string:'navel orange']
61oset = ABAC.Oset(bob,"what2eat")
62term=ABAC.DataTerm("string", "'navel orange'")
63p = ABAC.Oset(term)
64
65print "\n===bad============ bob.what2eat <- navel orange"
66out = ctxt.query(oset, p)
67for c in out[1]:
68    print "%s <- %s" % (c.head_string(), c.tail_string())
69
70##########################################################################
71# oset = [keyid:$ralphs].oset:fruitprice([float:1.50])
72# p = [string:'apple']
73param=ABAC.DataTerm("float", "1.50")
74oset = ABAC.Oset(ralphs,"fruitprice")
75oset.oset_add_data_term(param)
76term=ABAC.DataTerm("string", "'apple'")
77p = ABAC.Oset(term)
78
79print "\n===good============ ralphs.fruitprice(1.50) <- apple"
80out = ctxt.query(oset, p)
81for c in out[1]:
82    print "%s <- %s" % (c.head_string(), c.tail_string())
83
84##########################################################################
85# oset = [keyid:$ralphs].oset:fruitprice([float:1.50])
86# p = [string:'green apple']
87param=ABAC.DataTerm("float", "1.50")
88oset = ABAC.Oset(ralphs,"fruitprice")
89oset.oset_add_data_term(param)
90term=ABAC.DataTerm("string", "'green apple'")
91p = ABAC.Oset(term)
92
93print "\n===bad============ ralphs.fruitprice(1.50) <- green apple"
94out = ctxt.query(oset, p)
95for c in out[1]:
96    print "%s <- %s" % (c.head_string(), c.tail_string())
97
98##########################################################################
99# dump the yap dB
100#
101#ctxt.dump_yap_db()
102
103##########################################################################
104# dump the loaded principals/policies
105#
106out = ctxt.context_principals()
107print "\n...final principal set..."
108for x in out[1]:
109    print "%s " % x.string()
110print "\n"
111out = ctxt.context_credentials()
112print "\n...final policy attribute set..."
113for c in out[1]:
114    print "%s <- %s" % (c.head_string(), c.tail_string())
115print "\n"
116
117
118
Note: See TracBrowser for help on using the repository browser.