Skip to content

Commit

Permalink
Increasing the connection pool size in case we're using gitlab-ci bui…
Browse files Browse the repository at this point in the history
…ld (#63)

Co-authored-by: Guy Lichtman <1395797+glicht@users.noreply.github.com>
Co-authored-by: hod-alpert <haplert@paloaltonetworks.com>
Co-authored-by: avidan-H <ahessing@paloaltonetworks.com>
Co-authored-by: avidan-H <46294017+avidan-H@users.noreply.github.com>
  • Loading branch information
5 people authored May 26, 2021
1 parent 13f2d3c commit 9daf1c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
[PyPI History][1]

[1]: https://pypi.org/project/demisto-py/#history
## 3.0.1
* Support setting the number of parallel connections to a single host via the `DEMISTO_CONNECTION_POOL_MAXSIZE` environment variable.

## 3.0.0
* Drop support for Python 2. demisto-py now requires Python 3.7 or later. Pin to demisto-py <2.0.24 to maintain 2.7 support.
* Fixed bug in arguments required for the route: `/v2/inv-playbook/task/form/submit`.
Expand Down
26 changes: 25 additions & 1 deletion demisto_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def configure(base_url=None, api_key=None, verify_ssl=None, proxy=None, username=None, password=None,
ssl_ca_cert=None, debug=False):
ssl_ca_cert=None, debug=False, connection_pool_maxsize=None):
"""
This wrapper provides an easier to use method of configuring the API client. The base
Configuration method is still exposed if you wish to further configure the API Client.
Expand All @@ -32,6 +32,7 @@ def configure(base_url=None, api_key=None, verify_ssl=None, proxy=None, username
* DEMISTO_PASSWORD
* DEMISTO_VERIFY_SSL (true/false. Default: true)
* SSL_CERT_FILE (specify an alternate certificate bundle)
* DEMISTO_CONNECTION_POOL_MAXSIZE (specify a connection pool max size)
:param base_url: str - Base url of your Demisto instance.
:param api_key: str - API key generated by your instance.
Expand All @@ -42,6 +43,7 @@ def configure(base_url=None, api_key=None, verify_ssl=None, proxy=None, username
:param proxy: dict - Dict object of your proxy settings.
:param ssl_ca_cert: str - specify an alternate certificate bundle
:param debug: bool - Include verbose logging.
:param connection_pool_maxsize: int - specify a connection max pool size
:return: Returns an API client configuration identical to the Configuration() method.
"""
if api_key is None:
Expand All @@ -58,6 +60,15 @@ def configure(base_url=None, api_key=None, verify_ssl=None, proxy=None, username
verify_ssl = verify_env.lower() not in ['false', '0', 'no']
else:
verify_ssl = True
if connection_pool_maxsize is None:
connection_pool_maxsize = os.getenv('DEMISTO_CONNECTION_POOL_MAXSIZE')
if connection_pool_maxsize:
if not connection_pool_maxsize.isdigit():
err_msg = ('DEMISTO_CONNECTION_POOL_MAXSIZE env variable should be set to a number'
f' but instead received "{connection_pool_maxsize}"')
raise ValueError(err_msg)
else:
connection_pool_maxsize = int(connection_pool_maxsize)
configuration = Configuration()
configuration.api_key['Authorization'] = api_key
configuration.host = base_url or os.getenv('DEMISTO_BASE_URL', None)
Expand All @@ -67,6 +78,8 @@ def configure(base_url=None, api_key=None, verify_ssl=None, proxy=None, username
configuration.proxy = proxy
configuration.debug = debug
configuration.ssl_ca_cert = ssl_ca_cert
if connection_pool_maxsize:
configuration.connection_pool_maxsize = connection_pool_maxsize

if not configuration.host:
raise ValueError('You must specify base_url either as a parameter or via env variable: DEMISTO_BASE_URL')
Expand Down Expand Up @@ -95,6 +108,15 @@ def login(base_url=None, username=None, password=None, verify_ssl=True, proxy=No
configuration_orig.verify_ssl = verify_ssl
configuration_orig.proxy = proxy
configuration_orig.debug = debug
connection_pool_maxsize = os.getenv('DEMISTO_CONNECTION_POOL_MAXSIZE')
if connection_pool_maxsize:
if connection_pool_maxsize.isdigit():
connection_pool_maxsize = int(connection_pool_maxsize)
configuration_orig.connection_pool_maxsize = connection_pool_maxsize
else:
err_msg = ('DEMISTO_CONNECTION_POOL_MAXSIZE env variable should be set to a number'
f' but instead received "{connection_pool_maxsize}"')
raise ValueError(err_msg)
api_client = ApiClient(configuration_orig)
api_client.user_agent = 'demisto-py/' + __version__
api_instance = demisto_api.DefaultApi(api_client)
Expand All @@ -115,6 +137,8 @@ def login(base_url=None, username=None, password=None, verify_ssl=True, proxy=No
configuration.verify_ssl = verify_ssl
configuration.proxy = proxy
configuration.debug = debug
if connection_pool_maxsize and isinstance(connection_pool_maxsize, int):
configuration.connection_pool_maxsize = connection_pool_maxsize
api_client = ApiClient(configuration, header_name="X-XSRF-TOKEN", header_value=xsrf_token,
cookie=cookies)
api_client.user_agent = 'demisto-py/' + __version__
Expand Down

0 comments on commit 9daf1c1

Please sign in to comment.