55
66import java .util .Optional ;
77
8+ import static io .snyk .plugins .artifactory .configuration .PluginConfiguration .SCANNER_LAST_MODIFIED_DELAY_DAYS ;
89import static io .snyk .plugins .artifactory .configuration .PluginConfiguration .SCANNER_LICENSE_THRESHOLD ;
910import static io .snyk .plugins .artifactory .configuration .PluginConfiguration .SCANNER_VULNERABILITY_THRESHOLD ;
1011
1112public class ValidationSettings {
1213
1314 private final Optional <Severity > vulnSeverityThreshold ;
14-
1515 private final Optional <Severity > licenseSeverityThreshold ;
16+ private final Optional <Integer > lastModifiedDelayDays ;
1617
1718 public ValidationSettings () {
18- this (Optional .of (Severity .HIGH ), Optional .of (Severity .HIGH ));
19+ this (Optional .of (Severity .HIGH ), Optional .of (Severity .HIGH ), Optional . of ( 0 ) );
1920 }
2021
21- private ValidationSettings (Optional <Severity > vulnSeverityThreshold , Optional <Severity > licenseSeverityThreshold ) {
22+ private ValidationSettings (Optional <Severity > vulnSeverityThreshold , Optional <Severity > licenseSeverityThreshold , Optional < Integer > lastModifiedDelayDays ) {
2223 this .vulnSeverityThreshold = vulnSeverityThreshold ;
2324 this .licenseSeverityThreshold = licenseSeverityThreshold ;
25+ this .lastModifiedDelayDays = lastModifiedDelayDays ;
2426 }
2527
2628 public ValidationSettings withVulnSeverityThreshold (Optional <Severity > threshold ) {
27- return new ValidationSettings (threshold , licenseSeverityThreshold );
29+ return new ValidationSettings (threshold , licenseSeverityThreshold , lastModifiedDelayDays );
2830 }
2931
3032 public ValidationSettings withLicenseSeverityThreshold (Optional <Severity > threshold ) {
31- return new ValidationSettings (vulnSeverityThreshold , threshold );
33+ return new ValidationSettings (vulnSeverityThreshold , threshold , lastModifiedDelayDays );
34+ }
35+
36+ public ValidationSettings withLastModifiedDelayDays (Optional <Integer > days ) {
37+ return new ValidationSettings (vulnSeverityThreshold , licenseSeverityThreshold , days );
3238 }
3339
3440 public Optional <Severity > getVulnSeverityThreshold () {
@@ -39,18 +45,37 @@ public Optional<Severity> getLicenseSeverityThreshold() {
3945 return licenseSeverityThreshold ;
4046 }
4147
48+ public Optional <Integer > getLastModifiedDelayDays () {
49+ return lastModifiedDelayDays ;
50+ }
51+
4252 public static ValidationSettings from (ConfigurationModule config ) {
4353 return from (
4454 config .getPropertyOrDefault (SCANNER_VULNERABILITY_THRESHOLD ),
45- config .getPropertyOrDefault (SCANNER_LICENSE_THRESHOLD )
55+ config .getPropertyOrDefault (SCANNER_LICENSE_THRESHOLD ),
56+ config .getPropertyOrDefault (SCANNER_LAST_MODIFIED_DELAY_DAYS )
4657 );
4758 }
4859
4960 public static ValidationSettings from (String vulnThreshold , String licenseThreshold ) {
61+ return from (vulnThreshold , licenseThreshold , "0" );
62+ }
63+
64+ public static ValidationSettings from (String vulnThreshold , String licenseThreshold , String lastModifiedDelayDaysStr ) {
5065 return new ValidationSettings (
5166 parseSeverity (vulnThreshold ),
52- parseSeverity (licenseThreshold )
67+ parseSeverity (licenseThreshold ),
68+ parseLastModifiedDelayDays (lastModifiedDelayDaysStr )
5369 );
70+ }
71+
72+ private static Optional <Integer > parseLastModifiedDelayDays (String lastModifiedDelayDaysStr ) {
73+ try {
74+ Integer lastModifiedDelayDays = Integer .parseInt (lastModifiedDelayDaysStr );
75+ return Optional .of (lastModifiedDelayDays );
76+ } catch (NumberFormatException e ) {
77+ throw new IllegalArgumentException ("Invalid value for last modified delay days: " + lastModifiedDelayDaysStr );
78+ }
5479 }
5580
5681 private static Optional <Severity > parseSeverity (String severityStr ) {
0 commit comments