2 from __future__ import with_statement
8 from types import StringTypes, ListType
9 from optparse import OptionParser
11 from sfa.util.sfalogging import logger
13 from sfa.trust.certificate import Certificate
14 from sfa.trust.credential import Credential
15 from sfa.trust.gid import GID
17 from sfa.storage.record import SfaRecord
19 def determine_sfa_filekind(fn):
21 if fn.endswith('.gid'): return 'gid'
22 elif fn.endswith('.cert'): return 'certificate'
23 elif fn.endswith('cred'): return 'credential'
26 cred=Credential(filename=fn)
32 if gid.uuid: return 'gid'
36 cert = Certificate(filename = fn)
41 # if "gidCaller" in dict:
51 lastpart = hrn.split(".")[-1]
52 filename = lastpart + ".gid"
54 if os.path.exists(filename):
55 print filename, ": already exists... skipping"
58 print filename, ": extracting gid of", hrn
60 gid.save_to_file(filename, save_parents = True)
62 def extract_gids(cred, extract_parents):
63 gidCaller = cred.get_gid_caller()
67 gidObject = cred.get_gid_object()
68 if gidObject and ((gidCaller == None) or (gidCaller.get_hrn() != gidObject.get_hrn())):
71 # no such method Credential.get_parent
73 # parent = cred.get_parent()
75 # extract_gids(parent, extract_parents)
77 def handle_input (filename, options):
78 kind = determine_sfa_filekind(filename)
79 handle_input_kind (filename,options,kind)
81 def handle_input_kind (filename, options, kind):
84 # dump methods current do 'print' so let's go this road for now
85 if kind=="certificate":
86 cert=Certificate (filename=filename)
87 print '--------------------',filename,'IS A',kind
88 cert.dump(show_extensions=options.show_extensions)
89 elif kind=="credential":
90 cred = Credential(filename = filename)
91 print '--------------------',filename,'IS A',kind
92 cred.dump(dump_parents = options.dump_parents)
93 if options.extract_gids:
94 print '--------------------',filename,'embedded GIDS'
95 extract_gids(cred, extract_parents = options.dump_parents)
97 gid = GID(filename = filename)
98 print '--------------------',filename,'IS A',kind
99 gid.dump(dump_parents = options.dump_parents)
101 print "%s: unknown filekind '%s'"% (filename,kind)
104 usage = """%prog file1 [ .. filen]
105 display info on input files"""
106 parser = OptionParser(usage=usage)
108 parser.add_option("-g", "--extract-gids", action="store_true", dest="extract_gids", default=False, help="Extract GIDs from credentials")
109 parser.add_option("-p", "--dump-parents", action="store_true", dest="dump_parents", default=False, help="Show parents")
110 parser.add_option("-e", "--extensions", action="store_true", dest="show_extensions", default="False", help="Show certificate extensions")
111 parser.add_option("-v", "--verbose", action='count', dest='verbose', default=0)
112 (options, args) = parser.parse_args()
114 logger.setLevelFromOptVerbose(options.verbose)
119 handle_input(f,options)
121 if __name__=="__main__":