From d661479f2f4028d72d522eb455c39c9c4e4b709f Mon Sep 17 00:00:00 2001 From: Guy Lichtman <1395797+glicht@users.noreply.github.com> Date: Mon, 30 Dec 2019 22:52:05 +0200 Subject: [PATCH 1/3] support ssl_ca_cert option. improved env variable configuration --- README.md | 10 ++++++++++ demisto_client/__init__.py | 23 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f5ebf0c..dc69f5d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,16 @@ Follow these instructions to generate your Demisto API Key. 1. In Demisto, navigate to **Settings > API Keys**. 2. Click the **Generate Your Key** button. +To avoid hard coding configurations in your code, it is possible to specify configruation params +as the following environment variables (env variables will be used if parameters are not specified): + + * DEMISTO_BASE_URL + * DEMISTO_API_KEY + * DEMISTO_USERNAME + * DEMISTO_PASSWORD + * DEMISTO_VERIFY_SSL (true/false. Default: true) + * SSL_CERT_FILE (specify an alternate certificate bundle) + ### 2. Create a Demisto client instance with the api-key and server-url: ```python import demisto_client diff --git a/demisto_client/__init__.py b/demisto_client/__init__.py index bdef139..92d4873 100644 --- a/demisto_client/__init__.py +++ b/demisto_client/__init__.py @@ -16,26 +16,30 @@ __version__ = 'dev' -def configure(base_url=None, api_key=None, verify_ssl=True, proxy=None, username=None, password=None, - debug=False): +def configure(base_url=None, api_key=None, verify_ssl=None, proxy=None, username=None, password=None, + ssl_ca_cert=None, debug=False): """ 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. - To avoid hard coding configurations in your code, it is also possible to specify api_key, username, password - and base_url as the following environment variables (env variables will be used if parameters are not specified): + To avoid hard coding configurations in your code, it is possible to specify configruation params + as the following environment variables (env variables will be used if parameters are not specified): * DEMISTO_BASE_URL * DEMISTO_API_KEY * DEMISTO_USERNAME * DEMISTO_PASSWORD + * DEMISTO_VERIFY_SSL (true/false. Default: true) + * SSL_CERT_FILE (specify an alternate certificate bundle) :param base_url: str - Base url of your Demisto instance. :param api_key: str - API key generated by your instance. :param username: str - Username of the user account. :param password: str - Password of the user account. - :param verify_ssl: bool - Indicates if valid SSLs are required for connection. + :param verify_ssl: bool - Indicates if valid SSLs are required for connection. If not specified (None) + will default to True. :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. :return: Returns an API client configuration identical to the Configuration() method. """ @@ -45,12 +49,21 @@ def configure(base_url=None, api_key=None, verify_ssl=True, proxy=None, username username = os.getenv('DEMISTO_USERNAME') if password is None: password = os.getenv('DEMISTO_PASSWORD') + if ssl_ca_cert is None: + ssl_ca_cert = os.getenv('SSL_CERT_FILE') + if verify_ssl is None: + verify_env = os.getenv('DEMISTO_VERIFY_SSL') + if verify_env: + verify_ssl = verify_env.lower() not in ['false', '0', 'no'] + else: + verify_ssl = True configuration = Configuration() configuration.api_key['Authorization'] = api_key configuration.host = base_url or os.getenv('DEMISTO_BASE_URL', None) configuration.verify_ssl = verify_ssl configuration.proxy = proxy configuration.debug = debug + configuration.ssl_ca_cert = ssl_ca_cert if not configuration.host: raise ValueError('You must specify base_url either as a parameter or via env variable: DEMISTO_BASE_URL') From c1aedc75115f6e8d78091151313cac5829bd1000 Mon Sep 17 00:00:00 2001 From: Guy Lichtman <1395797+glicht@users.noreply.github.com> Date: Mon, 30 Dec 2019 22:55:04 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2663a6f..5664abe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ [PyPI History][1] [1]: https://pypi.org/project/demisto-py/#history +## 2.0.8 +* Added `ssl_ca_cert` configuration option to specify an alternate certificate bundle. +* Added support for additional configuration environment variables: + * `DEMISTO_VERIFY_SSL` + * `SSL_CERT_FILE` ## 2.0.7 * Added `investigation_add_entries_sync` method creating a new entry in existing investigation. From 1a140e0642cfecbf92b65be260773a9ef425a76c Mon Sep 17 00:00:00 2001 From: Guy Lichtman <1395797+glicht@users.noreply.github.com> Date: Mon, 30 Dec 2019 23:13:45 +0200 Subject: [PATCH 3/3] pull request template --- .github/pull_request_template.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..77afa3f --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,14 @@ + + +## Status +Ready/In Progress/In Hold (Reason for hold) + +## Related Issues +fixes: link to the issue + +## Description +A few sentences describing the overall goals of the pull request's commits. + +## Must have +- [ ] Unit Test or Example Code +- [ ] Changelog entry