From db7a973131f4bb08b510621e4a37f52223d651e0 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Thu, 2 Nov 2023 13:51:49 +0100 Subject: [PATCH] fix: using extraCredentials:hosts --- Pilot/pilotTools.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Pilot/pilotTools.py b/Pilot/pilotTools.py index 9cd90adc..470a1f77 100644 --- a/Pilot/pilotTools.py +++ b/Pilot/pilotTools.py @@ -610,24 +610,29 @@ def sendMessage(url, pilotUUID, method, rawMessage): :param str rawMessage: a message to be sent, in JSON format :return: None. """ - message = json.dumps((json.dumps(rawMessage), pilotUUID)) - major, minor, micro, _, _ = sys.version_info - if major >= 3: - data = urlencode({"method": method, "args": message}).encode("utf-8") # encode to bytes ! for python3 - else: - data = urlencode({"method": method, "args": message}) caPath = os.getenv("X509_CERT_DIR") cert = os.getenv("X509_USER_PROXY") context = ssl.create_default_context() context.load_verify_locations(capath=caPath) + + message = json.dumps((json.dumps(rawMessage), pilotUUID)) + try: - context.load_cert_chain(cert) - except IsADirectoryError: + context.load_cert_chain(cert) # this is a proxy + raw_data = {"method": method, "args": message} + except IsADirectoryError: # assuming it'a dir containing cert and key context.load_cert_chain( os.path.join(cert, "hostcert.pem"), os.path.join(cert, "hostkey.pem") ) + raw_data = {"method": method, "args": message, "extraCredentials": '"hosts"'} + + if sys.version_info[0] == 3: + data = urlencode(raw_data).encode("utf-8") # encode to bytes ! for python3 + else: + data = urlencode(raw_data) + res = urlopen(url, data, context=context) res.close()