source: fedd/init_abac_authorizer.py @ dffa585

Last change on this file since dffa585 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
RevLine 
[2e46f35]1#!/usr/bin/env python
[71461a4]2
[353db8c]3import sys
[c573278]4import os, os.path
[353db8c]5
[f4f036f]6from federation.util import file_expanding_opts
7from federation.authorizer import abac_authorizer
[71461a4]8
[f4f036f]9class Parser(file_expanding_opts):
[71461a4]10    def __init__(self):
[f4f036f]11        file_expanding_opts.__init__(self, usage='%prog [options]')
[62f3dd9]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')
[71461a4]18        self.add_option('--policy', dest='policy', 
[62f3dd9]19                action='callback', callback=self.expand_file, type='str',
[71461a4]20                help='ABAC policy certificates')
[62f3dd9]21        self.add_option('--dir', dest='out_dir',
22                action='callback', callback=self.expand_file, type='str',
23                help='directory to save into')
[71461a4]24
25parser = Parser()
26opts, args = parser.parse_args()
27
[353db8c]28if any([ not x for x in (opts.cert, opts.policy, opts.out_dir)]):
[71461a4]29    parser.print_help()
30    sys.exit(1)
[c573278]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
[353db8c]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))
[6e63513]45except abac_authorizer.bad_cert_error, e:
[353db8c]46    sys.exit("Error creating authorizer: %s" % e)
Note: See TracBrowser for help on using the repository browser.