source: examples/python_tests/access_rt2/query.py @ 5110d42

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

1) reorganized the test directory to include python tests
2) attribute via api and principal via api from python scripts is

working (although there is a annoying seg fault at the very end
that must be related to something not been dup()ed.. need to wait
for c example to debug it)

3) able to query via api
4) replicated access_rt2 example in python and the query result matches
5) expanded api to make it easier to generate rt2 structure

  • Property mode set to 100755
File size: 2.0 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
22alphaID=ABAC.ID("Alpha_ID.pem");
23alphaID.load_privkey("Alpha_private.pem");
24#ctxt.load_id(alphaID)
25alpha=alphaID.keyid()
26
27bobID=ABAC.ID("Bob_ID.pem");
28bobID.load_privkey("Bob_private.pem");
29#ctxt.load_id(bobID)
30bob=bobID.keyid()
31
32joeID=ABAC.ID("Joe_ID.pem");
33joeID.load_privkey("Joe_private.pem");
34joe=joeID.keyid()
35
36
37##########################################################################
38# role =[keyid:alpha].role:access([string:'Read'],[urn:'file//fileA'])
39# p = "[keyid:bob]"
40param1=ABAC.DataTerm("string", "'Read'")
41param2=ABAC.DataTerm("urn","'file//fileA'")
42role = ABAC.Role(alpha,"access")
43role.add_data_term(param1)
44role.add_data_term(param2)
45p = ABAC.Role(bob)
46
47print "\n===good============ Alpha.access(Read,fileA)<-?-Bob"
48out = ctxt.query(role, p)
49
50for c in out[1]:
51    print "%s <- %s" % (c.head_string(), c.tail_string())
52
53##########################################################################
54# role =[keyid:alpha].role:access([string:'Read'],[urn:'file//fileA'])
55# p = "[keyid:joe]"
56param1=ABAC.DataTerm("string", "'Read'")
57param2=ABAC.DataTerm("urn","'file//fileA'")
58role = ABAC.Role(alpha,"access")
59role.add_data_term(param1)
60role.add_data_term(param2)
61p = ABAC.Role(joe)
62
63print "\n===bad============ Alpha.access(Read,fileA)<-?-Joe"
64out = ctxt.query(role,p)
65
66for c in out[1]:
67    print "%s <- %s" % (c.head_string(), c.tail_string())
68
69
70##########################################################################
71# role =[keyid:alpha].role:team([string:'proj2'])
72# p = "[keyid:joe]"
73param=ABAC.DataTerm("string", "'proj2'")
74role = ABAC.Role(alpha,"team")
75role.add_data_term(param)
76p = ABAC.Role(joe)
77print "\n===good============ Alpha.team(proj2)<-?-Joe"
78out = ctxt.query(role,p)
79
80for c in out[1]:
81    print "%s <- %s" % (c.head_string(), c.tail_string())
82
Note: See TracBrowser for help on using the repository browser.