source: fedd/init_abac_authorizer.py @ c573278

axis_examplecompt_changesinfo-ops
Last change on this file since c573278 was c573278, checked in by Ted Faber <faber@…>, 13 years ago

Checkpoint. Still lots to do

  • Property mode set to 100755
File size: 1.2 KB
Line 
1#!/usr/local/bin/python
2
3import sys
4import os, os.path
5
6from optparse import OptionParser
7from federation.authorizer import abac_authorizer
8
9class Parser(OptionParser):
10    def __init__(self):
11        OptionParser.__init__(self, usage='%prog [options]')
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
18parser = Parser()
19opts, args = parser.parse_args()
20
21if any([ not x for x in (opts.cert, opts.policy, opts.out_dir)]):
22    parser.print_help()
23    sys.exit(1)
24
25try:
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))
29except EnvironmentError, e:
30    sys.exit("Can't remove %s: %s" % ( e.filename, e.strerror))
31
32try:
33    a = abac_authorizer(key=opts.key, me=opts.cert, certs=opts.policy,
34            save=opts.out_dir)
35    a.save(opts.out_dir)
36except EnvironmentError, e:
37    sys.exit("Can't create or write %s: %s" % (e.filename, e.strerror))
38except abac_authorizer.bad_cert_error, e:
39    sys.exit("Error creating authorizer: %s" % e)
Note: See TracBrowser for help on using the repository browser.