@@ -687,7 +687,7 @@ def cancelTimer(self):
687
687
self ._timer .cancel ()
688
688
689
689
690
- def sendMessage (url , pilotUUID , wnVO , method , rawMessage , withJWT = False ):
690
+ def sendMessage (url , pilotUUID , wnVO , method , rawMessage , withJWT = False , jwt = {} ):
691
691
"""
692
692
Invoke a remote method on a Tornado server and pass a JSON message to it.
693
693
@@ -697,6 +697,7 @@ def sendMessage(url, pilotUUID, wnVO, method, rawMessage, withJWT=False):
697
697
:param str method: a method to be invoked
698
698
:param str rawMessage: a message to be sent, in JSON format
699
699
:param bool withJWT: tells if we use or not JWT
700
+ :param dict jwt: JWT for the requests
700
701
:return: None.
701
702
"""
702
703
@@ -708,12 +709,15 @@ def sendMessage(url, pilotUUID, wnVO, method, rawMessage, withJWT=False):
708
709
config = None
709
710
710
711
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" )
712
716
713
717
config = TokenBasedRequest (
714
718
url = url ,
715
719
caPath = caPath ,
716
- jwtData = jwtData
720
+ jwtData = access_token
717
721
)
718
722
719
723
else :
@@ -1141,10 +1145,10 @@ def __checkSecurityDir(self, envName, dirName):
1141
1145
1142
1146
def __retrieveIfNeededJWT (self ):
1143
1147
1144
- if self .diracXServer != "" :
1145
- if self .pilotSecret == "" :
1148
+ if self .diracXServer :
1149
+ if not self .pilotSecret :
1146
1150
raise ValueError ("PilotSecret has to be defined" )
1147
- if self .pilotUUID == "" :
1151
+ if not self .pilotUUID :
1148
1152
raise ValueError ("PilotUUID has to be defined" )
1149
1153
self .jwt = retrieveJWT (self .diracXServer , self .pilotUUID , self .pilotSecret )
1150
1154
self .log .debug ("Retrieved JWT from DiracX" )
0 commit comments