Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
##
## print("response.status_code is %s" % response.status_code)
##
if response.status_code != HTTP_REQUEST_SUCCESS_CODE:
if self._log:
code, verbiage = response.status_code, response.content[:56]
self._logDest.write('%s %s %s ...\n' % (timestamp(), code, verbiage))
self._logDest.flush()
##
## print(response)
##
#if response.status_code == PAGE_NOT_FOUND_CODE:
# problem = "%s Service unavailable from %s, check for proper hostname" % \
# (response.status_code, self.service_url)
# raise Exception(problem)
errorResponse = ErrorResponse(response.status_code, response.content)
response = RallyRESTResponse(self.session, context, request_url, errorResponse, self.hydration, 0)
return response
response = RallyRESTResponse(self.session, context, request_url, response,
self.hydration, limit, **kwargs)
if self._log:
if response.status_code == HTTP_REQUEST_SUCCESS_CODE:
#req_target = "/".join(request_url.split('/'))
slm_ws_ver = '/%s/' % (WEB_SERVICE % WS_API_VERSION)
req_target, oid = request_url.split(slm_ws_ver)[-1].rsplit('/', 1)
desc = '%s TotalResultCount %s' % (req_target, response.resultCount)
else:
desc = response.errors[0]
self._logDest.write('%s %s %s\n' % (timestamp(), response.status_code, desc))
self._logDest.flush()
def __init__(self, status_code, problem):
self.status_code = status_code
self.headers = {'placeholder' : True}
self.content = {'OperationResult' : {'Errors' : [problem],
'Warnings': [],
'Results' : [],
}
}
prob_str = str(problem)
if ErrorResponse.SECURITY_ERROR in prob_str:
self.content['OperationResult']['Errors'] = [ErrorResponse.SECURITY_ERROR]
if ErrorResponse.INVALID_CREDENTIALS in prob_str:
self.content['OperationResult']['Errors'] = [ErrorResponse.INVALID_CREDENTIALS]
if augments:
resource += ("&" + "&".join(augments))
full_resource_url = "%s/%s" % (self.service_url, resource)
if self._log:
self._logDest.write('%s DELETE %s\n' % (timestamp(), resource))
response = self.session.delete(full_resource_url, headers=RALLY_REST_HEADERS)
if response and response.status_code != HTTP_REQUEST_SUCCESS_CODE:
if self._log:
self._logDest.write('%s %s %s ...\n' % \
(timestamp(), response.status_code, response.content[:56]))
self._logDest.flush()
##
## if kwargs.get('debug', False):
## print(response.status_code, response.headers, response.content)
##
errorResponse = ErrorResponse(response.status_code, response.content)
response = RallyRESTResponse(self.session, context, resource, errorResponse, self.hydration, 0)
problem = "ERRORS: %s\nWARNINGS: %s\n" % ("\n".join(response.errors),
"\n".join(response.warnings))
raise RallyRESTAPIError(problem)
##
## print(response.content)
##
response = RallyRESTResponse(self.session, context, resource, response, "shell", 0)
if response.errors:
status = False
desc = response.errors[0]
else:
status = True
desc = '%s deleted' % entityName
if self._log:
## # the json dict should have a key named 'QueryResult' or 'CreateResult' or
## # 'DeleteResult' or 'UpdateResult' or 'OperationResult'
##
self.status_code = response.status_code
self.headers = response.headers
##
## print("RallyRESTResponse.status_code is %s" % self.status_code)
## print("RallyRESTResponse.headers: %s" % repr(self.headers))
## # response has these keys: url, status_code, headers, raw, _content, encoding, reason, elapsed, history, connection
##
## if self.status_code == 405:
## print("RallyRESTResponse.status_code is %s" % self.status_code)
## print(response.content)
## print("x" * 80)
##
if isinstance(response, ErrorResponse):
if 'OperationResult' in response.content:
if 'Errors' in response.content['OperationResult']:
self.errors = response.content['OperationResult']['Errors']
return
self._stdFormat = True
try:
self.content = response.json()
except:
problem = "Response for request: {0} either was not JSON content or was an invalidly formed/incomplete JSON structure".format(self.resource)
raise RallyResponseError(problem)
##
## print("response content: %s" % self.content)
##
self.request_type, self.data = self._determineRequestResponseType(request)
##
# or 'OperationResult' whose value is in turn a dict with values of
# 'Errors', 'Warnings', 'Results'
response = self.session.get(request_url, timeout=SERVICE_REQUEST_TIMEOUT)
except Exception as ex:
if response:
##
## print("Exception detected for session.get requests, response status code: %s" % response.status_code)
##
ret_code, content = response.status_code, response.content
else:
ret_code, content = PAGE_NOT_FOUND_CODE, str(ex.args[0])
if self._log:
self._logDest.write('%s %s\n' % (timestamp(), ret_code))
self._logDest.flush()
errorResponse = ErrorResponse(ret_code, content)
response = RallyRESTResponse(self.session, context, request_url, errorResponse, self.hydration, 0)
return response
##
## print("response.status_code is %s" % response.status_code)
##
if response.status_code != HTTP_REQUEST_SUCCESS_CODE:
if self._log:
code, verbiage = response.status_code, response.content[:56]
self._logDest.write('%s %s %s ...\n' % (timestamp(), code, verbiage))
self._logDest.flush()
##
## print(response)
##
#if response.status_code == PAGE_NOT_FOUND_CODE:
# problem = "%s Service unavailable from %s, check for proper hostname" % \