Rename apiKey() to credential() in FormRecognizer and TextAnalytics ClientBuilder#10738
Rename apiKey() to credential() in FormRecognizer and TextAnalytics ClientBuilder#10738samvaity merged 5 commits intoAzure:masterfrom
Conversation
| /** | ||
| * Test for null API key | ||
| */ | ||
| @Test |
There was a problem hiding this comment.
Why are the tests removed?
There was a problem hiding this comment.
Now that we have two overloads for the credential in the builder, it cannot resolve at compile time to pass in null object.
There was a problem hiding this comment.
assigning the null value to a type value, such as AzureKeyCredential credential = null, and replace null value with credential will resolve it. `=
There was a problem hiding this comment.
You can also do cast in API.
.credential((AzureKeyCredential) null)
| */ | ||
| public FormRecognizerClientBuilder apiKey(AzureKeyCredential apiKeyCredential) { | ||
| public FormRecognizerClientBuilder credential(AzureKeyCredential apiKeyCredential) { | ||
| this.credential = Objects.requireNonNull(apiKeyCredential, "'apiKeyCredential' cannot be null."); |
There was a problem hiding this comment.
Search is validating apiKeyCredential.getKey empty or null case.
There was a problem hiding this comment.
Moreover, if the credential is required, we can move the validation up to buildClient()
There was a problem hiding this comment.
There was a problem hiding this comment.
public SearchServiceClientBuilder credential(AzureKeyCredential keyCredential) {
if (keyCredential == null) {
throw logger.logExceptionAsError(new NullPointerException("'keyCredential' cannot be null."));
}
if (CoreUtils.isNullOrEmpty(keyCredential.getKey())) {
throw logger.logExceptionAsError(
new IllegalArgumentException("'keyCredential' cannot have a null or empty API key."));
}
this.keyCredential = keyCredential;
return this;
}
Here is how search do validation for your reference.
There was a problem hiding this comment.
@sima-zhu Could this
if (keyCredential == null) {
throw logger.logExceptionAsError(new NullPointerException("'keyCredential' cannot be null."));
}
be replaced with
this.credential = Objects.requireNonNull(keyCredential, "'keyCredential' cannot be null.");
And also for the rest of the code, I see that we are already doing the empty checks here and here. It would be redundant?
| @@ -54,7 +54,7 @@ public void invalidProtocol() { | |||
| public void nullApiKey() { | |||
There was a problem hiding this comment.
Method name should be renamed too.
| AzureKeyCredential credential = new AzureKeyCredential("{api_key}"); | ||
| TextAnalyticsClient client = new TextAnalyticsClientBuilder() | ||
| .apiKey(credential) | ||
| .credential(credential) |
There was a problem hiding this comment.
Update the name of the class to RotateAzureKeyCredential
| // BEGIN: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.instantiation | ||
| TextAnalyticsAsyncClient textAnalyticsAsyncClient = new TextAnalyticsClientBuilder() | ||
| .apiKey(new AzureKeyCredential("{api_key}")) | ||
| .credential(new AzureKeyCredential("{api_key}")) |
There was a problem hiding this comment.
Use azure_key_credential instead of api_key everywhere to be consistent with terminology.
There was a problem hiding this comment.
updated to say key as that is what it is called in Portal.
|
/azp run java - textanalytics - ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Fixes #10737