@@ -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" )
0 commit comments