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

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

Definition at line 100 of file ws_sso_content_reader.py.

References str.

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

References _getResponse(), getParentURL(), getResponseContent(), getSSOCookie(), and str.

Referenced by cmstc.TagCollector._open().

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

Definition at line 6 of file ws_sso_content_reader.py.

Referenced by FedRawDataInputSource.exceptionState(), and PedeSteererWeakModeConstraints.getConfigData().

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

Definition at line 41 of file ws_sso_content_reader.py.

Referenced by getContent(), and getSSOCookie().

41 def getParentURL(url):
42  items = url.split("/")
43  return '%s//%s/%s/' % (items[0],items[2],items[3])
44 
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().

Referenced by getContent(), and getSSOCookie().

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

Variable Documentation

ws_sso_content_reader.action

Definition at line 110 of file ws_sso_content_reader.py.

ws_sso_content_reader.args

Definition at line 115 of file ws_sso_content_reader.py.

ws_sso_content_reader.content
ws_sso_content_reader.default

Definition at line 110 of file ws_sso_content_reader.py.

ws_sso_content_reader.dest

Definition at line 110 of file ws_sso_content_reader.py.

ws_sso_content_reader.help

Definition at line 110 of file ws_sso_content_reader.py.

ws_sso_content_reader.opts

Definition at line 115 of file ws_sso_content_reader.py.

ws_sso_content_reader.parser

Definition at line 109 of file ws_sso_content_reader.py.

ws_sso_content_reader.usage

Definition at line 109 of file ws_sso_content_reader.py.