source: examples/python_tests/balltime_rt2/query.py @ 9b43fc3

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

1) add more doc to python_tests

  • Property mode set to 100755
File size: 3.2 KB
RevLine 
[7211a95]1#!/usr/bin/env python
2
3"""
[f824a9e]4Run the queries described in README
[7211a95]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
[f824a9e]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)
[7211a95]24
[f824a9e]25# retrieve principals' keyid value from local credential files
[7211a95]26leagueID=ABAC.ID("League_ID.pem");
27leagueID.id_load_privkey_file("League_private.pem");
28league=leagueID.id_keyid()
29
30johnID=ABAC.ID("John_ID.pem");
31johnID.id_load_privkey_file("John_private.pem");
32john=johnID.id_keyid()
33
34markID=ABAC.ID("Mark_ID.pem");
35markID.id_load_privkey_file("Mark_private.pem");
36mark=markID.id_keyid()
37
38##########################################################################
[f824a9e]39# dump the loaded principals/policies
40#
41out = ctxt.context_principals()
42print "\n...final principal set..."
43for x in out[1]:
44    print "%s " % x.string()
45out = ctxt.context_credentials()
46print "\n...final policy attribute set..."
47for c in out[1]:
48    print "%s <- %s" % (c.head_string(), c.tail_string())
49
50##########################################################################
51# can john go to stadium at 1pm?
[7211a95]52# role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T130000])
53# p=[keyid:john]
54param1=ABAC.DataTerm("string", "'access'")
55param2=ABAC.DataTerm("boolean", "true")
56param3=ABAC.DataTerm("time", "20120228T130000")
57role = ABAC.Role(league,"stadium")
58role.role_add_data_term(param1)
59role.role_add_data_term(param2)
60role.role_add_data_term(param3)
61p=ABAC.Role(john)
62print "\n===good============ league.stadium(access,true,20120128T130000)<-?-john"
63out = ctxt.query(role, p)
64for c in out[1]:
65    print "%s <- %s" % (c.head_string(), c.tail_string())
66
67##########################################################################
[f824a9e]68# can mark go to stadium at 11am?
[7211a95]69# role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T110000])
70# p=[keyid:mark]
71param1=ABAC.DataTerm("string", "'access'")
72param2=ABAC.DataTerm("boolean", "true")
73param3=ABAC.DataTerm("time", "20120228T110000")
74role = ABAC.Role(league,"stadium")
75role.role_add_data_term(param1)
76role.role_add_data_term(param2)
77role.role_add_data_term(param3)
78p=ABAC.Role(mark)
79print "\n===bad============ league.stadium(access,true,20120128T110000)<-?-mark"
80out = ctxt.query(role, p)
81for c in out[1]:
82    print "%s <- %s" % (c.head_string(), c.tail_string())
83
84##########################################################################
[f824a9e]85# can mark go to stadium at 8am then?
[7211a95]86# role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T080000])
87# p=[keyid:mark]
88param1=ABAC.DataTerm("string", "'access'")
89param2=ABAC.DataTerm("boolean", "true")
90param3=ABAC.DataTerm("time", "20120228T080000")
91role = ABAC.Role(league,"stadium")
92role.role_add_data_term(param1)
93role.role_add_data_term(param2)
94role.role_add_data_term(param3)
95p=ABAC.Role(mark)
96print "\n===good============ league.stadium(access,true,20120128T080000)<-?-mark"
97out = ctxt.query(role, p)
98for c in out[1]:
99    print "%s <- %s" % (c.head_string(), c.tail_string())
Note: See TracBrowser for help on using the repository browser.