Skip to content

Commit 22829bf

Browse files
authored
feat: proxy parameter for Client (#81)
1 parent 4912a11 commit 22829bf

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

vt/client.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,20 @@ class Client:
178178
testing purposes.
179179
:param trust_env: Get proxies information from HTTP_PROXY/HTTPS_PROXY
180180
environment variables if the parameter is True (False by default).
181+
:param timeout: A int that determines the number of seconds to wait for
182+
a request to timeout (300 by default).
183+
:param proxy: A string indicating the proxy to use for requests
184+
made by the client (None by default).
181185
:type apikey: str
182186
:type agent: str
183187
:type host: str
184188
:type trust_env: bool
189+
:type timeout: int
190+
:type proxy: str
185191
"""
186192

187193
def __init__(self, apikey, agent="unknown", host=None, trust_env=False,
188-
timeout=300):
194+
timeout=300, proxy=None):
189195
"""Initialize the client with the provided API key."""
190196

191197
if not isinstance(apikey, str):
@@ -200,6 +206,7 @@ def __init__(self, apikey, agent="unknown", host=None, trust_env=False,
200206
self._session = None
201207
self._trust_env = trust_env
202208
self._timeout = timeout
209+
self._proxy = proxy
203210

204211
def _full_url(self, path, *args):
205212
try:
@@ -281,7 +288,8 @@ def delete(self, path, *path_args):
281288
async def delete_async(self, path, *path_args):
282289
"""Like :func:`delete` but returns a coroutine."""
283290
return ClientResponse(
284-
await self._get_session().delete(self._full_url(path, *path_args)))
291+
await self._get_session().delete(
292+
self._full_url(path, *path_args), proxy=self._proxy))
285293

286294
def download_file(self, hash, file):
287295
"""Downloads a file given its hash (SHA-256, SHA-1 or MD5).
@@ -347,7 +355,7 @@ async def get_async(self, path, *path_args, params=None):
347355
return ClientResponse(
348356
await self._get_session().get(
349357
self._full_url(path, *path_args),
350-
params=params))
358+
params=params, proxy=self._proxy))
351359

352360
def get_data(self, path, *path_args, params=None):
353361
"""Sends a GET request to a given API endpoint and returns response's data.
@@ -467,7 +475,7 @@ async def patch_async(self, path, *path_args, data=None):
467475
return ClientResponse(
468476
await self._get_session().patch(
469477
self._full_url(path, *path_args),
470-
data=data))
478+
data=data, proxy=self._proxy))
471479

472480
def patch_object(self, path, *path_args, obj):
473481
"""Sends a PATCH request for modifying an object.
@@ -514,7 +522,7 @@ async def post_async(self, path, *path_args, data=None):
514522
return ClientResponse(
515523
await self._get_session().post(
516524
self._full_url(path, *path_args),
517-
data=data))
525+
data=data, proxy=self._proxy))
518526

519527
def post_object(self, path, *path_args, obj):
520528
"""Sends a POST request for creating an object.
@@ -610,7 +618,8 @@ async def scan_file_async(self, file, wait_for_completion=False):
610618

611619
upload_url = await self.get_data_async('/files/upload_url')
612620
response = ClientResponse(
613-
await self._get_session().post(upload_url, data=form_data))
621+
await self._get_session().post(
622+
upload_url, data=form_data, proxy=self._proxy))
614623

615624
analysis = await self._response_to_object(response)
616625

@@ -638,7 +647,8 @@ async def scan_url_async(self, url, wait_for_completion=False):
638647
form_data.add_field('url', url)
639648

640649
response = ClientResponse(
641-
await self._get_session().post(self._full_url('/urls'), data=form_data))
650+
await self._get_session().post(
651+
self._full_url('/urls'), data=form_data, proxy=self._proxy))
642652

643653
analysis = await self._response_to_object(response)
644654

vt/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.7.6'
1+
__version__ = '0.8.0'

0 commit comments

Comments
 (0)