Skip to content

Commit

Permalink
Merge pull request #31 from demisto/custome-certificate
Browse files Browse the repository at this point in the history
Custom certificate bundle
  • Loading branch information
glicht authored Dec 31, 2019
2 parents c8c4552 + 1a140e0 commit cc3ed50
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- REMINDER: THIS IS A PUBLIC REPO DO NOT POST HERE SECRETS/SENSITIVE DATA -->

## 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions demisto_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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')
Expand Down

0 comments on commit cc3ed50

Please sign in to comment.