|
3 | 3 | import io.snyk.plugins.artifactory.configuration.ConfigurationModule; |
4 | 4 | import io.snyk.plugins.artifactory.configuration.PluginConfiguration; |
5 | 5 | import io.snyk.plugins.artifactory.configuration.properties.ArtifactProperties; |
| 6 | +import io.snyk.plugins.artifactory.configuration.properties.BlockReasonProperty; |
6 | 7 | import io.snyk.plugins.artifactory.configuration.properties.RepositoryArtifactProperties; |
7 | 8 | import io.snyk.plugins.artifactory.ecosystem.EcosystemResolver; |
8 | 9 | import io.snyk.plugins.artifactory.ecosystem.RepositoryMetadataEcosystemResolver; |
|
12 | 13 | import io.snyk.plugins.artifactory.model.ValidationSettings; |
13 | 14 | import org.artifactory.fs.FileLayoutInfo; |
14 | 15 | import org.artifactory.fs.ItemInfo; |
| 16 | +import org.artifactory.exception.CancelException; |
15 | 17 | import org.artifactory.repo.RepoPath; |
16 | 18 | import org.artifactory.repo.Repositories; |
17 | 19 | import org.artifactory.repo.RepositoryConfiguration; |
|
24 | 26 | import java.time.Instant; |
25 | 27 | import java.util.Optional; |
26 | 28 |
|
| 29 | +import static io.snyk.plugins.artifactory.configuration.properties.ArtifactProperty.BLOCK_REASON; |
27 | 30 | import static java.util.Objects.requireNonNull; |
28 | 31 |
|
29 | 32 | public class ScannerModule { |
@@ -64,7 +67,7 @@ public void filterAccess(@Nonnull RepoPath repoPath) { |
64 | 67 |
|
65 | 68 | resolveArtifact(repoPath) |
66 | 69 | .ifPresentOrElse( |
67 | | - this::filter, |
| 70 | + artifact -> filter(repoPath, artifact), |
68 | 71 | () -> LOG.info("No vulnerability info found for {}", repoPath) |
69 | 72 | ); |
70 | 73 | } |
@@ -92,10 +95,26 @@ private MonitoredArtifact runTestWith(PackageScanner scanner, RepoPath repoPath) |
92 | 95 | return toMonitoredArtifact(testResult, repoPath); |
93 | 96 | } |
94 | 97 |
|
95 | | - private void filter(MonitoredArtifact artifact) { |
| 98 | + private void filter(RepoPath repoPath, MonitoredArtifact artifact) { |
| 99 | + ArtifactProperties props = properties(repoPath); |
| 100 | + try { |
| 101 | + props.remove(BLOCK_REASON); |
| 102 | + } catch (Exception e) { |
| 103 | + LOG.debug("Could not clear block reason for {}: {}", repoPath, e.getMessage()); |
| 104 | + } |
| 105 | + |
96 | 106 | ValidationSettings validationSettings = ValidationSettings.from(configurationModule); |
97 | 107 | PackageValidator validator = new PackageValidator(validationSettings); |
98 | | - validator.validate(artifact); |
| 108 | + try { |
| 109 | + validator.validate(artifact); |
| 110 | + } catch (CancelException e) { |
| 111 | + try { |
| 112 | + props.set(BLOCK_REASON, BlockReasonProperty.truncateForStorage(e.getMessage())); |
| 113 | + } catch (Exception ex) { |
| 114 | + LOG.warn("Could not set {} for {}: {}", BLOCK_REASON.propertyKey(), repoPath, ex.getMessage()); |
| 115 | + } |
| 116 | + throw e; |
| 117 | + } |
99 | 118 | } |
100 | 119 |
|
101 | 120 | private @NotNull MonitoredArtifact toMonitoredArtifact(TestResult testResult, @NotNull RepoPath repoPath) { |
|
0 commit comments