[71461a4] | 1 | #!/usr/local/bin/python |
---|
| 2 | |
---|
[353db8c] | 3 | import sys |
---|
[c573278] | 4 | import os, os.path |
---|
[353db8c] | 5 | |
---|
[71461a4] | 6 | from optparse import OptionParser |
---|
| 7 | from federation.authorizer import abac_authorizer |
---|
| 8 | |
---|
| 9 | class Parser(OptionParser): |
---|
| 10 | def __init__(self): |
---|
[547aa3b] | 11 | OptionParser.__init__(self, usage='%prog [options]') |
---|
[71461a4] | 12 | self.add_option('--cert', dest='cert', help='Identity certificate') |
---|
| 13 | self.add_option('--key', dest='key', help='Identity key') |
---|
| 14 | self.add_option('--policy', dest='policy', |
---|
| 15 | help='ABAC policy certificates') |
---|
| 16 | self.add_option('--dir', dest='out_dir', help='directory to save into') |
---|
| 17 | |
---|
| 18 | parser = Parser() |
---|
| 19 | opts, args = parser.parse_args() |
---|
| 20 | |
---|
[353db8c] | 21 | if any([ not x for x in (opts.cert, opts.policy, opts.out_dir)]): |
---|
[71461a4] | 22 | parser.print_help() |
---|
| 23 | sys.exit(1) |
---|
[c573278] | 24 | |
---|
| 25 | try: |
---|
| 26 | for path, dirs, files in os.walk(opts.out_dir, topdown=False): |
---|
| 27 | for f in files: os.unlink(os.path.join(path, f)) |
---|
| 28 | for d in dirs: os.rmdir(os.path.join(path, d)) |
---|
| 29 | except EnvironmentError, e: |
---|
| 30 | sys.exit("Can't remove %s: %s" % ( e.filename, e.strerror)) |
---|
| 31 | |
---|
[353db8c] | 32 | try: |
---|
| 33 | a = abac_authorizer(key=opts.key, me=opts.cert, certs=opts.policy, |
---|
| 34 | save=opts.out_dir) |
---|
| 35 | a.save(opts.out_dir) |
---|
| 36 | except EnvironmentError, e: |
---|
| 37 | sys.exit("Can't create or write %s: %s" % (e.filename, e.strerror)) |
---|
[6e63513] | 38 | except abac_authorizer.bad_cert_error, e: |
---|
[353db8c] | 39 | sys.exit("Error creating authorizer: %s" % e) |
---|