예제 #1
0
    def check_status(self):
        if not self._is_index_operation_running():
            raise errors.IntezerError('Index operation isn\'t currently running')

        response = self._api.get_index_response(self.index_id)
        if response.status_code == HTTPStatus.OK:
            if response.json()['status'] == 'failed':
                raise errors.IndexFailed()
            else:
                self.status = consts.IndexStatusCode.FINISH
        elif response.status_code == HTTPStatus.ACCEPTED:
            self.status = consts.IndexStatusCode.IN_PROGRESS
        else:
            raise errors.IntezerError('Error in response status code:{}'.format(response.status_code))

        return self.status
예제 #2
0
    def check_status(self):
        if not self._is_analysis_running():
            raise errors.IntezerError('Analysis dont running')

        response = self._api.get_analysis_response(self.analysis_id)
        if response.status_code == HTTPStatus.OK:
            self._report = response.json()['result']
            self.status = consts.AnalysisStatusCode.FINISH
        elif response.status_code == HTTPStatus.ACCEPTED:
            self.status = consts.AnalysisStatusCode.IN_PROGRESS
        else:
            raise errors.IntezerError(
                'Error in response status code:{}'.format(
                    response.status_code))

        return self.status
예제 #3
0
 def _assert_index_response_status_code(response: Response):
     if response.status_code == HTTPStatus.NOT_FOUND:
         raise errors.HashDoesNotExistError()
     elif response.status_code != HTTPStatus.CREATED:
         raise errors.IntezerError(
             'Error in response status code:{}'.format(
                 response.status_code))
예제 #4
0
    def check_status(self) -> consts.AnalysisStatusCode:
        if not self._is_analysis_running():
            raise errors.IntezerError('Analysis is not running')

        response = self._query_status_from_api()
        if response.status_code == HTTPStatus.OK:
            result = response.json()
            if result['status'] == consts.AnalysisStatusCode.FAILED.value:
                self.status = consts.AnalysisStatusCode.FAILED
                raise errors.IntezerError('Analysis failed')
            self._report = result['result']
            self.status = consts.AnalysisStatusCode.FINISH
        elif response.status_code == HTTPStatus.ACCEPTED:
            self.status = consts.AnalysisStatusCode.IN_PROGRESS
        else:
            raise errors.IntezerError(
                'Error in response status code:{}'.format(
                    response.status_code))

        return self.status
예제 #5
0
 def _assert_analysis_response_status_code(response: Response):
     if response.status_code == HTTPStatus.NOT_FOUND:
         raise errors.HashDoesNotExistError()
     elif response.status_code == HTTPStatus.CONFLICT:
         raise errors.AnalysisIsAlreadyRunning()
     elif response.status_code == HTTPStatus.FORBIDDEN:
         raise errors.InsufficientQuota()
     elif response.status_code != HTTPStatus.CREATED:
         raise errors.IntezerError(
             'Error in response status code:{}'.format(
                 response.status_code))
예제 #6
0
    def get_url_result(self, url: str) -> Optional[Response]:
        response = self.request_with_refresh_expired_access_token(path=url,
                                                                  method='GET')

        raise_for_status(response)

        response_json = response.json()

        if 'error' in response_json:
            raise errors.IntezerError('response error: {}'.format(
                response_json['error']))

        return response
예제 #7
0
def handle_response_status(status):
    if status not in (HTTPStatus.OK, HTTPStatus.ACCEPTED):
        raise errors.IntezerError(
            'Error in response status code:{}'.format(status))

    return status == HTTPStatus.OK
예제 #8
0
 def _assert_analysis_finished(self):
     if self._is_analysis_running():
         raise errors.AnalysisIsStillRunningError()
     if self.status != consts.AnalysisStatusCode.FINISH:
         raise errors.IntezerError('Analysis not finished successfully')