FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

draft mtls support by mredolatti · Pull Request #521 · splitio/python-client · GitHub

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 18 additions & 5 deletions splitio/api/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from collections import namedtuple

import requests
import logging
_LOGGER = logging.getLogger(__name__)


HttpResponse = namedtuple('HttpResponse', ['status_code', 'body'])


class HttpClientException(Exception):
"""HTTP Client exception."""

Expand All @@ -28,7 +28,7 @@ class HttpClient(object):
AUTH_URL = 'https://auth.split.io/api'
TELEMETRY_URL = 'https://telemetry.split.io/api'

def __init__(self, timeout=None, sdk_url=None, events_url=None, auth_url=None, telemetry_url=None):
def __init__(self, timeout=None, sdk_url=None, events_url=None, auth_url=None, telemetry_url=None, tls_config=None):
"""
Class constructor.

Expand All @@ -51,6 +51,8 @@ def __init__(self, timeout=None, sdk_url=None, events_url=None, auth_url=None, t
'telemetry': telemetry_url if telemetry_url is not None else self.TELEMETRY_URL,
}

self._tls = tls_config if tls_config else {}

def _build_url(self, server, path):
"""
Build URL according to server specified.
Expand Down Expand Up @@ -105,7 +107,8 @@ def get(self, server, path, sdk_key, query=None, extra_headers=None): # pylint:
self._build_url(server, path),
params=query,
headers=headers,
timeout=self._timeout
timeout=self._timeout,
cert=self._certs(),
)
return HttpResponse(response.status_code, response.text)
except Exception as exc: # pylint: disable=broad-except
Expand Down Expand Up @@ -142,8 +145,18 @@ def post(self, server, path, sdk_key, body, query=None, extra_headers=None): #
json=body,
params=query,
headers=headers,
timeout=self._timeout
timeout=self._timeout,
cert=self._certs(),
)
return HttpResponse(response.status_code, response.text)
except Exception as exc: # pylint: disable=broad-except
raise HttpClientException('requests library is throwing exceptions') from exc


def _certs(self):
"""
Get certificates as a tuple if they're set, None otherwise.
"""
if 'tlsClientCertificate' in self._tls and 'tlsClientPrivateKey' in self._tls:
return (self._tls.get('tlsClientCertificate'), self._tls.get('tlsClientPrivateKey'))
return None
2 changes: 2 additions & 0 deletions splitio/client/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
'IPAddressesEnabled': True,
'impressionsMode': 'OPTIMIZED',
'impressionListener': None,
'tlsClientCertificate': None,
'tlsClientPrivateKey': None,
'redisLocalCacheEnabled': True,
'redisLocalCacheTTL': 5,
'redisHost': 'localhost',
Expand Down
6 changes: 5 additions & 1 deletion splitio/client/factory.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,16 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
telemetry_evaluation_producer = telemetry_producer.get_telemetry_evaluation_producer()
telemetry_init_producer = telemetry_producer.get_telemetry_init_producer()

tls_keys = ['tlsClientCertificate', 'tlsClientPrivateKey']
tls_cfg = {k: cfg[k] for k in tls_keys} if all(k in cfg for k in tls_keys) else None

http_client = HttpClient(
sdk_url=sdk_url,
events_url=events_url,
auth_url=auth_api_base_url,
telemetry_url=telemetry_api_base_url,
timeout=cfg.get('connectionTimeout')
timeout=cfg.get('connectionTimeout'),
tls_config=tls_cfg
)

sdk_metadata = util.get_metadata(cfg)
Expand Down

Back | FazBrowse Home | New Git URL