source: fedd/import_abac_creds.py @ e5a595e

compt_changes
Last change on this file since e5a595e was cc6091c, checked in by Ted Faber <faber@…>, 13 years ago

Wrong args?

  • Property mode set to 100755
File size: 1.3 KB
Line 
1#!/usr/bin/env python
2
3import sys, os
4import re
5import os.path
6
7from optparse import OptionParser, OptionValueError
8
9from federation.authorizer import abac_authorizer
10from federation.util import file_expanding_opts
11
12class access_opts(file_expanding_opts):
13    '''
14    Parse the options for this program.  Most are straightforward, but the
15    mapper uses a callback to convert from a string to a local mapper function.
16    '''
17
18    def __init__(self):
19        file_expanding_opts.__init__(self, usage='%prog [opts] file [...]')
20        self.add_option('--dir', dest='dir', default=None,
21                type='str', action='callback', callback=self.expand_file,
22                help='Authorizer to update')
23        self.add_option('--debug', action='store_true', dest='debug', 
24                default=False, help='Just print actions')
25        self.set_defaults(mapper=None)
26
27# Main
28
29opts, args = access_opts().parse_args()
30
31# Validate arguments
32if len(args) < 1:
33    sys.exit('No filenames given to import')
34if opts.dir is None:
35    sys.exit('Need an authorizer to update --dir')
36if not os.path.isabs(opts.dir):
37    sys.exit('Authorizer path must be absolute')
38
39auth = abac_authorizer(load=opts.dir)
40if not auth.import_credentials(file_list=args):
41    sys.exit("Could not import all creds")
42
43if not opts.debug: auth.save()
44else: print "All credentials can be imported.  Not saving because --debug"
45sys.exit(0)
Note: See TracBrowser for help on using the repository browser.