#!/usr/bin/env python import sys, os import re import os.path from optparse import OptionParser, OptionValueError from federation.authorizer import abac_authorizer from federation.util import file_expanding_opts class access_opts(file_expanding_opts): ''' Parse the options for this program. Most are straightforward, but the mapper uses a callback to convert from a string to a local mapper function. ''' def __init__(self): file_expanding_opts.__init__(self, usage='%prog [opts] file [...]') self.add_option('--dir', dest='dir', default=None, type='str', action='callback', callback=self.expand_file, help='Authorizer to update') self.add_option('--debug', action='store_true', dest='debug', default=False, help='Just print actions') self.set_defaults(mapper=None) # Main opts, args = access_opts().parse_args() # Validate arguments if len(args) < 1: sys.exit('No filenames given to import') if opts.dir is None: sys.exit('Need an authorizer to update --dir') if not os.path.isabs(opts.dir): sys.exit('Authorizer path must be absolute') auth = abac_authorizer(load=opts.dir) if not auth.import_credentials(file_list=args): sys.exit("Could not import all creds") if not opts.debug: auth.save() else: print "All credentials can be imported. Not saving because --debug" sys.exit(0)