Skip to content

Commit 484e77c

Browse files
committed
Version 1.0.26: Allow custom requests parameters
* for ex. disabling SSL verification as in test_status_connection.py
1 parent 2ab9ddc commit 484e77c

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

ravenpackapi/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
from ravenpackapi.utils.constants import JSON_AVAILABLE_FIELDS, ENTITY_TYPES
1515

1616
_VALID_METHODS = ('get', 'post', 'put', 'delete')
17-
VERSION = '1.0.25'
17+
VERSION = '1.0.26'
1818

1919
logger = logging.getLogger("ravenpack.core")
2020

2121

2222
class RPApi(object):
2323
_CHUNK_SIZE = 32 * 1024
24+
common_request_params = {}
2425

2526
def __init__(self, api_key=None):
2627
self._BASE_URL = os.environ.get(
@@ -59,6 +60,7 @@ def request(self, endpoint, data=None, params=None, method='get', stream=False):
5960
data=json.dumps(data) if data else None,
6061
params=params,
6162
stream=stream,
63+
**self.common_request_params
6264
)
6365
if self.log_curl_commands:
6466
logger.info("API query to %s" % to_curl(response.request))
@@ -159,3 +161,7 @@ def get_entity_mapping(self, identifiers):
159161
)
160162
data = response.json()
161163
return RPMappingResults(data)
164+
165+
def get_status(self):
166+
response = self.request('/status')
167+
return response.json()

ravenpackapi/models/job.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def save_to_file(self, filename):
115115
response = requests.get(job.url,
116116
headers=api.headers,
117117
stream=True,
118+
**api.common_request_params
118119
)
119120
if response.status_code != 200:
120121
logger.error("Error calling the API, we tried: %s" % to_curl(response.request))
@@ -136,6 +137,7 @@ def iterate_results(self):
136137
r = s.get(job.url,
137138
headers=api.headers,
138139
stream=True,
140+
**api.common_request_params
139141
)
140142
iterator = r.iter_lines(chunk_size=self._CHUNK_SIZE)
141143
headers = next(iterator) # discard the headers
File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
from urllib3.exceptions import InsecureRequestWarning
3+
4+
from ravenpackapi import RPApi
5+
6+
7+
class TestEntityMapping(object):
8+
def test_status(self):
9+
api = RPApi()
10+
status = api.get_status()
11+
assert status.get('status') == 'OK'
12+
13+
def test_status_no_https_verify(self):
14+
api = RPApi()
15+
api.common_request_params['verify'] = False
16+
with pytest.warns(InsecureRequestWarning):
17+
status = api.get_status()
18+
assert status.get('status') == 'OK'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '1.0.25'
3+
VERSION = '1.0.26'
44

55
with open('README.rst') as readme_file:
66
readme = readme_file.read()

0 commit comments

Comments
 (0)