Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0b458f2

Browse files
committedMar 18, 2025·
moved to general tls configuration class
Signed-off-by: GilboaAWS <[email protected]>
1 parent 04d2fb3 commit 0b458f2

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed
 

‎python/python/glide/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
ProtocolVersion,
124124
ReadFrom,
125125
ServerCredentials,
126+
TlsAdvancedConfiguration,
126127
)
127128
from glide.constants import (
128129
OK,
@@ -201,6 +202,7 @@
201202
"TJsonUniversalResponse",
202203
"TOK",
203204
"TResult",
205+
"TlsAdvancedConfiguration",
204206
"TXInfoStreamFullResponse",
205207
"TXInfoStreamResponse",
206208
"FtAggregateResponse",

‎python/python/glide/config.py

+31-15
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ class PeriodicChecksStatus(Enum):
139139
"""
140140

141141

142+
class TlsAdvancedConfiguration:
143+
"""
144+
Represents advanced TLS configuration settings.
145+
146+
Attributes:
147+
insecure (Optional[bool]): Indicates whether to bypass TLS certificate verification.
148+
When set to True, the client will bypass certificate validation (for example, when connecting
149+
to servers with self-signed or unauthorized certificates). This setting is useful for development
150+
or testing environments, but should not be used in production due to security risks.
151+
"""
152+
153+
def __init__(self, insecure: Optional[bool] = None):
154+
self.insecure = insecure
155+
156+
142157
class AdvancedBaseClientConfiguration:
143158
"""
144159
Represents the advanced configuration settings for a base Glide client.
@@ -148,29 +163,30 @@ class AdvancedBaseClientConfiguration:
148163
This applies both during initial client creation and any reconnections that may occur during request processing.
149164
**Note**: A high connection timeout may lead to prolonged blocking of the entire command pipeline.
150165
If not explicitly set, a default value of 250 milliseconds will be used.
151-
tls_insecure (Optional[bool]): The TLS state; defaults to secured (False).
152-
When set to True, the client will bypass certificate verification, allowing connections to
153-
Valkey/Redis instances with self-signed or otherwise unauthorized certificates.
154-
This option is intended for local development or testing environments where a valid
155-
certificate may not be available. It is not recommended for production use,
156-
as disabling certificate validation exposes the connection to potential security
157-
risks such as man-in-the-middle attacks.
166+
tls_config (Optional[TlsAdvancedConfiguration]): The advanced TLS configuration settings.
167+
This allows for more granular control of TLS behavior, such as enabling an insecure mode
168+
that bypasses certificate validation.
158169
"""
159170

160171
def __init__(
161172
self,
162173
connection_timeout: Optional[int] = None,
163-
tls_insecure: Optional[bool] = None,
174+
tls_config: Optional[TlsAdvancedConfiguration] = None,
164175
):
165176
self.connection_timeout = connection_timeout
166-
self.tls_insecure = tls_insecure
177+
self.tls_config = tls_config
167178

168179
def _create_a_protobuf_conn_request(
169180
self, request: ConnectionRequest
170181
) -> ConnectionRequest:
171182
if self.connection_timeout:
172183
request.connection_timeout = self.connection_timeout
173-
if True == self.tls_insecure and TlsMode.SecureTls == request.tls_mode:
184+
185+
if (
186+
self.tls_config
187+
and self.tls_config.insecure
188+
and request.tls_mode == TlsMode.SecureTls
189+
):
174190
request.tls_mode = TlsMode.InsecureTls
175191

176192
return request
@@ -186,7 +202,7 @@ class BaseClientConfiguration:
186202
the cluster and find all nodes.
187203
If the server is in standalone mode, only nodes whose addresses were provided will be used by the
188204
client.
189-
For example:
205+
For example::
190206
191207
[
192208
{address:sample-address-0001.use1.cache.amazonaws.com, port:6379},
@@ -311,10 +327,10 @@ class AdvancedGlideClientConfiguration(AdvancedBaseClientConfiguration):
311327
def __init__(
312328
self,
313329
connection_timeout: Optional[int] = None,
314-
tls_insecure: Optional[bool] = None,
330+
tls_config: Optional[TlsAdvancedConfiguration] = None,
315331
):
316332

317-
super().__init__(connection_timeout, tls_insecure)
333+
super().__init__(connection_timeout, tls_config)
318334

319335

320336
class GlideClientConfiguration(BaseClientConfiguration):
@@ -487,9 +503,9 @@ class AdvancedGlideClusterClientConfiguration(AdvancedBaseClientConfiguration):
487503
def __init__(
488504
self,
489505
connection_timeout: Optional[int] = None,
490-
tls_insecure: Optional[bool] = None,
506+
tls_config: Optional[TlsAdvancedConfiguration] = None,
491507
):
492-
super().__init__(connection_timeout, tls_insecure)
508+
super().__init__(connection_timeout, tls_config)
493509

494510

495511
class GlideClusterClientConfiguration(BaseClientConfiguration):

0 commit comments

Comments
 (0)
Please sign in to comment.