Skip to content

Commit

Permalink
bugfix release
Browse files Browse the repository at this point in the history
  • Loading branch information
tjarrettveracode committed Sep 14, 2020
1 parent 52b01a6 commit 3a3c55d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
setup(
name = 'veracode_api_py',
packages = ['veracode_api_py'],
version = '0.6',
version = '0.7',
license='MIT',
description = 'Python helper library for working with the Veracode APIs. Handles retries, pagination, and other features of the modern Veracode REST APIs.',
author = 'Tim Jarrett',
author_email = 'tjarrett@veracode.com',
url = 'https://github.com/tjarrettveracode',
download_url = 'https://github.com/tjarrettveracode/veracode-api-py/archive/v_06.tar.gz',
download_url = 'https://github.com/tjarrettveracode/veracode-api-py/archive/v_07.tar.gz',
keywords = ['veracode', 'veracode-api'],
install_requires=[
'veracode-api-signing'
Expand Down
110 changes: 55 additions & 55 deletions veracode_api_py/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,64 +63,64 @@ def _request(self, url, method, params=None):
logging.exception("Connection error")
raise VeracodeAPIError(e)

def _rest_request(self, url, method, params=None,body=None,fullresponse=False):
# base request method for a REST request
myheaders = {"User-Agent": "api.py"}
if method in ["POST", "PUT"]:
myheaders.update({'Content-type': 'application/json'})

if method == "GET":
# incorporate retries to deal with some failure situations
try:
session = requests.Session()
session.mount(self.base_rest_url, HTTPAdapter(max_retries=3))
request = requests.Request(method, self.base_rest_url + url, params=params, auth=RequestsAuthPluginVeracodeHMAC(), headers=myheaders)
prepared_request = request.prepare()
r = session.send(prepared_request, proxies=self.proxies)
if r.status_code == 500 or r.status_code == 504:
time.sleep(1)
r = requests.Request(method, url, params=params, auth=RequestsAuthPluginVeracodeHMAC(),headers=myheaders,json=body)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
elif method == "POST":
try:
r = requests.post(self.base_rest_url + url,params=params,auth=RequestsAuthPluginVeracodeHMAC(),headers=myheaders,data=body)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
elif method == "PUT":
try:
r = requests.put(self.base_rest_url + url,params=params,auth=RequestsAuthPluginVeracodeHMAC(), headers=myheaders,data=body)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
elif method == "DELETE":
try:
r = requests.delete(self.base_rest_url + url,params=params,auth=RequestsAuthPluginVeracodeHMAC(),headers=myheaders)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
else:
raise VeracodeAPIError("Unsupported HTTP method")
def _rest_request(self, url, method, params=None,body=None,fullresponse=False):
# base request method for a REST request
myheaders = {"User-Agent": "api.py"}
if method in ["POST", "PUT"]:
myheaders.update({'Content-type': 'application/json'})

if method == "GET":
# incorporate retries to deal with some failure situations
try:
session = requests.Session()
session.mount(self.base_rest_url, HTTPAdapter(max_retries=3))
request = requests.Request(method, self.base_rest_url + url, params=params, auth=RequestsAuthPluginVeracodeHMAC(), headers=myheaders)
prepared_request = request.prepare()
r = session.send(prepared_request, proxies=self.proxies)
if r.status_code == 500 or r.status_code == 504:
time.sleep(1)
r = requests.Request(method, url, params=params, auth=RequestsAuthPluginVeracodeHMAC(),headers=myheaders,json=body)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
elif method == "POST":
try:
r = requests.post(self.base_rest_url + url,params=params,auth=RequestsAuthPluginVeracodeHMAC(),headers=myheaders,data=body)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
elif method == "PUT":
try:
r = requests.put(self.base_rest_url + url,params=params,auth=RequestsAuthPluginVeracodeHMAC(), headers=myheaders,data=body)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
elif method == "DELETE":
try:
r = requests.delete(self.base_rest_url + url,params=params,auth=RequestsAuthPluginVeracodeHMAC(),headers=myheaders)
except requests.exceptions.RequestException as e:
logging.exception("Connection error")
raise VeracodeAPIError(e)
else:
raise VeracodeAPIError("Unsupported HTTP method")

if not (r.status_code == requests.codes.ok):
logging.debug("API call returned non-200 HTTP status code: {}".format(r.status_code))
if not (r.status_code == requests.codes.ok):
logging.debug("API call returned non-200 HTTP status code: {}".format(r.status_code))

if not (r.ok):
logging.debug("Error retrieving data. HTTP status code: {}".format(r.status_code))
if r.status_code == 401:
logging.exception("Check that your Veracode API account credentials are correct.")
else:
logging.exception("Error [{}]: {} for request {}".format(r.status_code,r.text, r.request.url))
raise requests.exceptions.RequestException()
elif fullresponse:
return r
else:
if r.text != "":
return r.json()
if not (r.ok):
logging.debug("Error retrieving data. HTTP status code: {}".format(r.status_code))
if r.status_code == 401:
logging.exception("Check that your Veracode API account credentials are correct.")
else:
logging.exception("Error [{}]: {} for request {}".format(r.status_code,r.text, r.request.url))
raise requests.exceptions.RequestException()
elif fullresponse:
return r
else:
return ""
if r.text != "":
return r.json()
else:
return ""

def _rest_paged_request(self, url, method, element, params=None):
all_data = []
Expand Down

0 comments on commit 3a3c55d

Please sign in to comment.