Helper/Nix: constructRunCommandLogPath: take RunCommandLog as input

This way we ensure that it actually exists in the database, rather than
blindly trusting user-generated input.
This commit is contained in:
Cole Helbling 2022-01-28 10:02:31 -08:00
parent 61914d56c6
commit 8eab7b8543
4 changed files with 8 additions and 6 deletions

View file

@ -537,7 +537,8 @@ sub runcommandlog :Local :Args(1) {
die if defined $tail && $tail !~ /^[0-9]+$/;
my $logFile = constructRunCommandLogPath($uuid);
my $runlog = $c->model('DB')->resultset('RunCommandLogs')->find({ uuid => $uuid });
my $logFile = constructRunCommandLogPath($runlog);
if (-f $logFile) {
serveLogFile($c, $logFile, $tail);
return;

View file

@ -591,12 +591,13 @@ sub isLocalStore {
sub constructRunCommandLogPath {
my ($filename) = @_;
my ($runlog) = @_;
my $uuid = $runlog->uuid;
my $hydra_path = Hydra::Model::DB::getHydraPath;
my $bucket = substr($filename, 0, 2);
my $bucket = substr($uuid, 0, 2);
return "$hydra_path/runcommand-logs/$bucket/$filename";
return "$hydra_path/runcommand-logs/$bucket/$uuid";
}
1;

View file

@ -163,7 +163,7 @@ sub buildFinished {
$runlog->started();
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog->uuid);
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog);
my $dir = dirname($logPath);
my $oldUmask = umask();

View file

@ -60,7 +60,7 @@ subtest "Validate a run log was created" => sub {
is($runlog->exit_code, 0, "This command should have succeeded.");
subtest "Validate the run log file exists" => sub {
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog->uuid);
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog);
ok(-f $logPath, "The run log was saved to a file.");
ok(-z $logPath, "The run log was empty.");
};