Added verify_ssl_cert parameter to database initializer

This commit is contained in:
Itai Shirav 2018-12-14 11:13:23 +02:00
parent 8c22c753a8
commit 9df82a44ec
3 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,7 @@ Change Log
Unreleased Unreleased
---------- ----------
- Added `timeout` parameter to database initializer (SUHAR1K) - Added `timeout` parameter to database initializer (SUHAR1K)
- Added `verify_ssl_cert` parameter to database initializer
- Added `final()` method to querysets (M1hacka) - Added `final()` method to querysets (M1hacka)
v1.0.3 v1.0.3

View File

@ -10,7 +10,7 @@ infi.clickhouse_orm.database
Database instances connect to a specific ClickHouse database for running queries, Database instances connect to a specific ClickHouse database for running queries,
inserting data and other operations. inserting data and other operations.
#### Database(db_name, db_url="http://localhost:8123/", username=None, password=None, readonly=False, autocreate=True, timeout=60) #### Database(db_name, db_url="http://localhost:8123/", username=None, password=None, readonly=False, autocreate=True, timeout=60, verify_ssl_cert=True)
Initializes a database instance. Unless it's readonly, the database will be Initializes a database instance. Unless it's readonly, the database will be
@ -23,6 +23,7 @@ created on the ClickHouse server if it does not already exist.
- `readonly`: use a read-only connection. - `readonly`: use a read-only connection.
- `autocreate`: automatically create the database if it does not exist (unless in readonly mode). - `autocreate`: automatically create the database if it does not exist (unless in readonly mode).
- `timeout`: the connection timeout in seconds. - `timeout`: the connection timeout in seconds.
- `verify_ssl_cert`: whether to verify the server's certificate when connecting via HTTPS.
#### add_setting(name, value) #### add_setting(name, value)

View File

@ -73,7 +73,8 @@ class Database(object):
''' '''
def __init__(self, db_name, db_url='http://localhost:8123/', def __init__(self, db_name, db_url='http://localhost:8123/',
username=None, password=None, readonly=False, autocreate=True, timeout=60): username=None, password=None, readonly=False, autocreate=True,
timeout=60, verify_ssl_cert=True):
''' '''
Initializes a database instance. Unless it's readonly, the database will be Initializes a database instance. Unless it's readonly, the database will be
created on the ClickHouse server if it does not already exist. created on the ClickHouse server if it does not already exist.
@ -85,6 +86,7 @@ class Database(object):
- `readonly`: use a read-only connection. - `readonly`: use a read-only connection.
- `autocreate`: automatically create the database if it does not exist (unless in readonly mode). - `autocreate`: automatically create the database if it does not exist (unless in readonly mode).
- `timeout`: the connection timeout in seconds. - `timeout`: the connection timeout in seconds.
- `verify_ssl_cert`: whether to verify the server's certificate when connecting via HTTPS.
''' '''
self.db_name = db_name self.db_name = db_name
self.db_url = db_url self.db_url = db_url
@ -93,6 +95,7 @@ class Database(object):
self.readonly = False self.readonly = False
self.timeout = timeout self.timeout = timeout
self.request_session = requests.Session() self.request_session = requests.Session()
self.request_session.verify = verify_ssl_cert
self.settings = {} self.settings = {}
self.db_exists = False # this is required before running _is_existing_database self.db_exists = False # this is required before running _is_existing_database
self.db_exists = self._is_existing_database() self.db_exists = self._is_existing_database()