11
11
STREAM_FLAGS_PATH = '/flags'
12
12
13
13
14
+ class HTTPConfig (object ):
15
+ """Advanced HTTP configuration options for the SDK client.
16
+
17
+ This class groups together HTTP/HTTPS-related configuration properties that rarely need to be changed.
18
+ If you need to set these, construct an `HTTPConfig` instance and pass it as the `http` parameter when
19
+ you construct the main :class:`Config` for the SDK client.
20
+
21
+ For some of these properties, :class:`Config` also has properties with the same names; the latter are
22
+ deprecated and will be removed in the future, and if you specify an `HTTPConfig` instance then the
23
+ corresponding `Config` properties will be ignored.
24
+ """
25
+ def __init__ (self ,
26
+ connect_timeout = 10 ,
27
+ read_timeout = 15 ,
28
+ http_proxy = None ,
29
+ ca_certs = None ,
30
+ cert_file = None ,
31
+ disable_ssl_verification = False ):
32
+ """
33
+ :param float connect_timeout: The connect timeout for network connections in seconds.
34
+ :param float read_timeout: The read timeout for network connections in seconds.
35
+ :param http_proxy: Use a proxy when connecting to LaunchDarkly. This is the full URI of the
36
+ proxy; for example: http://my-proxy.com:1234. Note that unlike the standard `http_proxy` environment
37
+ variable, this is used regardless of whether the target URI is HTTP or HTTPS (the actual LaunchDarkly
38
+ service uses HTTPS, but a Relay Proxy instance could use HTTP). Setting this Config parameter will
39
+ override any proxy specified by an environment variable, but only for LaunchDarkly SDK connections.
40
+ :param string ca_certs: If using a custom certificate authority, set this to the file path of the
41
+ certificate bundle.
42
+ :param string cert_file: If using a custom client certificate, set this to the file path of the
43
+ certificate.
44
+ :param bool disable_ssl_verification: If true, completely disables SSL verification and certificate
45
+ verification for secure requests. This is unsafe and should not be used in a production environment;
46
+ instead, use a self-signed certificate and set `ca_certs`.
47
+ """
48
+ self .__connect_timeout = connect_timeout
49
+ self .__read_timeout = read_timeout
50
+ self .__http_proxy = http_proxy
51
+ self .__ca_certs = ca_certs
52
+ self .__cert_file = cert_file
53
+ self .__disable_ssl_verification = disable_ssl_verification
54
+
55
+ @property
56
+ def connect_timeout (self ):
57
+ return self .__connect_timeout
58
+
59
+ @property
60
+ def read_timeout (self ):
61
+ return self .__read_timeout
62
+
63
+ @property
64
+ def http_proxy (self ):
65
+ return self .__http_proxy
66
+
67
+ @property
68
+ def ca_certs (self ):
69
+ return self .__ca_certs
70
+
71
+ @property
72
+ def cert_file (self ):
73
+ return self .__cert_file
74
+
75
+ @property
76
+ def disable_ssl_verification (self ):
77
+ return self .__disable_ssl_verification
78
+
14
79
class Config (object ):
15
80
"""Advanced configuration options for the SDK client.
16
81
@@ -27,6 +92,7 @@ def __init__(self,
27
92
flush_interval = 5 ,
28
93
stream_uri = 'https://stream.launchdarkly.com' ,
29
94
stream = True ,
95
+ initial_reconnect_delay = 1 ,
30
96
verify_ssl = True ,
31
97
defaults = None ,
32
98
send_events = None ,
@@ -47,15 +113,18 @@ def __init__(self,
47
113
diagnostic_opt_out = False ,
48
114
diagnostic_recording_interval = 900 ,
49
115
wrapper_name = None ,
50
- wrapper_version = None ):
116
+ wrapper_version = None ,
117
+ http = None ):
51
118
"""
52
119
:param string sdk_key: The SDK key for your LaunchDarkly account.
53
120
:param string base_uri: The base URL for the LaunchDarkly server. Most users should use the default
54
121
value.
55
122
:param string events_uri: The URL for the LaunchDarkly events server. Most users should use the
56
123
default value.
57
- :param float connect_timeout: The connect timeout for network connections in seconds.
58
- :param float read_timeout: The read timeout for network connections in seconds.
124
+ :param float connect_timeout: Deprecated; use `http` instead and specify the `connect_timeout` as
125
+ part of :class:`HTTPConfig`.
126
+ :param float read_timeout: Deprecated; use `http` instead and specify the `read_timeout` as
127
+ part of :class:`HTTPConfig`.
59
128
:param int events_upload_max_batch_size: The maximum number of analytics events that the client will
60
129
send at once.
61
130
:param int events_max_pending: The capacity of the events buffer. The client buffers up to this many
@@ -67,6 +136,12 @@ def __init__(self,
67
136
use the default value.
68
137
:param bool stream: Whether or not the streaming API should be used to receive flag updates. By
69
138
default, it is enabled. Streaming should only be disabled on the advice of LaunchDarkly support.
139
+ :param float initial_reconnect_delay: The initial reconnect delay (in seconds) for the streaming
140
+ connection. The streaming service uses a backoff algorithm (with jitter) every time the connection needs
141
+ to be reestablished. The delay for the first reconnection will start near this value, and then
142
+ increase exponentially for any subsequent connection failures.
143
+ :param bool verify_ssl: Deprecated; use `http` instead and specify `disable_ssl_verification` as
144
+ part of :class:`HTTPConfig` if you want to turn off SSL verification (not recommended).
70
145
:param bool send_events: Whether or not to send events back to LaunchDarkly. This differs from
71
146
`offline` in that it affects only the sending of client-side events, not streaming or polling for
72
147
events from the server. By default, events will be sent.
@@ -99,11 +174,8 @@ def __init__(self,
99
174
:type event_processor_class: (ldclient.config.Config) -> EventProcessor
100
175
:param update_processor_class: A factory for an UpdateProcessor implementation taking the sdk key,
101
176
config, and FeatureStore implementation
102
- :param http_proxy: Use a proxy when connecting to LaunchDarkly. This is the full URI of the
103
- proxy; for example: http://my-proxy.com:1234. Note that unlike the standard `http_proxy` environment
104
- variable, this is used regardless of whether the target URI is HTTP or HTTPS (the actual LaunchDarkly
105
- service uses HTTPS, but a Relay Proxy instance could use HTTP). Setting this Config parameter will
106
- override any proxy specified by an environment variable, but only for LaunchDarkly SDK connections.
177
+ :param http_proxy: Deprecated; use `http` instead and specify the `http_proxy` as part of
178
+ :class:`HTTPConfig`.
107
179
:param bool diagnostic_opt_out: Unless this field is set to True, the client will send
108
180
some diagnostics data to the LaunchDarkly servers in order to assist in the development of future SDK
109
181
improvements. These diagnostics consist of an initial payload containing some details of SDK in use,
@@ -118,6 +190,8 @@ def __init__(self,
118
190
use. If `wrapper_name` is not set, this field will be ignored. Otherwise the version string will
119
191
be included in the HTTP headers along with the `wrapper_name` during requests to the LaunchDarkly
120
192
servers.
193
+ :param HTTPConfig http: Optional properties for customizing the client's HTTP/HTTPS behavior. See
194
+ :class:`HTTPConfig`.
121
195
"""
122
196
self .__sdk_key = sdk_key
123
197
@@ -129,6 +203,7 @@ def __init__(self,
129
203
self .__stream_uri = stream_uri .rstrip ('\\ ' )
130
204
self .__update_processor_class = update_processor_class
131
205
self .__stream = stream
206
+ self .__initial_reconnect_delay = initial_reconnect_delay
132
207
self .__poll_interval = max (poll_interval , 30 )
133
208
self .__use_ldd = use_ldd
134
209
self .__feature_store = InMemoryFeatureStore () if not feature_store else feature_store
@@ -154,6 +229,7 @@ def __init__(self,
154
229
self .__diagnostic_recording_interval = max (diagnostic_recording_interval , 60 )
155
230
self .__wrapper_name = wrapper_name
156
231
self .__wrapper_version = wrapper_version
232
+ self .__http = http
157
233
158
234
@classmethod
159
235
def default (cls ):
@@ -178,6 +254,7 @@ def copy_with_new_sdk_key(self, new_sdk_key):
178
254
flush_interval = self .__flush_interval ,
179
255
stream_uri = self .__stream_uri ,
180
256
stream = self .__stream ,
257
+ initial_reconnect_delay = self .__initial_reconnect_delay ,
181
258
verify_ssl = self .__verify_ssl ,
182
259
defaults = self .__defaults ,
183
260
send_events = self .__send_events ,
@@ -196,7 +273,8 @@ def copy_with_new_sdk_key(self, new_sdk_key):
196
273
diagnostic_opt_out = self .__diagnostic_opt_out ,
197
274
diagnostic_recording_interval = self .__diagnostic_recording_interval ,
198
275
wrapper_name = self .__wrapper_name ,
199
- wrapper_version = self .__wrapper_version )
276
+ wrapper_version = self .__wrapper_version ,
277
+ http = self .__http )
200
278
201
279
# for internal use only - probably should be part of the client logic
202
280
def get_default (self , key , default ):
@@ -244,6 +322,9 @@ def stream(self):
244
322
return self .__stream
245
323
246
324
@property
325
+ def initial_reconnect_delay (self ):
326
+ return self .__initial_reconnect_delay
327
+ @property
247
328
def poll_interval (self ):
248
329
return self .__poll_interval
249
330
@@ -335,6 +416,19 @@ def wrapper_name(self):
335
416
def wrapper_version (self ):
336
417
return self .__wrapper_version
337
418
419
+ @property
420
+ def http (self ):
421
+ if self .__http is None :
422
+ return HTTPConfig (
423
+ connect_timeout = self .__connect_timeout ,
424
+ read_timeout = self .__read_timeout ,
425
+ http_proxy = self .__http_proxy ,
426
+ ca_certs = None ,
427
+ cert_file = None ,
428
+ disable_ssl_verification = not self .__verify_ssl
429
+ )
430
+ return self .__http
431
+
338
432
def _validate (self ):
339
433
if self .offline is False and self .sdk_key is None or self .sdk_key == '' :
340
434
log .warning ("Missing or blank sdk_key." )
0 commit comments