Changeset 2106ed1


Ignore:
Timestamp:
Jun 25, 2008 2:56:12 PM (16 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
Children:
8922e1b
Parents:
d26d52e
Message:

check password failures. Exception doesn_t have a message attribute under python 2.4

Location:
fedd
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd.py

    rd26d52e r2106ed1  
    131131    sys.exit("Must supply certificate file (probably in config)")
    132132
    133 bad_password = True
    134 while bad_password:
     133ctx = None
     134while ctx == None:
    135135    try:
    136136        ctx = fedd_ssl_context(impl.cert_file, impl.trusted_certs,
    137137                password=impl.cert_pwd)
    138         bad_password = False
    139138    except SSL.SSLError, e:
    140         if e.message == "bad decrypt" and impl.cert_pwd == None:
    141             bad_password = True
    142         else:
     139        if str(e) != "bad decrypt" or impl.cert_pwd != None:
    143140            raise
    144141
  • fedd/fedd_client.py

    rd26d52e r2106ed1  
    1111from ZSI import SoapWriter
    1212
    13 from fedd_util import fedid, fedd_ssl_context, pack_soap, pack_id
     13from fedd_util import fedid, fedd_ssl_context, pack_soap, unpack_soap, \
     14        pack_id, unpack_id
    1415
    1516from optparse import OptionParser, OptionValueError
     
    108109                const=sys.stderr, help="Print SOAP exchange to stderr")
    109110
    110 
    111 
    112 def print_ID(id, out=sys.stdout, prefix=None, no_nl=False):
    113     """Print an ID element (which may have many types) to as a string
    114    
    115     If out is given, that is the output destination. If prefix is given that
    116     string is prepended.  If no_nl is given, the newline is not printed.
    117     """
    118     # This comprehension selects all accessors from id of the form
    119     # get_element_*, calls those in turn and returns a list of non-None ones.
    120     # For valid ID elements that will contain exactly one element, which we
    121     # print.  Anything else is an error.
    122     names = [ getattr(id, method)() for method in dir(id) \
    123                     if method.startswith("get_element_") \
    124                         and callable(getattr(id, method))
    125                         and getattr(id,method)() != None ]
    126     if len(names) == 1:
    127         if prefix == None: print >>out, names[0],
    128         else: print >>out, "%s%s" % (prefix,names[0]),
    129         if not no_nl: print >>out
    130     else:
    131         raise IDFormatException()
    132 
    133 
    134 def print_users(ul, out=sys.stdout):
    135     """
    136     Print a list of users, with "User: " prepended, one to a line on out.
    137    
    138     @param ul sequence of user elements
    139     @param out output object.  Defaults to sys.stdout
    140     """
    141     if ul != None:
    142         for u in ul:
    143             print_ID(u.get_element_userID(), out, "User: ")
    144 
    145 
    146111def print_response_as_testbed(resp, label, out=sys.stdout):
    147112    """Print the response as input to the splitter script"""
    148     emulab_data = {
    149             "Boss: ": "get_element_boss",
    150             "OpsNode: ": "get_element_ops",
    151             "Domain: ": "get_element_domain",
    152             "FileServer: ": "get_element_fileServer",
    153             "EventServer: ": "get_element_eventServer",
     113
     114    e = resp['emulab']
     115    p = e['project']
     116    fields = {
     117            "Boss": e['boss'],
     118            "OpsNode": e['ops'],
     119            "Domain": e['domain'],
     120            "FileServer": e['fileServer'],
     121            "EventServer": e['eventServer'],
     122            "Project": unpack_id(p['name'])
    154123            }
    155124    if (label != None): print >> out, "[%s]" % label
    156     e = resp.get_element_emulab()
    157     if ( e != None):
    158         p = e.get_element_project()
    159         if ( p != None ):
    160             print_ID(p.get_element_name(), out, "Project: ")
    161             print_users(p.get_element_user(), out)
    162         for k, m in emulab_data.iteritems():
    163             method = getattr(e, m);
    164             if method != None and callable(method):
    165                 print >> out, "%s%s" % (k, method())
    166         for a in e.get_element_fedAttr():
    167             print >>out, "%s: %s" % \
    168                     (a.get_element_attribute(), a.get_element_value())
     125
     126    for l, v in fields.iteritems():
     127        print >>out, "%s: %s" % (l, v)
     128
     129    for u in p['user']:
     130        print >>out, "User: %s" % unpack_id(u['userID'])
     131
     132    for a in e['fedAttr']:
     133        print >>out, "%s: %s" % (a['attribute'], a['value'])
     134
    169135def add_ssh_key(option, opt_str, value, parser, access_keys):
    170136    try:
     
    256222        # Yes, doing this on message type is not ideal.  The string comes from
    257223        # OpenSSL, so check there is this stops working.
    258         if e.message == "bad decrypt":
     224        if str(e) == "bad decrypt":
    259225            print >>sys.stderr, "Bad Passphrase given."
    260226        else: raise
     
    301267        pack_soap(req, "RequestAccessRequestBody", msg))
    302268
    303 if opts.debug > 1:
    304     print msg
     269if opts.debug > 1: print >>sys.stderr, msg
    305270
    306271if opts.serialize_only:
     
    315280    sys.exit("Fault: %s" % e)
    316281
     282
    317283if (resp != None):
    318284    resp_body = resp.get_element_RequestAccessResponseBody()
    319285    if ( resp_body != None):
    320286        try:
    321             print_response_as_testbed(resp_body, opts.label)
     287            resp_dict = unpack_soap(resp_body)
     288            if opts.debug > 1: print >>sys.stderr, resp_dict
     289            print_response_as_testbed(resp_dict, opts.label)
    322290        except RuntimeError, e:
    323291            sys.exit("Bad response. %s" % e.messgae)
  • fedd/fedd_util.py

    rd26d52e r2106ed1  
    163163    elif id.startswith("http:") or id.startswith("https:"): return { 'uri': id }
    164164    else: return { 'username': id}
     165
     166def unpack_id(id):
     167    """return id as a type determined by the key"""
     168    if id.has_key("fedid"): return fedid(id["fedid"])
     169    else:
     170        for k in ("username", "uri", "kerberosUsername"):
     171            if id.has_key(k): return id[k]
     172    return None
    165173
    166174def pack_soap(container, name, contents):
Note: See TracChangeset for help on using the changeset viewer.