Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 from os import getenv
00018 from os.path import exists
00019 from httpslib import HTTPSConnection
00020 from urllib2 import AbstractHTTPHandler
00021
00022
00023 class X509CertAuth(HTTPSConnection):
00024 '''Class to authenticate via Grid Certificate'''
00025 def __init__(self, host, *args, **kwargs):
00026 key_file = None
00027 cert_file = None
00028
00029 x509_path = getenv("X509_USER_PROXY", None)
00030 if x509_path and exists(x509_path):
00031 key_file = cert_file = x509_path
00032
00033 if not key_file:
00034 x509_path = getenv("X509_USER_KEY", None)
00035 if x509_path and exists(x509_path):
00036 key_file = x509_path
00037
00038 if not cert_file:
00039 x509_path = getenv("X509_USER_CERT", None)
00040 if x509_path and exists(x509_path):
00041 cert_file = x509_path
00042
00043 if not key_file:
00044 x509_path = getenv("HOME") + "/.globus/userkey.pem"
00045 if exists(x509_path):
00046 key_file = x509_path
00047
00048 if not cert_file:
00049 x509_path = getenv("HOME") + "/.globus/usercert.pem"
00050 if exists(x509_path):
00051 cert_file = x509_path
00052
00053 if not key_file or not exists(key_file):
00054 print >>stderr, "No certificate private key file found"
00055 exit(1)
00056
00057 if not cert_file or not exists(cert_file):
00058 print >>stderr, "No certificate public key file found"
00059 exit(1)
00060
00061
00062
00063
00064 HTTPSConnection.__init__(self,
00065 host,
00066 key_file = key_file,
00067 cert_file = cert_file,
00068 **kwargs)
00069
00070
00071
00072 class X509CertOpen(AbstractHTTPHandler):
00073 def default_open(self, req):
00074 return self.do_open(X509CertAuth, req)