[cf7bc45] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | import sys, os |
---|
| 4 | import re |
---|
| 5 | import os.path |
---|
| 6 | |
---|
| 7 | from optparse import OptionParser, OptionValueError |
---|
| 8 | |
---|
| 9 | from federation.authorizer import abac_authorizer |
---|
| 10 | from federation.util import file_expanding_opts |
---|
| 11 | |
---|
| 12 | class 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 | |
---|
| 29 | opts, args = access_opts().parse_args() |
---|
| 30 | |
---|
| 31 | # Validate arguments |
---|
| 32 | if len(args) < 1: |
---|
| 33 | sys.exit('No filenames given to import') |
---|
| 34 | if opts.dir is None: |
---|
| 35 | sys.exit('Need an authorizer to update --dir') |
---|
| 36 | if not os.path.isabs(opts.dir): |
---|
| 37 | sys.exit('Authorizer path must be absolute') |
---|
| 38 | |
---|
| 39 | auth = abac_authorizer(load=opts.dir) |
---|
[cc6091c] | 40 | if not auth.import_credentials(file_list=args): |
---|
[cf7bc45] | 41 | sys.exit("Could not import all creds") |
---|
| 42 | |
---|
| 43 | if not opts.debug: auth.save() |
---|
| 44 | else: print "All credentials can be imported. Not saving because --debug" |
---|
| 45 | sys.exit(0) |
---|