CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
ws_sso_content_reader Namespace Reference

Classes

class  HTTPSClientAuthHandler
 

Functions

def _getResponse
 
def checkRequiredArguments
 
def getContent
 
def getFile
 
def getParentURL
 
def getResponseContent
 
def getResponseURL
 
def getSSOCookie
 

Variables

tuple content = getContent(opts.url, opts.cert_path, opts.key_path, opts.postdata, opts.debug)
 
tuple parser = OptionParser(usage="%prog [-d(ebug)] -o(ut) COOKIE_FILENAME -c(cert) CERN-PEM -k(ey) CERT-KEY -u(rl) URL")
 

Function Documentation

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

Definition at line 26 of file ws_sso_content_reader.py.

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

26 
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
def ws_sso_content_reader.checkRequiredArguments (   opts,
  parser 
)

Definition at line 100 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))
def ws_sso_content_reader.getContent (   target_url,
  cert_path,
  key_path,
  post_data = None,
  debug = False,
  adfslogin = None 
)

Definition at line 64 of file ws_sso_content_reader.py.

References _getResponse(), getParentURL(), getResponseContent(), getSSOCookie(), and SiPixelLorentzAngle_cfi.read.

Referenced by cmstc.TagCollector._open().

64 
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
def ws_sso_content_reader.getFile (   path)

Definition at line 6 of file ws_sso_content_reader.py.

6 
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
def ws_sso_content_reader.getParentURL (   url)

Definition at line 41 of file ws_sso_content_reader.py.

Referenced by getContent(), and getSSOCookie().

41 
42 def getParentURL(url):
43  items = url.split("/")
44  return '%s//%s/%s/' % (items[0],items[2],items[3])
def ws_sso_content_reader.getResponseContent (   opener,
  url,
  post_data = None,
  debug = False 
)

Definition at line 35 of file ws_sso_content_reader.py.

References _getResponse(), and SiPixelLorentzAngle_cfi.read.

Referenced by getContent(), and getSSOCookie().

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

Definition at line 38 of file ws_sso_content_reader.py.

References _getResponse().

Referenced by getSSOCookie().

38 
39 def getResponseURL(opener, url, post_data=None, debug=False):
40  return urllib2.unquote(_getResponse(opener, url, post_data, debug).url)
def ws_sso_content_reader.getSSOCookie (   opener,
  target_url,
  cookie,
  debug = False 
)

Definition at line 45 of file ws_sso_content_reader.py.

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

Referenced by getContent().

45 
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)

Variable Documentation

tuple ws_sso_content_reader.content = getContent(opts.url, opts.cert_path, opts.key_path, opts.postdata, opts.debug)

Definition at line 117 of file ws_sso_content_reader.py.

Referenced by MonitorElement.addProfiles(), L1GtVhdlWriterCore.buildDefValuesBuffer(), PhysicsTools::MVATrainerLooper::TrainerContainer.clear(), SiPixelDataQuality.fillGlobalQualityPlot(), cond::auth::DecodingKey.flush(), cond::auth::DecodingKey.init(), PhysicsTools::MVATrainer.MVATrainer(), XMLDocument.readContent(), evf::RecoEventOutputModuleForFU< Consumer >.RecoEventOutputModuleForFU(), CompareToMedian.runTest(), HcalDigisClient.scaleMETH2D(), ecaldqm::DQWorkerClient.towerAverage_(), RawEventFileWriterForBU.writeJsds(), and jsoncollector::FileIO.writeStringToFile().

tuple ws_sso_content_reader.parser = OptionParser(usage="%prog [-d(ebug)] -o(ut) COOKIE_FILENAME -c(cert) CERN-PEM -k(ey) CERT-KEY -u(rl) URL")

Definition at line 109 of file ws_sso_content_reader.py.