Skip to content

Commit

Permalink
Merge pull request #95 from snyk/dotkas/SUP-2696/increase-debugging-o…
Browse files Browse the repository at this point in the history
…utput

fix: [SUP-2696] adding extended logging information
  • Loading branch information
dotkas authored Feb 25, 2024
2 parents 7a0b943 + 909f070 commit cd51c65
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ executions {

download {
beforeDownload { Request request, RepoPath repoPath ->
snykPlugin.handleBeforeDownloadEvent(repoPath)
try {
snykPlugin.handleBeforeDownloadEvent(repoPath)
} catch (Exception e) {
log.error("An exception occurred during beforeDownload, re-throwing it for Artifactory to handle. Message was: ${e.message}")
throw e
}
}
}

storage {
afterPropertyCreate { ItemInfo itemInfo, String propertyName, String[] propertyValues ->
snykPlugin.handleAfterPropertyCreateEvent(security.currentUser(), itemInfo, propertyName, propertyValues)
try {
snykPlugin.handleAfterPropertyCreateEvent(security.currentUser(), itemInfo, propertyName, propertyValues)
} catch (Exception e) {
log.error("An exception occurred during afterPropertyCreate, re-throwing it for Artifactory to handle. Message was: ${e.message}")
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public void handleBeforeDownloadEvent(RepoPath repoPath) {
.map(m -> e.getMessage() + " " + m)
.orElseGet(e::getMessage);

String message = format("Artifact scan failed. %s %s", causeMessage, repoPath);
String message = format("Artifact scan failed due to an API error on Snyk's side. %s %s", causeMessage, repoPath);
LOG.debug(message);
if ("true".equals(blockOnApiFailure)) {
LOG.debug("Blocking download. Plugin Property \"{}\" is \"true\". {}", blockOnApiFailurePropertyKey, repoPath);
throw new CancelException(message, 500);
}
LOG.debug(message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,31 @@ protected void validateVulnerabilityIssues(TestResult testResult, RepoPath repoP
Severity vulnerabilityThreshold = Severity.of(configurationModule.getPropertyOrDefault(PluginConfiguration.SCANNER_VULNERABILITY_THRESHOLD));
if (vulnerabilityThreshold == Severity.LOW) {
if (!testResult.issues.vulnerabilities.isEmpty()) {
LOG.debug("Found vulnerabilities in {} returning 403", repoPath);
throw new CancelException(format("Artifact has vulnerabilities. %s", repoPath), 403);
}
} else if (vulnerabilityThreshold == Severity.MEDIUM) {
long count = testResult.issues.vulnerabilities.stream()
.filter(vulnerability -> vulnerability.severity == Severity.MEDIUM || vulnerability.severity == Severity.HIGH || vulnerability.severity == Severity.CRITICAL)
.count();
if (count > 0) {
LOG.debug("Found {} vulnerabilities in {} returning 403", count, repoPath);
throw new CancelException(format("Artifact has vulnerabilities with medium, high or critical severity. %s", repoPath), 403);
}
} else if (vulnerabilityThreshold == Severity.HIGH) {
long count = testResult.issues.vulnerabilities.stream()
.filter(vulnerability -> vulnerability.severity == Severity.HIGH || vulnerability.severity == Severity.CRITICAL)
.count();
if (count > 0) {
LOG.debug("Found {}, vulnerabilities in {} returning 403", count, repoPath);
throw new CancelException(format("Artifact has vulnerabilities with high or critical severity. %s", repoPath), 403);
}
} else if (vulnerabilityThreshold == Severity.CRITICAL) {
long count = testResult.issues.vulnerabilities.stream()
.filter(vulnerability -> vulnerability.severity == Severity.CRITICAL)
.count();
if (count > 0) {
LOG.debug("Found {} vulnerabilities in {} returning 403", count, repoPath);
throw new CancelException(format("Artifact has vulnerabilities with critical severity. %s", repoPath), 403);
}
}
Expand All @@ -171,20 +175,23 @@ protected void validateLicenseIssues(TestResult testResult, RepoPath repoPath) {
Severity licensesThreshold = Severity.of(configurationModule.getPropertyOrDefault(PluginConfiguration.SCANNER_LICENSE_THRESHOLD));
if (licensesThreshold == Severity.LOW) {
if (!testResult.issues.licenses.isEmpty()) {
LOG.debug("Found license issues in {} returning 403", repoPath);
throw new CancelException(format("Artifact has license issues. %s", repoPath), 403);
}
} else if (licensesThreshold == Severity.MEDIUM) {
long count = testResult.issues.licenses.stream()
.filter(vulnerability -> vulnerability.severity == Severity.MEDIUM || vulnerability.severity == Severity.HIGH)
.count();
if (count > 0) {
LOG.debug("Found {} license issues in {} returning 403", count, repoPath);
throw new CancelException(format("Artifact has license issues with medium or high severity. %s", repoPath), 403);
}
} else if (licensesThreshold == Severity.HIGH) {
long count = testResult.issues.licenses.stream()
.filter(vulnerability -> vulnerability.severity == Severity.HIGH)
.count();
if (count > 0) {
LOG.debug("Found {} license issues in {} returning 403", count, repoPath);
throw new CancelException(format("Artifact has license issues with high severity. %s", repoPath), 403);
}
}
Expand Down

0 comments on commit cd51c65

Please sign in to comment.