source: fedd/init_abac_authorizer.py @ 913dc7a

axis_examplecompt_changesinfo-ops
Last change on this file since 913dc7a was 62f3dd9, checked in by Ted Faber <faber@…>, 14 years ago

allow command line progams to expand tildes. Added a class derived from OptionParser? to make that easily available.

  • Property mode set to 100755
File size: 1.5 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, file_expanding_opts
8
9class Parser(OptionParser):
10    def __init__(self):
11        OptionParser.__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.