source: fedd/init_abac_authorizer.py @ 771a277

axis_examplecompt_changesinfo-ops
Last change on this file since 771a277 was 2e46f35, checked in by mikeryan <mikeryan@…>, 14 years ago

switch to /usr/bin/env python to run python

  • Property mode set to 100755
File size: 1.5 KB
Line 
1#!/usr/bin/env python
2
3import sys
4import os, os.path
5
6from federation.util import file_expanding_opts
7from federation.authorizer import abac_authorizer
8
9class Parser(file_expanding_opts):
10    def __init__(self):
11        file_expanding_opts.__init__(self, usage='%prog [options]')
12        self.add_option('--cert', dest='cert', 
13                action='callback', callback=self.expand_file, type='str',
14                help='Identity certificate')
15        self.add_option('--key', dest='key',
16                action='callback', callback=self.expand_file, type='str',
17                help='Identity key')
18        self.add_option('--policy', dest='policy', 
19                action='callback', callback=self.expand_file, type='str',
20                help='ABAC policy certificates')
21        self.add_option('--dir', dest='out_dir',
22                action='callback', callback=self.expand_file, type='str',
23                help='directory to save into')
24
25parser = Parser()
26opts, args = parser.parse_args()
27
28if any([ not x for x in (opts.cert, opts.policy, opts.out_dir)]):
29    parser.print_help()
30    sys.exit(1)
31
32try:
33    for path, dirs, files in os.walk(opts.out_dir, topdown=False):
34        for f in files: os.unlink(os.path.join(path, f))
35        for d in dirs: os.rmdir(os.path.join(path, d))
36except EnvironmentError, e:
37    sys.exit("Can't remove %s: %s" % ( e.filename, e.strerror))
38
39try:
40    a = abac_authorizer(key=opts.key, me=opts.cert, certs=opts.policy,
41            save=opts.out_dir)
42    a.save(opts.out_dir)
43except EnvironmentError, e:
44    sys.exit("Can't create or write %s: %s" % (e.filename, e.strerror))
45except abac_authorizer.bad_cert_error, e:
46    sys.exit("Error creating authorizer: %s" % e)
Note: See TracBrowser for help on using the repository browser.