From e476c7b9e6e96942e0900ab073602dc618fd823e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 18 May 2023 09:20:52 -0400 Subject: [PATCH] Avoid deprecationwarning in python 3.10+ Newer python is not backwards compatible with a constant. Attempt to use new constant and fallback to teh old one if unavilable. --- .../common/initramfs/opt/confluent/bin/apiclient | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient b/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient index 12510cc9..d2c49edb 100644 --- a/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient +++ b/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient @@ -21,6 +21,10 @@ class InvalidApiKey(Exception): def msg_align(len): return (len + 3) & ~3 +try: + _protoparm = ssl.PROTOCOL_TLS_CLIENT +except AttributeError: + _protoparm = ssl.PROTOCOL_SSLv23 cryptname = ctypes.util.find_library('crypt') if not cryptname: if os.path.exists('/lib64/libcrypt.so.2') or os.path.exists('/usr/lib64/libcrypt.so.2'): @@ -305,7 +309,7 @@ class HTTPSClient(client.HTTPConnection, object): def check_connections(self): foundsrv = None hosts = self.hosts - ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + ctx = ssl.SSLContext(_protoparm) ctx.load_verify_locations('/etc/confluent/ca.pem') ctx.verify_mode = ssl.CERT_REQUIRED ctx.check_hostname = True @@ -358,7 +362,7 @@ class HTTPSClient(client.HTTPConnection, object): psock = socket.socket(addrinf[0]) psock.settimeout(15) psock.connect(addrinf[4]) - ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + ctx = ssl.SSLContext(_protoparm) ctx.load_verify_locations('/etc/confluent/ca.pem') host = self.host.split('%', 1)[0] if '[' not in host and ':' in host: