Skip to content

Commit 4707c2e

Browse files
fix: Small fixes
1 parent 4e687ca commit 4707c2e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Pilot/pilotTools.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def cancelTimer(self):
687687
self._timer.cancel()
688688

689689

690-
def sendMessage(url, pilotUUID, wnVO, method, rawMessage, withJWT=False):
690+
def sendMessage(url, pilotUUID, wnVO, method, rawMessage, withJWT=False, jwt={}):
691691
"""
692692
Invoke a remote method on a Tornado server and pass a JSON message to it.
693693
@@ -697,6 +697,7 @@ def sendMessage(url, pilotUUID, wnVO, method, rawMessage, withJWT=False):
697697
:param str method: a method to be invoked
698698
:param str rawMessage: a message to be sent, in JSON format
699699
:param bool withJWT: tells if we use or not JWT
700+
:param dict jwt: JWT for the requests
700701
:return: None.
701702
"""
702703

@@ -708,12 +709,15 @@ def sendMessage(url, pilotUUID, wnVO, method, rawMessage, withJWT=False):
708709
config = None
709710

710711
if withJWT:
711-
jwtData = os.getenv("JWT_TOKEN")
712+
try:
713+
access_token = jwt["access_token"]
714+
except ValueError as e:
715+
raise ValueError("JWT is needed, with an access_token field")
712716

713717
config = TokenBasedRequest(
714718
url=url,
715719
caPath=caPath,
716-
jwtData=jwtData
720+
jwtData=access_token
717721
)
718722

719723
else:
@@ -1141,10 +1145,10 @@ def __checkSecurityDir(self, envName, dirName):
11411145

11421146
def __retrieveIfNeededJWT(self):
11431147

1144-
if self.diracXServer != "":
1145-
if self.pilotSecret == "":
1148+
if self.diracXServer:
1149+
if not self.pilotSecret:
11461150
raise ValueError("PilotSecret has to be defined")
1147-
if self.pilotUUID == "":
1151+
if not self.pilotUUID:
11481152
raise ValueError("PilotUUID has to be defined")
11491153
self.jwt = retrieveJWT(self.diracXServer, self.pilotUUID, self.pilotSecret)
11501154
self.log.debug("Retrieved JWT from DiracX")

Pilot/proxyTools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def executeRequest(self, raw_data, insecure=False):
124124
:return: Parsed JSON response
125125
:rtype: dict
126126
"""
127-
if sys.version_info[0] == 3:
127+
if sys.version_info.major == 3:
128128
data = urlencode(raw_data).encode("utf-8") # encode to bytes ! for python3
129129
else:
130130
# Python2
@@ -141,15 +141,15 @@ def executeRequest(self, raw_data, insecure=False):
141141
ctx.check_hostname = False
142142
ctx.verify_mode = ssl.CERT_NONE
143143

144-
if sys.version_info[0] >= 3:
144+
if sys.version_info.major == 3:
145145
# Python 3 code
146146
with urlopen(request, context=ctx) as res:
147147
response_data = res.read().decode("utf-8") # Decode response bytes
148148
else:
149149
# Python 2 code
150150
res = urlopen(request, context=ctx)
151151
try:
152-
response_data = res.read().decode("utf-8") # Decode response bytes
152+
response_data = res.read()
153153
finally:
154154
res.close()
155155

0 commit comments

Comments
 (0)