CMS 3D CMS Logo

authentication.py
Go to the documentation of this file.
1 from __future__ import print_function
2 ################################################################################
3 # RelMon: a tool for automatic Release Comparison
4 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
5 #
6 # This is a code manipulation of a component of the DQMCompare tool of
7 # Marco Rovere and Luca Malgeri.
8 #
9 #
10 #
11 # Danilo Piparo CERN - danilo.piparo@cern.ch
12 #
13 ################################################################################
14 
15 from os import getenv
16 from os.path import exists
17 from httplib import HTTPSConnection
18 from urllib2 import AbstractHTTPHandler
19 #-------------------------------------------------------------------------------
20 
21 class X509CertAuth(HTTPSConnection):
22  '''Class to authenticate via Grid Certificate'''
23  def __init__(self, host, *args, **kwargs):
24  key_file = None
25  cert_file = None
26 
27  x509_path = getenv("X509_USER_PROXY", None)
28  if x509_path and exists(x509_path):
29  key_file = cert_file = x509_path
30 
31  if not key_file:
32  x509_path = getenv("X509_USER_KEY", None)
33  if x509_path and exists(x509_path):
34  key_file = x509_path
35 
36  if not cert_file:
37  x509_path = getenv("X509_USER_CERT", None)
38  if x509_path and exists(x509_path):
39  cert_file = x509_path
40 
41  if not key_file:
42  x509_path = getenv("HOME") + "/.globus/userkey.pem"
43  if exists(x509_path):
44  key_file = x509_path
45 
46  if not cert_file:
47  x509_path = getenv("HOME") + "/.globus/usercert.pem"
48  if exists(x509_path):
49  cert_file = x509_path
50 
51  if not key_file or not exists(key_file):
52  print("No certificate private key file found", file=stderr)
53  exit(1)
54 
55  if not cert_file or not exists(cert_file):
56  print("No certificate public key file found", file=stderr)
57  exit(1)
58 
59  #print "Using SSL private key", key_file
60  #print "Using SSL public key", cert_file
61 
62  HTTPSConnection.__init__(self,
63  host,
64  key_file = key_file,
65  cert_file = cert_file,
66  **kwargs)
67 
68 #-----------------------------------------------------------------------------
69 
70 class X509CertOpen(AbstractHTTPHandler):
71  def default_open(self, req):
72  return self.do_open(X509CertAuth, req)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def __init__(self, host, args, kwargs)
def exit(msg="")