From a8772035b5f69526e51dd0de1c56b805d64128c9 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Fri, 24 Nov 2023 09:37:33 -0500 Subject: [PATCH] fix: add 429 errors to retry (#92) --- .../openvulnerability/client/nvd/NvdApiRetryStrategy.java | 2 +- .../openvulnerability/client/nvd/NvdCveClient.java | 4 ++-- .../openvulnerability/client/nvd/NvdCveClientBuilder.java | 6 +++--- .../jeremylong/vulnz/cli/commands/AbstractNvdCommand.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdApiRetryStrategy.java b/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdApiRetryStrategy.java index 80cd96fc..409c6db3 100644 --- a/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdApiRetryStrategy.java +++ b/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdApiRetryStrategy.java @@ -42,7 +42,7 @@ public class NvdApiRetryStrategy extends DefaultHttpRequestRetryStrategy { public NvdApiRetryStrategy(int maxRetries, long delay) { super(maxRetries, TimeValue.of(delay, TimeUnit.MILLISECONDS), new ArrayList>(), - Arrays.asList(503)); + Arrays.asList(429, 503)); this.maxRetries = maxRetries; this.delay = delay; } diff --git a/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClient.java b/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClient.java index b8b2a7f5..9616974f 100644 --- a/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClient.java +++ b/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClient.java @@ -143,7 +143,7 @@ public class NvdCveClient implements PagedDataSource { * @param endpoint the endpoint for the NVD CVE API; if null the default endpoint is used * @param threadCount the number of threads to use when calling the NVD API. * @param maxPageCount the maximum number of pages to retrieve from the NVD API. - * @param maxRetryCount the maximum number of retries for 503 status code responses. + * @param maxRetryCount the maximum number of retries for 503 and 429 status code responses. */ NvdCveClient(String apiKey, String endpoint, int threadCount, int maxPageCount, int maxRetryCount) { this(apiKey, endpoint, apiKey == null ? 6500 : 600, threadCount, maxPageCount, maxRetryCount); @@ -157,7 +157,7 @@ public class NvdCveClient implements PagedDataSource { * @param delay the delay in milliseconds between API calls on a single thread. * @param threadCount the number of threads to use when calling the NVD API. * @param maxPageCount the maximum number of pages to retrieve from the NVD API. - * @param maxRetryCount the maximum number of retries for 503 status code responses. + * @param maxRetryCount the maximum number of retries for 503 and 429 status code responses. */ NvdCveClient(String apiKey, String endpoint, long delay, int threadCount, int maxPageCount, int maxRetryCount) { this.apiKey = apiKey; diff --git a/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClientBuilder.java b/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClientBuilder.java index 6e2fc284..91732003 100644 --- a/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClientBuilder.java +++ b/open-vulnerability-clients/src/main/java/io/github/jeremylong/openvulnerability/client/nvd/NvdCveClientBuilder.java @@ -65,7 +65,7 @@ public final class NvdCveClientBuilder { */ private long delay; /** - * The maximum number of retries for 503 responses from the NVD. + * The maximum number of retries for 503 and 429 responses from the NVD. */ private int maxRetryCount = 10; /** @@ -127,9 +127,9 @@ public NvdCveClientBuilder withDelay(long milliseconds) { } /** - * Set the maximum number of retries for 503 responses from the NVD; default is 10. + * Set the maximum number of retries for 503 and 429 responses from the NVD; default is 10. * - * @param maxRetryCount the maximum number of retries for 503 responses from the NVD. + * @param maxRetryCount the maximum number of retries for 503 and 429 responses from the NVD. * @return the builder */ public NvdCveClientBuilder withMaxRetryCount(int maxRetryCount) { diff --git a/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/AbstractNvdCommand.java b/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/AbstractNvdCommand.java index 9740f17b..5a007f23 100644 --- a/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/AbstractNvdCommand.java +++ b/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/AbstractNvdCommand.java @@ -29,7 +29,7 @@ public abstract class AbstractNvdCommand extends AbstractJsonCommand { "--delay"}, description = "The delay in milliseconds between API calls to the NVD - important if pulling a larger data set without an API Key") private int delay; @CommandLine.Option(names = { - "--maxRetry"}, description = "The maximum number of retry attempts on 503 errors from the NVD API") + "--maxRetry"}, description = "The maximum number of retry attempts on 503 and 429 errors from the NVD API") private int maxRetry; @CommandLine.Option(names = { "--pageCount"}, description = "The number of `pages` of data to retrieve from the NVD if more then a single page is returned")