Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connectionString() method should throw IllegalArgurmentException #7121

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,30 @@ public ConfigurationClientBuilder endpoint(String endpoint) {
* @param connectionString Connection string in the format "endpoint={endpoint_value};id={id_value};
* secret={secret_value}"
* @return The updated ConfigurationClientBuilder object.
* @throws NullPointerException If {@code credential} is {@code null}.
* @throws NullPointerException If {@code connectionString} is {@code null}.
* @throws IllegalArgumentException if {@code connectionString} is an empty string, the {@code connectionString}
* secret is invalid, or the HMAC-SHA256 MAC algorithm cannot be instantiated.
*/
public ConfigurationClientBuilder connectionString(String connectionString) {
Objects.requireNonNull(connectionString);
Objects.requireNonNull(connectionString, "'connectionString' cannot be null.");

if (connectionString.isEmpty()) {
throw logger.logExceptionAsError(
new IllegalArgumentException("'connectionString' cannot be an empty string."));
}

try {
this.credential = new ConfigurationClientCredentials(connectionString);
} catch (InvalidKeyException err) {
throw logger.logExceptionAsError(new IllegalArgumentException(
"The secret is invalid and cannot instantiate the HMAC-SHA256 algorithm.", err));
"The secret contained within the connection string is invalid and cannot instantiate the HMAC-SHA256"
+ " algorithm.", err));
} catch (NoSuchAlgorithmException err) {
throw logger.logExceptionAsError(
new IllegalArgumentException("HMAC-SHA256 MAC algorithm cannot be instantiated.", err));
}

this.endpoint = credential.getBaseUri();

// Clear TokenCredential in favor of connection string credential
this.tokenCredential = null;
return this;
}

Expand All @@ -272,9 +277,6 @@ public ConfigurationClientBuilder credential(TokenCredential tokenCredential) {
// token credential can not be null value
Objects.requireNonNull(tokenCredential);
this.tokenCredential = tokenCredential;

// Clear connection string based credential in favor of TokenCredential
this.credential = null;
return this;
}

Expand Down