CMS 3D CMS Logo

Classes | Functions | Variables
ws_sso_content_reader Namespace Reference

Classes

class  HTTPSClientAuthHandler
 

Functions

def _getResponse (opener, url, post_data=None, debug=False)
 
def checkRequiredArguments (opts, parser)
 
def getContent (target_url, cert_path, key_path, post_data=None, debug=False, adfslogin=None)
 
def getFile (path)
 
def getParentURL (url)
 
def getResponseContent (opener, url, post_data=None, debug=False)
 
def getResponseURL (opener, url, post_data=None, debug=False)
 
def getSSOCookie (opener, target_url, cookie, debug=False)
 

Variables

 action
 
 args
 
 content
 
 default
 
 dest
 
 help
 
 opts
 
 parser
 
 usage
 

Function Documentation

◆ _getResponse()

def ws_sso_content_reader._getResponse (   opener,
  url,
  post_data = None,
  debug = False 
)
private

Definition at line 27 of file ws_sso_content_reader.py.

27 def _getResponse(opener, url, post_data=None, debug=False):
28  response = opener.open(url, post_data)
29  if debug:
30  sys.stderr.write("Code: %s\n" % response.code)
31  sys.stderr.write("Headers: %s\n" % response.headers)
32  sys.stderr.write("Msg: %s\n" % response.msg)
33  sys.stderr.write("Url: %s\n" % response.url)
34  return response
35 

Referenced by getContent(), getResponseContent(), and getResponseURL().

◆ checkRequiredArguments()

def ws_sso_content_reader.checkRequiredArguments (   opts,
  parser 
)

Definition at line 101 of file ws_sso_content_reader.py.

101 def checkRequiredArguments(opts, parser):
102  missing_options = []
103  for option in parser.option_list:
104  if re.match(r'^\[REQUIRED\]', option.help) and eval('opts. %s' % option.dest) == None:
105  missing_options.extend(option._long_opts)
106  if len(missing_options) > 0:
107  parser.error('Missing REQUIRED parameters: %s' % str(missing_options))
108 

References str.

◆ getContent()

def ws_sso_content_reader.getContent (   target_url,
  cert_path,
  key_path,
  post_data = None,
  debug = False,
  adfslogin = None 
)

Definition at line 65 of file ws_sso_content_reader.py.

65 def getContent(target_url, cert_path, key_path, post_data=None, debug=False, adfslogin=None):
66  opener = urllib2.build_opener(urllib2.HTTPSHandler())
67  if adfslogin:
68  opener.addheaders = [('Adfs-Login', adfslogin)] #local version of tc test
69 
70  #try to access the url first
71  try:
72  content = getResponseContent(opener, target_url, post_data, debug)
73  if not 'Sign in with your CERN account' in content:
74  return content
75  except Exception:
76  if debug:
77  sys.stderr.write("The request has an error, will try to create a new cookie\n")
78 
79  cookie = cookielib.CookieJar()
80  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie), HTTPSClientAuthHandler(key_path, cert_path)) #will use private key and ceritifcate
81  if debug:
82  sys.stderr.write("The return page is sso login page, will request cookie.")
83  hasCookie = False
84  # if the access gave an exception, try to get a cookie
85  try:
86  getSSOCookie(opener, target_url, cookie, debug)
87  hasCookie = True
88  result = getResponseContent(opener, target_url, post_data, debug)
89  except Exception as e:
90  result = ""
91  print(sys.stderr.write("ERROR:"+str(e)))
92  if hasCookie:
93  burl = getParentURL(target_url)
94  try:
95  _getResponse(opener, burl+"signOut").read()
96  _getResponse(opener, "https://login.cern.ch/adfs/ls/?wa=wsignout1.0").read()
97  except:
98  sys.stderr.write("Error, could not logout correctly from server")
99  return result
100 

References _getResponse(), getParentURL(), getResponseContent(), getSSOCookie(), print(), readEcalDQMStatus.read, and str.

◆ getFile()

def ws_sso_content_reader.getFile (   path)

Definition at line 7 of file ws_sso_content_reader.py.

7 def getFile(path):
8  npath = os.path.expanduser(path)
9  while os.path.islink(npath):
10  path = os.readlink(npath)
11  if path[0] != "/": path = os.path.join(os.path.dirname(npath),path)
12  npath = path
13  return npath
14 

◆ getParentURL()

def ws_sso_content_reader.getParentURL (   url)

Definition at line 42 of file ws_sso_content_reader.py.

42 def getParentURL(url):
43  items = url.split("/")
44  return '%s//%s/%s/' % (items[0],items[2],items[3])
45 

