source: examples/python_tests/balltime_rt2/query.py @ 669b481

mei_rt2mei_rt2_fix_1
Last change on this file since 669b481 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.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
22leagueID=ABAC.ID("League_ID.pem");
23leagueID.id_load_privkey_file("League_private.pem");
24league=leagueID.id_keyid()
25
26johnID=ABAC.ID("John_ID.pem");
27johnID.id_load_privkey_file("John_private.pem");
28john=johnID.id_keyid()
29
30markID=ABAC.ID("Mark_ID.pem");
31markID.id_load_privkey_file("Mark_private.pem");
32mark=markID.id_keyid()
33
34##########################################################################
35# role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T130000])
36# p=[keyid:john]
37param1=ABAC.DataTerm("string", "'access'")
38param2=ABAC.DataTerm("boolean", "true")
39param3=ABAC.DataTerm("time", "20120228T130000")
40role = ABAC.Role(league,"stadium")
41role.role_add_data_term(param1)
42role.role_add_data_term(param2)
43role.role_add_data_term(param3)
44p=ABAC.Role(john)
45print "\n===good============ league.stadium(access,true,20120128T130000)<-?-john"
46out = ctxt.query(role, p)
47for c in out[1]:
48    print "%s <- %s" % (c.head_string(), c.tail_string())
49
50##########################################################################
51# role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T110000])
52# p=[keyid:mark]
53param1=ABAC.DataTerm("string", "'access'")
54param2=ABAC.DataTerm("boolean", "true")
55param3=ABAC.DataTerm("time", "20120228T110000")
56role = ABAC.Role(league,"stadium")
57role.role_add_data_term(param1)
58role.role_add_data_term(param2)
59role.role_add_data_term(param3)
60p=ABAC.Role(mark)
61print "\n===bad============ league.stadium(access,true,20120128T110000)<-?-mark"
62out = ctxt.query(role, p)
63for c in out[1]:
64    print "%s <- %s" % (c.head_string(), c.tail_string())
65
66##########################################################################
67# role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T080000])
68# p=[keyid:mark]
69param1=ABAC.DataTerm("string", "'access'")
70param2=ABAC.DataTerm("boolean", "true")
71param3=ABAC.DataTerm("time", "20120228T080000")
72role = ABAC.Role(league,"stadium")
73role.role_add_data_term(param1)
74role.role_add_data_term(param2)
75role.role_add_data_term(param3)
76p=ABAC.Role(mark)
77print "\n===good============ league.stadium(access,true,20120128T080000)<-?-mark"
78out = ctxt.query(role, p)
79for c in out[1]:
80    print "%s <- %s" % (c.head_string(), c.tail_string())
81
82##########################################################################
83# dump the yap dB
84#
85#ctxt.dump_yap_db()
86
87##########################################################################
88# dump the loaded principals/policies
89#
90out = ctxt.context_principals()
91print "\n...final principal set..."
92for x in out[1]:
93    print "%s " % x.string()
94print "\n"
95out = ctxt.context_credentials()
96print "\n...final policy attribute set..."
97for c in out[1]:
98    print "%s <- %s" % (c.head_string(), c.tail_string())
99print "\n"
100
Note: See TracBrowser for help on using the repository browser.