Beispiel #1
0
  def __init__(self, url, email, password, extra_headers=None):
    self.url = url.rstrip('/')
    # Email and password are accessed by commit queue, keep them.
    self.email = email
    self.password = password
    # TODO(maruel): It's not awesome but maybe necessary to retrieve the value.
    # It happens when the presubmit check is ran out of process, the cookie
    # needed to be recreated from the credentials. Instead, it should pass the
    # email and the cookie.
    if email and password:
      get_creds = lambda: (email, password)
      self.rpc_server = upload.HttpRpcServer(
            self.url,
            get_creds,
            extra_headers=extra_headers or {})
    else:
      if email == '':
        # If email is given as an empty string, then assume we want to make
        # requests that do not need authentication.  Bypass authentication by
        # setting the auth_function to None.
        self.rpc_server = upload.HttpRpcServer(url, None)
      else:
        self.rpc_server = upload.GetRpcServer(url, email)

    self._xsrf_token = None
    self._xsrf_token_time = None
Beispiel #2
0
def SendToRietveld(request_path, payload=None,
                   content_type="application/octet-stream", timeout=None):
  """Send a POST/GET to Rietveld.  Returns the response body."""
  server = GetCodeReviewSetting("CODE_REVIEW_SERVER")
  if not server:
    ErrorExit(CODEREVIEW_SETTINGS_FILE_NOT_FOUND)
  def GetUserCredentials():
    """Prompts the user for a username and password."""
    email = upload.GetEmail("Email (login for uploading to %s)" % server)
    password = getpass.getpass("Password for %s: " % email)
    return email, password
  rpc_server = upload.HttpRpcServer(server,
                                    GetUserCredentials,
                                    save_cookies=True)

  try:
    return rpc_server.Send(request_path, payload, content_type, timeout)
  except urllib2.URLError as e:
    print "'%s'" % server
    print "'%s'" % request_path
    print e
    if timeout is None:
      ErrorExit("Error accessing url %s" % request_path)
    else:
      return None
Beispiel #3
0
def GetXsrfToken(timeout=None):
  server = GetCodeReviewSetting("CODE_REVIEW_SERVER")
  def GetUserCredentials():
    """Prompts the user for a username and password."""
    email = upload.GetEmail("Email (login for uploading to %s)" % server)
    password = getpass.getpass("Password for %s: " % email)
    return email, password
  rpc_server = upload.HttpRpcServer(server,
                                    GetUserCredentials,
                                    save_cookies=True)
  try:
    return rpc_server.Send('/xsrf_token',
                           extra_headers={'X-Requesting-XSRF-Token': '1'})
  except urllib2.URLError as e:
    return None
Beispiel #4
0
 def __init__(self, url, email, password, extra_headers=None):
   self.url = url
   # TODO(maruel): It's not awesome but maybe necessary to retrieve the value.
   # It happens when the presubmit check is ran out of process, the cookie
   # needed to be recreated from the credentials. Instead, it should pass the
   # email and the cookie.
   self.email = email
   self.password = password
   if email and password:
     get_creds = lambda: (email, password)
     self.rpc_server = upload.HttpRpcServer(
           self.url,
           get_creds,
           extra_headers=extra_headers or {})
   else:
     self.rpc_server = upload.GetRpcServer(url, email)
   self._xsrf_token = None
   self._xsrf_token_time = None