Skip to content

Commit

Permalink
API Change / Migrate harvester Jeeves services to Spring MVC - fix Co…
Browse files Browse the repository at this point in the history
…deQL issue - retrieve log files using the history identifier not directly using the log file name as a request parameter
  • Loading branch information
josegar74 committed Jan 29, 2024
1 parent 67435d9 commit 822c611
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.fao.geonet.repository.specification.HarvestHistorySpecs;
import org.fao.geonet.services.harvesting.Util;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpEntity;
Expand All @@ -70,6 +71,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RequestMapping(value = {
"/{portal}/api/harvesters"
Expand Down Expand Up @@ -436,7 +438,7 @@ public ResponseEntity<HttpStatus> deleteHarvesterHistory(
summary = "Download a logfile from harvesting",
description = "")
@GetMapping(
value = "/log",
value = "/{harvesterHistoryIdentifier}/log",
produces = {
"text/plain"
})
Expand All @@ -448,21 +450,25 @@ public ResponseEntity<HttpStatus> deleteHarvesterHistory(
@ResponseBody
public void getLog(
@Parameter(
description = "Harvester log file name",
description = "Harvester identifier",
required = true
)
@RequestParam(name = "file")
String logFile,
HttpServletResponse response) throws IOException, ResourceNotFoundException {

// Security checks, this is no free proxy!!
if (logFile.startsWith("http") ||
logFile.startsWith("ftp") ||
logFile.startsWith("sftp") ||
logFile.contains("..") ||
!logFile.endsWith(".log") ||
!logFile.contains("harvester_")) {
throw new IllegalArgumentException(String.format("No valid harvester log file name: %s", logFile));
@PathVariable
Integer harvesterHistoryIdentifier,
HttpServletResponse response) throws IOException, JDOMException, ResourceNotFoundException {


Optional<HarvestHistory> harvestHistoryOptional = historyRepository.findById(harvesterHistoryIdentifier);
String logFile = "";

if (harvestHistoryOptional.isPresent()) {
Element info = harvestHistoryOptional.get().getInfoAsXml();
logFile = info.getChildText("logfile");
}

if (StringUtils.isEmpty(logFile)) {
throw new ResourceNotFoundException(
"Couldn't find or read the logfile in catalogue log directory for the harvester history entry. Check log file configuration.");
}

File mainLogFile = GeonetworkDataDirectory.getLogfile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ <h4 data-ng-show="h.deleted == 'false'" class="timeline-title">
<a
data-ng-show="h.info[0].logfile"
class="btn btn-default pull-right"
ng-href="../api/harvesters/log?file={{ (h.info[0].logfile | asArray)[0] | encodeURIComponent }}"
ng-href="../api/harvesters/{{h.id}}/log"
target="_blank"
>
<i class="fa fa-fw fa-download"></i>
Expand Down

0 comments on commit 822c611

Please sign in to comment.