Class NvdCveClientBuilder
java.lang.Object
io.github.jeremylong.openvulnerability.client.nvd.NvdCveClientBuilder
- All Implemented Interfaces:
Cloneable
Used to build an NVD CVE API client. As the NvdCveClient client is autocloseable the builder should be used in a try
with resources:
try (NvdCveClient api = NvdCveClientBuilder.aNvdCveApi().build()) {
while (api.hasNext()) {
Collection<DefCveItem> items = api.next();
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumFilters for the NVD CVE API that are used without parameters.static enumThe CVSS V2 Severity.static enumThe CVSS V3 Severity.static enumParameters to the NVD CVE API used to filter the results.static enumVersion boundary type for filtering. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe NVD CVE API key.private PathThe directory to cache the NVD CVE API responses.private longThe minimum delay between API calls in milliseconds.private StringThe endpoint for the NVD CVE API.private final List<org.apache.hc.core5.http.NameValuePair>A list of filters to apply to the request.private HttpAsyncClientSupplierprivate static final org.slf4j.LoggerReference to the logger.private intThe maximum number of pages to retrieve from the NVD API.private intThe maximum number of retries for 503 and 429 responses from the NVD.private intThe number of requests to make per a rolling 30-seconds.private intThe number of results per page.private StringThe user agent to append to the default open-vulnerability-client's user-agent string -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NvdCveClientBuilderBegin building the NVD CVE API Object.build()Build the NVD CVE API client.clone()Clone the builder.withAdditionalUserAgent(String userAgent) Use an additional identifier as part of the User-Agent when making requests.withApiKey(String apiKey) Use an NVD CVE API key.withCacheDirectory(Path cacheDirectory) Sets the directory to cache the NVD CVE API responses.Filter the results for a specific CVSS V2 Severity.Filter the results for a specific CVSS V3 Severity.withDelay(long milliseconds) Use a minimum delay in milliseconds between API calls; useful if you run into issues with rate limiting.withEndpoint(String endpoint) Use an alternative endpoint for the NVD CVE API.Add a querystring parameter to filter the call to the NVD CVE API.withFilter(NvdCveClientBuilder.Filter filter, String value) Add a querystring parameter to filter the call to the NVD CVE API.withFilter(String filter, String value) Add a querystring parameter to filter the call to the NVD CVE API.withHttpClientSupplier(HttpAsyncClientSupplier httpClientSupplier) Provide a supplier for custom HTTP clients.withLastModifiedFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate) Use a range of no more than 120 days on the last modified dates to filter the results.withMaxPageCount(int count) Set the maximum number of pages to retrieve from the NVD API.withMaxRetryCount(int maxRetryCount) Set the maximum number of retries for 503 and 429 responses from the NVD; default is 10.withPublishedDateFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate) Filter the results with a range of published date times.withrequestsPerThirtySeconds(int requestsPerThirtySeconds) Deprecated.withRequestsPerThirtySeconds(int requestsPerThirtySeconds) Set the number of requests to make in a rolling 30-seconds.withResultsPerPage(int resultsPerPage) Use a specific number of results per page.withVersionEnd(String versionEnd) The virtualMatchString parameter may be combined with versionEnd and versionEndType to return only the CVEs associated with CPEs in specific version ranges.withVersionEnd(String versionEnd, NvdCveClientBuilder.VersionType endType) The virtualMatchString parameter may be combined with versionEnd and versionEndType to return only the CVEs associated with CPEs in specific version ranges.withVersionStart(String versionStart) The virtualMatchString parameter may be combined with versionStart and versionStartType to return only the CVEs associated with CPEs in specific version ranges.withVersionStart(String versionStart, NvdCveClientBuilder.VersionType startType) The virtualMatchString parameter may be combined with versionStart and versionStartType to return only the CVEs associated with CPEs in specific version ranges.withVirtualMatchString(String virtualMatchString) This parameter filters CVE more broadly than cpeName.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOGReference to the logger. -
filters
A list of filters to apply to the request. -
apiKey
The NVD CVE API key. -
endpoint
The endpoint for the NVD CVE API. -
resultsPerPage
private int resultsPerPageThe number of results per page. -
delay
private long delayThe minimum delay between API calls in milliseconds. -
maxRetryCount
private int maxRetryCountThe maximum number of retries for 503 and 429 responses from the NVD. -
requestsPerThirtySeconds
private int requestsPerThirtySecondsThe number of requests to make per a rolling 30-seconds. -
maxPageCount
private int maxPageCountThe maximum number of pages to retrieve from the NVD API. -
cacheDirectory
The directory to cache the NVD CVE API responses. -
httpClientSupplier
-
userAgent
The user agent to append to the default open-vulnerability-client's user-agent string
-
-
Constructor Details
-
NvdCveClientBuilder
private NvdCveClientBuilder()Private constructor for a builder.
-
-
Method Details
-
aNvdCveApi
Begin building the NVD CVE API Object.- Returns:
- the builder
-
withApiKey
Use an NVD CVE API key.- Parameters:
apiKey- the NVD CVE API key.- Returns:
- the builder
- See Also:
-
withEndpoint
Use an alternative endpoint for the NVD CVE API.- Parameters:
endpoint- the endpoint for the NVD CVE API- Returns:
- the builder
-
withCacheDirectory
Sets the directory to cache the NVD CVE API responses. This should only be used if downloading the entire set of CVE data from the NVD API. If the cache directory is used and there is an interruption in the download - under rare cases if the NVD updated the CVE data - the cache directory will not be updated and as such, the mirror may be out of sync. If using the cache directory and an interruption occurs, it is recommended to try again within 20 hours and if succesful, perform another update to retrieve the entries modified within the last 20 hours.- Parameters:
cacheDirectory- the directory to cache the NVD CVE API responses- Returns:
- the builder
-
withDelay
Use a minimum delay in milliseconds between API calls; useful if you run into issues with rate limiting.- Parameters:
milliseconds- the minimum number of milliseconds between API calls to the NVD CVE API- Returns:
- the builder
-
withMaxRetryCount
Set the maximum number of retries for 503 and 429 responses from the NVD; default is 10.- Parameters:
maxRetryCount- the maximum number of retries for 503 and 429 responses from the NVD.- Returns:
- the builder
-
withrequestsPerThirtySeconds
Deprecated.usewithRequestsPerThirtySeconds(int)insteadSet the number of requests to make in a rolling 30-seconds.- Parameters:
requestsPerThirtySeconds- the number of requests to make in a rolling 30-seconds.- Returns:
- the builder
-
withRequestsPerThirtySeconds
Set the number of requests to make in a rolling 30-seconds.- Parameters:
requestsPerThirtySeconds- the number of requests to make in a rolling 30-seconds.- Returns:
- the builder
-
withMaxPageCount
Set the maximum number of pages to retrieve from the NVD API.- Parameters:
count- the maximum number of pages to retrieve from the NVD API- Returns:
- the builder
-
withResultsPerPage
Use a specific number of results per page. Value must be between 1 and 2000. The default value is 2000.- Parameters:
resultsPerPage- the number of results per page- Returns:
- the builder
-
withFilter
Add a querystring parameter to filter the call to the NVD CVE API.- Parameters:
filter- the querystring parametervalue- the querystring parameter value- Returns:
- the builder
-
withFilter
Add a querystring parameter to filter the call to the NVD CVE API.- Parameters:
filter- the querystring parametervalue- the querystring parameter value- Returns:
- the builder
-
withFilter
Add a querystring parameter to filter the call to the NVD CVE API.- Parameters:
filter- the querystring parameter- Returns:
- the builder
-
withLastModifiedFilter
public NvdCveClientBuilder withLastModifiedFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate) Use a range of no more than 120 days on the last modified dates to filter the results. The ZonedDateTime objects must be set to UTC.- Parameters:
utcStartDate- the UTC date time for the range startutcEndDate- the UTC date time for the range end- Returns:
- the builder
-
withAdditionalUserAgent
Use an additional identifier as part of the User-Agent when making requests.- Parameters:
userAgent- the user agent string to append- Returns:
- the builder
-
withPublishedDateFilter
public NvdCveClientBuilder withPublishedDateFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate) Filter the results with a range of published date times. The ZonedDateTime objects must be set to UTC.- Parameters:
utcStartDate- the UTC date time for the range startutcEndDate- the UTC date time for the range end- Returns:
- the builder
-
withCvssV2SeverityFilter
Filter the results for a specific CVSS V2 Severity.- Parameters:
severity- the severity- Returns:
- the builder
-
withCvssV3SeverityFilter
Filter the results for a specific CVSS V3 Severity.- Parameters:
severity- the severity- Returns:
- the builder
-
withVirtualMatchString
This parameter filters CVE more broadly than cpeName. The exact value of {cpe match string} is compared against the CPE Match Criteria present on CVE applicability statements.- Parameters:
virtualMatchString- virtual matching CPE- Returns:
- the builder
- See Also:
-
withVersionStart
The virtualMatchString parameter may be combined with versionStart and versionStartType to return only the CVEs associated with CPEs in specific version ranges.- Parameters:
versionStart- the version start- Returns:
- the builder
- See Also:
-
withVersionStart
public NvdCveClientBuilder withVersionStart(String versionStart, NvdCveClientBuilder.VersionType startType) The virtualMatchString parameter may be combined with versionStart and versionStartType to return only the CVEs associated with CPEs in specific version ranges.- Parameters:
versionStart- the version startstartType- including or excluding- Returns:
- the builder
- See Also:
-
withVersionEnd
The virtualMatchString parameter may be combined with versionEnd and versionEndType to return only the CVEs associated with CPEs in specific version ranges.- Parameters:
versionEnd- the version end- Returns:
- the builder
- See Also:
-
withVersionEnd
public NvdCveClientBuilder withVersionEnd(String versionEnd, NvdCveClientBuilder.VersionType endType) The virtualMatchString parameter may be combined with versionEnd and versionEndType to return only the CVEs associated with CPEs in specific version ranges.- Parameters:
versionEnd- the version endendType- including or excluding- Returns:
- the builder
- See Also:
-
withHttpClientSupplier
Provide a supplier for custom HTTP clients.Note that
withDelay(long)andwithMaxRetryCount(int)have no effect when a customHttpAsyncClientSupplieris provided. Instead, clients created by the supplier should be configured to useNvdApiRetryStrategywith the desired delay and retry count values.- Parameters:
httpClientSupplier- supplier for custom HTTP clients; ifnulla default client will be used- Returns:
- the builder
-
build
Build the NVD CVE API client.- Returns:
- the NVD CVE API client
-
clone
Clone the builder.
-
withRequestsPerThirtySeconds(int)instead