source: examples/example_scripts/python/abac_prover.py @ f89b991

mei_rt2
Last change on this file since f89b991 was 4f40c3e, checked in by Mei <mei@…>, 11 years ago

1) add a yap patch file for 6.2.2 for FreeBSD platform
2) update documentaions

  • Property mode set to 100755
File size: 1.5 KB
Line 
1#!/usr/bin/env python
2
3"""
4   abac_prover.py
5   
6   To demonstrate how to use ABAC's api in python to make a query
7
8   call:   abac_prover "keystorestring" "rolestring" "principalstring"
9
10   pre-condition: run make attr_abac  generate IceCream_ID.pem and IceCream_private.pem with
11
12   This program will make a prover call using
13           rolestring <- principalstring
14
15"""
16
17import getopt
18import sys
19from ABAC import Context
20
21
22def usage():
23    print "Usage: abac_prover.py \\"
24    print "        --keystore <keystore> \\"
25    print "        --role <role> --principal <principal> "
26    print "    loads the keystore and runs the query role <-?- principal"
27    sys.exit(1)
28
29keystore = ''
30role = ''
31principal = ''
32
33try:
34    opts, args = getopt.getopt(sys.argv[1:], '', ['keystore=', 'role=', 'principal='])
35except getopt.GetoptError, err:
36    print str(err)
37    sys.exit(1)
38
39for o, a in opts:
40    if o == '--keystore':
41        keystore = a
42    elif o == '--role':
43        role = a
44    elif o == '--principal':
45        principal = a
46    else:
47        assert False, "WAT"
48
49if keystore == '' or role == '' or principal == '':
50    usage()
51
52# code begins here! sorry about that
53
54print keystore
55print role
56print principal
57
58ctx = Context()
59ctx.load_directory(keystore)
60
61print "ABAC version %s" % ctx.version()
62
63(success, credentials) = ctx.query(role, principal)
64
65if success:
66    print "success"
67
68for credential in credentials:
69    print "credential %s <- %s" % (credential.head_string(), credential.tail_string())
70
71
Note: See TracBrowser for help on using the repository browser.