Skip to content

Commit

Permalink
fix: using extraCredentials:hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Nov 2, 2023
1 parent f757003 commit db7a973
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Pilot/pilotTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit db7a973

Please sign in to comment.