CMS 3D CMS Logo

authentication.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
14 
15 from sys import version_info
16 from os import getenv
17 from os.path import exists
18 if version_info[0]==2:
19  from httplib import HTTPSConnection
20  from urllib2 import AbstractHTTPHandler
21 else:
22  from http.client import HTTPSConnection
23  from urllib.request import AbstractHTTPHandler
24 #-------------------------------------------------------------------------------
25 
26 class X509CertAuth(HTTPSConnection):
27  '''Class to authenticate via Grid Certificate'''
28  def __init__(self, host, *args, **kwargs):
29  key_file = None
30  cert_file = None
31 
32  x509_path = getenv("X509_USER_PROXY", None)
33  if x509_path and exists(x509_path):
34  key_file = cert_file = x509_path
35 
36  if not key_file:
37  x509_path = getenv("X509_USER_KEY", None)
38  if x509_path and exists(x509_path):
39  key_file = x509_path
40 
41  if not cert_file:
42  x509_path = getenv("X509_USER_CERT", None)
43  if x509_path and exists(x509_path):
44  cert_file = x509_path
45 
46  if not key_file:
47  x509_path = getenv("HOME") + "/.globus/userkey.pem"
48  if exists(x509_path):
49  key_file = x509_path
50 
51  if not cert_file:
52  x509_path = getenv("HOME") + "/.globus/usercert.pem"
53  if exists(x509_path):
54  cert_file = x509_path
55 
56  if not key_file or not exists(key_file):
57  print("No certificate private key file found", file=stderr)
58  exit(1)
59 
60  if not cert_file or not exists(cert_file):
61  print("No certificate public key file found", file=stderr)
62  exit(1)
63 
64  #print "Using SSL private key", key_file
65  #print "Using SSL public key", cert_file
66 
67  HTTPSConnection.__init__(self,
68  host,
69  key_file = key_file,
70  cert_file = cert_file,
71  **kwargs)
72 
73 #-----------------------------------------------------------------------------
74 
75 class X509CertOpen(AbstractHTTPHandler):
76  def default_open(self, req):
77  return self.do_open(X509CertAuth, req)
authentication.X509CertOpen
Definition: authentication.py:75
authentication.X509CertAuth
Definition: authentication.py:26
authentication.X509CertAuth.__init__
def __init__(self, host, *args, **kwargs)
Definition: authentication.py:28
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
authentication.X509CertOpen.default_open
def default_open(self, req)
Definition: authentication.py:76
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53