Ignore:
Timestamp:
Dec 14, 2010 6:58:28 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
c092b7f
Parents:
2627eb3
Message:

Move proofs around. Lots of changes, including fault handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/client_lib.py

    r2627eb3 re83f2f2  
    77
    88from string import join
     9from datetime import datetime
    910
    1011
     
    3132                callback=self.expand_file,
    3233                type="string", help="my certificate file")
     34        self.add_option("--auth_log", action="callback", dest="auth_log",
     35                callback=self.expand_file, default=None,
     36                type="string", help="Log authentication decisions to this file")
    3337        self.add_option("--abac", action="callback", dest="abac_dir",
    3438                callback=self.expand_file,
     
    5357                const=sys.stderr, help="Print SOAP exchange to stderr")
    5458
    55 def exit_with_fault(exc, out=sys.stderr):
     59def log_authentication(fn, action, outcome, proof):
     60    f = open(fn, 'a')
     61    print >>f, '%s %s at %s' % (action, outcome, datetime.now())
     62    if isinstance(proof, list):
     63        for p in proof:
     64            print >>f, p.to_xml()
     65    else:
     66        print >>f, proof.to_xml()
     67    f.close()
     68
     69
     70def exit_with_fault(exc, action, opts, out=sys.stderr):
    5671    """
    5772    Print an error message and exit.  exc is the RPCException that caused the
     
    7287        code = -1
    7388
     89    if exc.code == service_error.access and opts.auth_log:
     90        try:
     91            log_authentication(opts.auth_log, action, 'failed', exc.proof)
     92        except EnvironmentError, e:
     93            print >>sys.stderr, "Failed to log to %s: %s" % \
     94                    (e.filename, e.strerror)
     95
    7496    print>>out, codestr
    7597    print>>out, "Description: %s" % exc.desc
     
    81103    XMLPRC calls.
    82104    """
    83     def __init__(self, desc=None, code=None, errstr=None):
     105    def __init__(self, desc=None, code=None, errstr=None, proof=None):
    84106        RuntimeError.__init__(self)
    85107        self.desc = desc
     
    87109        else: self.code = -1
    88110        self.errstr = errstr
     111        self.proof = proof
    89112
    90113class CertificateMismatchError(RuntimeError): pass
     
    208231            except service_error, e:
    209232                raise RPCException(desc=e.desc, code=e.code,
    210                         errstr=e.code_string())
     233                        errstr=e.code_string(), proof=e.proof)
    211234    elif transport == "xmlrpc":
    212235        if serialize_only:
Note: See TracChangeset for help on using the changeset viewer.