Package ai.nightfall.scan
Class NightfallClient.Builder
java.lang.Object
ai.nightfall.scan.NightfallClient.Builder
- Enclosing class:
- NightfallClient
A builder class that configures, validates, then creates instances of a Nightfall Client.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the client using the configured values, falling back on defaults if any values were not explicitly set.static NightfallClientBuilds and returns the client with all default values.withAPIKey(String apiKey) Sets the API key for the Nightfall Client.withConnectionTimeout(Duration connectionTimeout) Sets the connection timeout for the underlying HTTP client.withFileUploadConcurrency(int concurrency) Sets the concurrency for file upload operations.withKeepAliveDuration(Duration keepAliveDuration) Sets the keep-alive duration for a connection in the underlying HTTP connection pool.withMaxIdleConnections(int maxIdleConnections) Sets the maximum number of idle connections in the underlying HTTP client.withReadTimeout(Duration readTimeout) Sets the read timeout for the underlying HTTP client.withWriteTimeout(Duration writeTimeout) Sets the write timeout for the underlying HTTP client.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
defaultClient
Builds and returns the client with all default values. The API key is loaded from the environment variableNIGHTFALL_API_KEY. The underlying client manages an HTTP connection pool, so instantiating more than one Nightfall client is not necessary.- Returns:
- a Nightfall client
- Throws:
IllegalArgumentException- if no value is set for the API key
-
withAPIKey
Sets the API key for the Nightfall Client.- Parameters:
apiKey- a valid Nightfall API key- Returns:
- the builder
-
withFileUploadConcurrency
Sets the concurrency for file upload operations. This field represents the number of HTTP requests that may execute in parallel when uploading file bytes. Be cognizant of your HTTP connection pool settings when deciding on a value in order to optimize your upload bandwidth. Valid values are in the range [1, 100], inclusive. Defaults to 1 if unset.- Parameters:
concurrency- an integer in the range [1, 100]- Returns:
- the builder
- Throws:
IllegalArgumentException- if the argument falls outside the allowed range
-
withConnectionTimeout
Sets the connection timeout for the underlying HTTP client. If unset, defaults to 10 seconds. If set to 0, connections will not time out.- Parameters:
connectionTimeout- a non-negative duration less than or equal to 60 seconds- Returns:
- the builder
- Throws:
IllegalArgumentException- if the argument falls outside the allowed range
-
withReadTimeout
Sets the read timeout for the underlying HTTP client. If unset, defaults to 30 seconds. If set to 0, reads will not time out.- Parameters:
readTimeout- a non-negative duration less than or equal to 120 seconds- Returns:
- the builder
- Throws:
IllegalArgumentException- if the argument falls outside the allowed range
-
withWriteTimeout
Sets the write timeout for the underlying HTTP client. If unset, defaults to 60 seconds. If set to 0, writes will not time out.- Parameters:
writeTimeout- a non-negative duration less than or equal to 120 seconds- Returns:
- the builder
- Throws:
IllegalArgumentException- if the argument falls outside the allowed range
-
withMaxIdleConnections
Sets the maximum number of idle connections in the underlying HTTP client. Be sure this value cooperates with the configuration forfileUploadConcurrency. If unset, defaults to 100.- Parameters:
maxIdleConnections- an integer in the range [1, 500]- Returns:
- the builder
- Throws:
IllegalArgumentException- if the argument falls outside the allowed range
-
withKeepAliveDuration
Sets the keep-alive duration for a connection in the underlying HTTP connection pool. If unset, defaults to 30 seconds.- Parameters:
keepAliveDuration- a positive duration less than or equal to 120 seconds- Returns:
- the builder
- Throws:
IllegalArgumentException- if the argument falls outside the allowed range
-
build
Builds the client using the configured values, falling back on defaults if any values were not explicitly set.- Returns:
- a Nightfall client
- Throws:
IllegalArgumentException- if the API key was not set
-