예제 #1
0
    def _CheckGitkitError(self, raw_response):
        """Raises error if API invocation failed.

    Args:
      raw_response: string, the http response.

    Raises:
      GitkitClientError: if the error code is 4xx.
      GitkitServerError: if the response if malformed.

    Returns:
      Successful response as dict.
    """
        try:
            response = simplejson.loads(raw_response)
            if 'error' not in response:
                return response
            else:
                error = response['error']
                if 'code' in error:
                    code = error['code']
                    if str(code).startswith('4'):
                        raise errors.GitkitClientError(error['message'])
                    else:
                        raise errors.GitkitServerError(error['message'])
        except simplejson.JSONDecodeError:
            pass
        raise errors.GitkitServerError('null error code from Gitkit server')
 def GetClientId(self):
   config_data = self._RetrieveProjectConfig()
   client_id = None
   for idp in config_data['idpConfig']:
     if idp['provider'] == 'GOOGLE':
       client_id = idp['clientId']
   if not client_id:
       raise errors.GitkitServerError('Google client ID not configured yet.')
   return client_id
 def GetSignInOptions(self):
   config_data = self._RetrieveProjectConfig()
   sign_in_options = []
   for idp in config_data['idpConfig']:
     if idp['enabled']:
       sign_in_options.append(str(idp['provider']).lower())
   if config_data['allowPasswordUser']:
     sign_in_options.append('password')
   if not sign_in_options:
     raise errors.GitkitServerError('no sign in option configured')
   return sign_in_options
예제 #4
0
    def GetPublicCert(self):
        """Download Gitkit public cert.

    Returns:
      dict of public certs.
    """

        cert_url = self.google_api_url + 'publicKeys'

        resp, content = self.http.request(cert_url)
        if resp.status == 200:
            return simplejson.loads(content)
        else:
            raise errors.GitkitServerError('Error response for cert url: %s' %
                                           content)