Referenced by getContent(), and getSSOCookie().

◆ getResponseContent()

def ws_sso_content_reader.getResponseContent (   opener,
  url,
  post_data = None,
  debug = False 
)

Definition at line 36 of file ws_sso_content_reader.py.

36 def getResponseContent(opener, url, post_data=None, debug=False):
37  return _getResponse(opener, url, post_data, debug).read()
38 

References _getResponse(), and readEcalDQMStatus.read.

Referenced by getContent(), and getSSOCookie().

◆ getResponseURL()

def ws_sso_content_reader.getResponseURL (   opener,
  url,
  post_data = None,
  debug = False 
)

Definition at line 39 of file ws_sso_content_reader.py.

39 def getResponseURL(opener, url, post_data=None, debug=False):
40  return urllib2.unquote(_getResponse(opener, url, post_data, debug).url)
41 

References _getResponse().

Referenced by getSSOCookie().

◆ getSSOCookie()

def ws_sso_content_reader.getSSOCookie (   opener,
  target_url,
  cookie,
  debug = False 
)

Definition at line 46 of file ws_sso_content_reader.py.

46 def getSSOCookie(opener, target_url, cookie, debug=False):
47  opener.addheaders = [('User-agent', 'curl-sso-certificate/0.0.2')] #in sync with cern-get-sso-cookie tool
48  url = getResponseURL(opener, getParentURL(target_url), debug=debug)
49  content = getResponseContent(opener, url, debug=debug)
50  ret = re.search('<form .+? action="(.+?)">', content)
51  if ret == None:
52  raise Exception("error: The page doesn't have the form with adfs url, check 'User-agent' header")
53  url = urllib2.unquote(ret.group(1))
54  h = HTMLParser.HTMLParser()
55  post_data_local = ''
56  for match in re.finditer('input type="hidden" name="([^"]*)" value="([^"]*)"', content):
57  post_data_local += "&%s=%s" % (match.group(1), urllib.quote(h.unescape(match.group(2))))
58  is_link_found = True
59 
60  if not is_link_found:
61  raise Exception("error: The page doesn't have the form with security attributes, check 'User-agent' header")
62  post_data_local = post_data_local[1:] #remove first &
63  getResponseContent(opener, url, post_data_local, debug)
64 

References getParentURL(), getResponseContent(), and getResponseURL().

Referenced by getContent().

Variable Documentation

◆ action

ws_sso_content_reader.action

Definition at line 111 of file ws_sso_content_reader.py.

◆ args

ws_sso_content_reader.args

Definition at line 116 of file ws_sso_content_reader.py.

◆ content

ws_sso_content_reader.content

Definition at line 118 of file ws_sso_content_reader.py.

◆ default

ws_sso_content_reader.default

Definition at line 111 of file ws_sso_content_reader.py.

◆ dest

ws_sso_content_reader.dest

Definition at line 111 of file ws_sso_content_reader.py.

◆ help

ws_sso_content_reader.help

Definition at line 111 of file ws_sso_content_reader.py.

◆ opts

ws_sso_content_reader.opts

Definition at line 116 of file ws_sso_content_reader.py.

◆ parser

ws_sso_content_reader.parser

Definition at line 110 of file ws_sso_content_reader.py.

◆ usage

ws_sso_content_reader.usage

Definition at line 110 of file ws_sso_content_reader.py.

ws_sso_content_reader.getParentURL
def getParentURL(url)
Definition: ws_sso_content_reader.py:42
ws_sso_content_reader.getContent
def getContent(target_url, cert_path, key_path, post_data=None, debug=False, adfslogin=None)
Definition: ws_sso_content_reader.py:65
ws_sso_content_reader.checkRequiredArguments
def checkRequiredArguments(opts, parser)
Definition: ws_sso_content_reader.py:101
ws_sso_content_reader.getFile
def getFile(path)
Definition: ws_sso_content_reader.py:7
ws_sso_content_reader.getSSOCookie
def getSSOCookie(opener, target_url, cookie, debug=False)
Definition: ws_sso_content_reader.py:46
str
#define str(s)
Definition: TestProcessor.cc:53
ws_sso_content_reader._getResponse
def _getResponse(opener, url, post_data=None, debug=False)
Definition: ws_sso_content_reader.py:27
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
Exception
ws_sso_content_reader.getResponseURL
def getResponseURL(opener, url, post_data=None, debug=False)
Definition: ws_sso_content_reader.py:39
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
ws_sso_content_reader.getResponseContent
def getResponseContent(opener, url, post_data=None, debug=False)
Definition: ws_sso_content_reader.py:36