コード例 #1
0
ファイル: client.py プロジェクト: longkb/clusterClient
    def _cs_request(self, *args, **kwargs):
        kargs = {}
        kargs.setdefault('headers', kwargs.get('headers', {}))
        kargs['headers']['User-Agent'] = self.USER_AGENT

        if 'body' in kwargs:
            kargs['body'] = kwargs['body']

        if self.log_credentials:
            log_kargs = kargs
        else:
            log_kargs = self._strip_credentials(kargs)

        utils.http_log_req(_logger, args, log_kargs)
        try:
            resp, body = self.request(*args, **kargs)
        except requests.exceptions.SSLError as e:
            raise exceptions.SslCertificateValidationError(reason=e)
        except Exception as e:
            # Wrap the low-level connection error (socket timeout, redirect
            # limit, decompression error, etc) into our custom high-level
            # connection exception (it is excepted in the upper layers of code)
            _logger.debug("throwing ConnectionFailed : %s", e)
            raise exceptions.ConnectionFailed(reason=e)
        utils.http_log_resp(_logger, resp, body)
        if resp.status_code == 401:
            raise exceptions.Unauthorized(message=body)
        return resp, body
コード例 #2
0
ファイル: client.py プロジェクト: longkb/clusterClient
    def _authenticate_keystone(self):
        if self.user_id:
            creds = {'userId': self.user_id,
                     'password': self.password}
        else:
            creds = {'username': self.username,
                     'password': self.password}

        if self.tenant_id:
            body = {'auth': {'passwordCredentials': creds,
                             'tenantId': self.tenant_id, }, }
        else:
            body = {'auth': {'passwordCredentials': creds,
                             'tenantName': self.tenant_name, }, }

        if self.auth_url is None:
            raise exceptions.NoAuthURLProvided()

        token_url = self.auth_url + "/tokens"
        resp, resp_body = self._cs_request(token_url, "POST",
                                           body=json.dumps(body),
                                           content_type="application/json",
                                           allow_redirects=True)
        if resp.status_code != 200:
            raise exceptions.Unauthorized(message=resp_body)
        if resp_body:
            try:
                resp_body = json.loads(resp_body)
            except ValueError:
                pass
        else:
            resp_body = None
        self._extract_service_catalog(resp_body)
コード例 #3
0
ファイル: client.py プロジェクト: longkb/clusterClient
 def authenticate(self):
     if self.auth_strategy == 'keystone':
         self._authenticate_keystone()
     elif self.auth_strategy == 'noauth':
         self._authenticate_noauth()
     else:
         err_msg = _('Unknown auth strategy: %s') % self.auth_strategy
         raise exceptions.Unauthorized(message=err_msg)
コード例 #4
0
ファイル: client.py プロジェクト: longkb/clusterClient
 def _authenticate_noauth(self):
     if not self.endpoint_url:
         message = _('For "noauth" authentication strategy, the endpoint '
                     'must be specified either in the constructor or '
                     'using --os-url')
         raise exceptions.Unauthorized(message=message)