Skip to content

Commit

Permalink
Merge pull request #1085 from MetPX/daniel_made_me_do_it
Browse files Browse the repository at this point in the history
more robust validation of return value from destfnscript
  • Loading branch information
petersilva authored Jun 6, 2024
2 parents 01e9904 + 7efabbf commit f983ae5
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions sarracenia/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,16 @@ def sundew_getDestInfos(self, msg, currentFileOption, filename):
for dfm in self.plugins['destfn']:
classname = dfm.__qualname__.split('.')[0]
if (scriptclass == classname) or (scriptclass.capitalize() == classname):
destFileName = dfm(msg)
try:
destFileName = dfm(msg)
except Exception as ex:
logger.error( f'DESTFNSCRIPT plugin {dfm} crashed: {ex}' )
logger.debug( "details:", exc_info=True )

if destFileName == None or type(destFileName) != str:
logger.error( f"DESTFNSCRIPT {dfm} return value must be the new file name as a string. This one returned {destFileName}, ignoring")
return None

elif spec == 'TIME':
timeSuffix = ':' + time.strftime("%Y%m%d%H%M%S", time.gmtime())
if 'pubTime' in msg:
Expand All @@ -756,9 +765,8 @@ def sundew_getDestInfos(self, msg, currentFileOption, filename):
timeSuffix = ':' + parts[-1]

else:
logger.error("Don't understand this DESTFN parameter: %s" %
spec)
return filename
logger.error( f"invalid DESTFN parameter: {spec}" )
return None
return destFileName + satnet + timeSuffix


Expand Down Expand Up @@ -1642,6 +1650,14 @@ def do_download(self) -> None:
self.worklist.ok.append(msg)
continue

if not 'new_dir' in msg or not msg['new_dir']:
self.reject(msg, 422, f"new_dir message field missing, do not know which directory to put file in. skipping." )
continue

if not 'new_file' in msg or not msg['new_file']:
self.reject(msg, 422, f"new_file message field missing, do not know name of file to write. skipping." )
continue

new_path = msg['new_dir'] + os.path.sep + msg['new_file']
new_file = msg['new_file']

Expand Down Expand Up @@ -2735,6 +2751,14 @@ def do_send(self):

for msg in self.worklist.incoming:

if not 'new_dir' in msg or not msg['new_dir']:
self.reject(msg, 422, f"new_dir message field missing, do not know which directory to put file in. skipping." )
continue

if not 'new_file' in msg or not msg['new_file']:
self.reject(msg, 422, f"new_file message field missing, do not know name of file to write. skipping." )
continue

# weed out non-file transfer operations that are configured to not be done.
if 'fileOp' in msg:
if ('directory' in msg['fileOp']) and ('remove' in msg['fileOp']) and ( 'rmdir' not in self.o.fileEvents ):
Expand Down

0 comments on commit f983ae5

Please sign in to comment.