CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 27 of file ws_sso_content_reader.py.

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

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

Definition at line 101 of file ws_sso_content_reader.py.

References str.

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

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

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

Definition at line 7 of file ws_sso_content_reader.py.

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

Definition at line 42 of file ws_sso_content_reader.py.

Referenced by getContent(), and getSSOCookie().

42 
43 def getParentURL(url):
44  items = url.split("/")
45  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 36 of file ws_sso_content_reader.py.

References _getResponse(), and SiPixelLorentzAngle_cfi.read.

Referenced by getContent(), and getSSOCookie().

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

Definition at line 39 of file ws_sso_content_reader.py.

References _getResponse().

Referenced by getSSOCookie().

39 
40 def getResponseURL(opener, url, post_data=None, debug=False):
41  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 46 of file ws_sso_content_reader.py.

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

Referenced by getContent().

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

Referenced by L1GtVhdlWriterCore.buildDefValuesBuffer(), evf::EvFOutputJSONWriter.EvFOutputJSONWriter(), SiPixelDataQuality.fillGlobalQualityPlot(), HGCalHistoSeedingImpl.fillSmoothHistoClusters(), HGCalHistoSeedingImpl.fillSmoothPhiHistoClusters(), HGCalHistoSeedingImpl.fillSmoothRPhiHistoClusters(), cond::auth::DecodingKey.flush(), cscdqm::Collection.getNodeProperties(), evf::GlobalEvFOutputJSONDef.GlobalEvFOutputJSONDef(), HcalDigisClient.HcalDigisEndjob(), HcalRecHitsDQMClient.HcalRecHitsEndjob(), cond::auth::DecodingKey.init(), evf::RecoEventOutputModuleForFU< Consumer >.initRun(), ecaldqm::MLClient.producePlots(), GzInputStream.readLine(), CompareToMedian.runTest(), LegacyIOHelper.save(), 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 110 of file ws_sso_content_reader.py.