source: examples/python_tests/basic_id/id.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: 1.5 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd1:env keystore=`pwd` ./id.py
7cmd2:env ABAC_CN=1 keystore=`pwd` ./id.py
8
9"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15
16print "ABAC version %s" % ctxt.version()
17
18keystore=os.environ["keystore"]
19
20ctxt.load_directory(keystore)
21out = ctxt.context_principals()
22print "...initial principal set..."
23for x in out[1]:
24    print "%s " % x.string()
25print "\n" 
26
27id=ABAC.ID("Mary", 0)
28print "adding -> %s(good)" % id.name()
29id.write_cert("Mary_ID.pem")
30id.write_privkey("Mary_private.pem")
31ctxt.load_id_file("Mary_ID.pem","Mary_private.pem")
32
33nid=ABAC.ID("Jack", 0)
34print "adding -> %s(good)" % nid.name()
35ctxt.load_id(nid)
36
37id=ABAC.ID("Mark", 0)
38print "adding -> %s(good)" % id.name()
39id.write_privkey("Mark_IDKEY.pem")
40id.write_cert("Mark_IDKEY.pem")
41ctxt.load_id_file("Mark_IDKEY.pem")
42
43id=ABAC.ID("John", 0)
44print "adding -> %s(good,invisible)" % id.name()
45id.write_privkey("John_idkey.pem")
46id.write_cert("John_idkey.pem")
47ctxt.load_id_file("John_idkey.pem")
48
49id=ABAC.ID("Lori", 0)
50print "adding -> %s(good,nokey)" % id.name()
51id.write_cert("Lori_IDKEY.pem")
52ctxt.load_id_file("Lori_IDKEY.pem")
53
54id=ABAC.ID("Tom", 0)
55print "adding -> %s(bad,nocert)" % id.name()
56id.write_privkey("Tom_IDKEY.pem")
57ctxt.load_id_file("Tom_IDKEY.pem")
58
59print "adding -> Casper(bad,unknown file)"
60ctxt.load_id_file("Casper_IDKEY.pem")
61
62print "...final principal set..."
63out = ctxt.context_principals()
64for x in out[1]:
65    print "%s " % x.string()
66print "\n"
67
68ctxt.dump_yap()
Note: See TracBrowser for help on using the repository browser.