Skip to content

Commit 818b431

Browse files
committed
Made a few corrections to secrets classes.
1 parent bf2a463 commit 818b431

File tree

7 files changed

+235
-227
lines changed

7 files changed

+235
-227
lines changed

sdk/keyvault/azure-security-keyvault-secrets-v2/src/main/java/com/azure/v2/security/keyvault/secrets/SecretClient.java

Lines changed: 198 additions & 189 deletions
Large diffs are not rendered by default.

sdk/keyvault/azure-security-keyvault-secrets-v2/src/main/java/com/azure/v2/security/keyvault/secrets/SecretClientBuilder.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
import io.clientcore.core.traits.HttpTrait;
2828
import io.clientcore.core.utils.configuration.Configuration;
2929

30-
import java.net.MalformedURLException;
3130
import java.net.URI;
3231
import java.net.URISyntaxException;
33-
import java.net.URL;
3432
import java.util.ArrayList;
3533
import java.util.List;
3634

@@ -52,9 +50,8 @@
5250
* <!-- src_embed com.v2.azure.security.keyvault.SecretClient.instantiation -->
5351
* <!-- end com.azure.v2.security.keyvault.SecretClient.instantiation -->
5452
*
55-
* <p>The {@link HttpInstrumentationOptions.HttpLogLevel log level},
56-
* {@link HttpInstrumentationOptions instrumentation policy} and custom {@link HttpClient HTTP client} can be optionally
57-
* configured in the {@link SecretClientBuilder}.</p>
53+
* <p>The {@link HttpInstrumentationOptions.HttpLogLevel log level}, multiple custom {@link HttpPipelinePolicy policies}
54+
* and custom {@link HttpClient HTTP client} can be optionally configured in the {@link SecretClientBuilder}.</p>
5855
*
5956
* <!-- src_embed com.azure.v2.security.keyvault.secrets.SecretClient.instantiation.withHttpClient -->
6057
* <!-- end com.azure.v2.security.keyvault.secrets.SecretClient.instantiation.withHttpClient -->
@@ -102,7 +99,7 @@ public SecretClientBuilder() {
10299
* <p>If {@link SecretClientBuilder#httpPipeline(HttpPipeline) pipeline} is set, then the {@code pipeline} and
103100
* {@link SecretClientBuilder#endpoint(String) endpoint} are used to create the
104101
* {@link SecretClientBuilder client}. All other builder settings are ignored. If {@code pipeline} is not set, then
105-
* the {@link SecretClientBuilder#credential(TokenCredential) credential}, and
102+
* a {@link SecretClientBuilder#credential(TokenCredential) credential} and
106103
* {@link SecretClientBuilder#endpoint(String) endpoint} are required to build the {@link SecretClient client}.</p>
107104
*
108105
* @return A {@link SecretClient} based on the options set in this builder.
@@ -114,19 +111,20 @@ public SecretClientBuilder() {
114111
* {@link #httpRetryPolicy(HttpRetryPolicy)} have been set.
115112
*/
116113
public SecretClient buildClient() {
117-
return new SecretClient(getClientImpl(), endpoint);
114+
return new SecretClient(buildImplClient(), endpoint);
118115
}
119116

120-
private SecretClientImpl getClientImpl() {
117+
private SecretClientImpl buildImplClient() {
121118
Configuration configuration = this.configuration == null
122119
? Configuration.getGlobalConfiguration()
123120
: this.configuration;
124121

125122
String endpoint = getEndpoint(configuration);
126123

127124
if (endpoint == null) {
128-
throw LOGGER.logThrowableAsError(
129-
new IllegalStateException("An Azure Key Vault of Managed HSM endpoint url is required."));
125+
throw LOGGER.logThrowableAsError(new IllegalStateException(
126+
"An Azure Key Vault endpoint is required. You can set one by using the KeyClientBuilder.endpoint()"
127+
+ "method or by setting the environment variable 'AZURE_KEYVAULT_ENDPOINT'."));
130128
}
131129

132130
SecretServiceVersion version = this.version == null ? SecretServiceVersion.getLatest() : this.version;
@@ -136,7 +134,8 @@ private SecretClientImpl getClientImpl() {
136134
}
137135

138136
if (credential == null) {
139-
throw LOGGER.logThrowableAsError(new IllegalStateException("Azure Key Vault credentials are required."));
137+
throw LOGGER.logThrowableAsError(new IllegalStateException(
138+
"A credential object is required. You can set one by using the KeyClientBuilder.credential() method."));
140139
}
141140

142141
// Closest to API goes first, closest to wire goes last.
@@ -194,8 +193,8 @@ private SecretClientImpl getClientImpl() {
194193
* other information via {@link KeyVaultSecretIdentifier#getEndpoint()}.
195194
* @return The updated {@link SecretClientBuilder} object.
196195
*
197-
* @throws IllegalArgumentException If {@code endpoint} isn't a valid URI.
198-
* @throws NullPointerException If {@code endpoint} is null.
196+
* @throws IllegalArgumentException If {@code endpoint} cannot be parsed into a valid URI.
197+
* @throws NullPointerException If {@code endpoint} is {@code null}.
199198
*/
200199
@Override
201200
public SecretClientBuilder endpoint(String endpoint) {
@@ -216,8 +215,8 @@ public SecretClientBuilder endpoint(String endpoint) {
216215

217216
/**
218217
* Sets the {@link TokenCredential} used to authorize requests sent to the service. Refer to the Azure SDK for Java
219-
* <a href="https://aka.ms/azsdk/java/docs/identity">identity and authentication</a>
220-
* documentation for more details on proper usage of the {@link TokenCredential} type.
218+
* <a href="https://aka.ms/azsdk/java/docs/identity">identity and authentication</a> documentation for more details
219+
* on proper usage of the {@link TokenCredential} type.
221220
*
222221
* @param credential {@link TokenCredential} used to authorize requests sent to the service.
223222
* @return The updated {@link SecretClientBuilder} object.
@@ -248,7 +247,7 @@ public SecretClientBuilder credential(TokenCredential credential) {
248247
* If OpenTelemetry is not found on the classpath, the same information is captured in logs.
249248
* HTTP request spans contain basic information about the request, such as the HTTP method, URL, status code and
250249
* duration.
251-
* See {@link io.clientcore.core.http.pipeline.HttpInstrumentationPolicy} for
250+
* See {@link HttpInstrumentationPolicy} for
252251
* the details.</li>
253252
* </ul>
254253
*
@@ -288,7 +287,7 @@ public SecretClientBuilder httpInstrumentationOptions(HttpInstrumentationOptions
288287
@Override
289288
public SecretClientBuilder addHttpPipelinePolicy(HttpPipelinePolicy pipelinePolicy) {
290289
if (pipelinePolicy == null) {
291-
throw LOGGER.logThrowableAsError(new NullPointerException("'policy' cannot be null."));
290+
throw LOGGER.logThrowableAsError(new NullPointerException("'pipelinePolicy' cannot be null."));
292291
}
293292

294293
policies.add(pipelinePolicy);
@@ -469,10 +468,10 @@ private String getEndpoint(Configuration configuration) {
469468
}
470469

471470
try {
472-
URL url = new URL(configEndpoint);
471+
URI uri = new URI(configEndpoint);
473472

474-
return url.toString();
475-
} catch (MalformedURLException ex) {
473+
return uri.toString();
474+
} catch (URISyntaxException ex) {
476475
return null;
477476
}
478477
}

sdk/keyvault/azure-security-keyvault-secrets-v2/src/main/java/com/azure/v2/security/keyvault/secrets/implementation/KeyVaultCredentialPolicy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ public static void clearCache() {
324324
* @return The host name and port of the Key Vault or Managed HSM endpoint.
325325
*/
326326
private static String getRequestAuthority(HttpRequest request) {
327-
URI url = request.getUri();
328-
String authority = url.getAuthority();
329-
int port = url.getPort();
327+
URI uri = request.getUri();
328+
String authority = uri.getAuthority();
329+
int port = uri.getPort();
330330

331331
// Append port for complete authority.
332332
if (!authority.contains(":") && port > 0) {

sdk/keyvault/azure-security-keyvault-secrets-v2/src/main/java/com/azure/v2/security/keyvault/secrets/implementation/SecretClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public Response<SecretBundle> updateSecretWithResponse(String secretName, String
560560
* </pre>
561561
*
562562
* @param secretName The name of the secret.
563-
* @param secretVersion The version of the secret. This URI fragment is optional. If not specified, the latest
563+
* @param secretVersion The version of the secret. This URL fragment is optional. If not specified, the latest
564564
* version of the secret is returned.
565565
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
566566
* @throws HttpResponseException thrown if the service returns an error.

sdk/keyvault/azure-security-keyvault-secrets-v2/src/main/java/com/azure/v2/security/keyvault/secrets/implementation/models/SecretsModelsUtils.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import io.clientcore.core.serialization.json.JsonReader;
1212

1313
import java.io.IOException;
14-
import java.net.MalformedURLException;
15-
import java.net.URL;
14+
import java.net.URI;
15+
import java.net.URISyntaxException;
1616
import java.time.Instant;
1717
import java.time.OffsetDateTime;
1818
import java.time.ZoneOffset;
@@ -200,8 +200,8 @@ public static void unpackId(String id, Consumer<String> nameConsumer, Consumer<S
200200
}
201201

202202
try {
203-
URL url = new URL(id);
204-
String[] tokens = url.getPath().split("/");
203+
URI uri = new URI(id);
204+
String[] tokens = uri.getPath().split("/");
205205

206206
if (tokens.length >= 3) {
207207
nameConsumer.accept(tokens[2]);
@@ -210,14 +210,15 @@ public static void unpackId(String id, Consumer<String> nameConsumer, Consumer<S
210210
if (tokens.length >= 4) {
211211
versionConsumer.accept(tokens[3]);
212212
}
213-
} catch (MalformedURLException e) {
213+
} catch (URISyntaxException e) {
214214
// Should never come here.
215-
LOGGER.atError().log("Received Malformed Secret Id URL from KV Service");
215+
LOGGER.atError().log("Received malformed secret id URL from Key Vault Service.");
216216
}
217217
}
218218

219219
public static OffsetDateTime epochToOffsetDateTime(JsonReader epochReader) throws IOException {
220220
Instant instant = Instant.ofEpochMilli(epochReader.getLong() * 1000L);
221+
221222
return OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
222223
}
223224

sdk/keyvault/azure-security-keyvault-secrets-v2/src/main/java/com/azure/v2/security/keyvault/secrets/models/KeyVaultSecretIdentifier.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.azure.v2.security.keyvault.secrets.SecretClient;
77
import io.clientcore.core.instrumentation.logging.ClientLogger;
88

9-
import java.net.MalformedURLException;
10-
import java.net.URL;
9+
import java.net.URI;
10+
import java.net.URISyntaxException;
1111

1212
/**
1313
* Information about a {@link KeyVaultSecret} parsed from the secret URL. You can use this information when calling
@@ -45,9 +45,9 @@ public KeyVaultSecretIdentifier(String sourceId) {
4545
}
4646

4747
try {
48-
final URL url = new URL(sourceId);
48+
final URI uri = new URI(sourceId);
4949
// We expect an sourceId with either 3 or 4 path segments: key vault + collection + name + "pending"/version
50-
final String[] pathSegments = url.getPath().split("/");
50+
final String[] pathSegments = uri.getPath().split("/");
5151

5252
// More or less segments in the URI than expected.
5353
if (pathSegments.length != 3 && pathSegments.length != 4) {
@@ -56,10 +56,10 @@ public KeyVaultSecretIdentifier(String sourceId) {
5656
}
5757

5858
this.sourceId = sourceId;
59-
this.endpoint = url.getProtocol() + "://" + url.getHost();
59+
this.endpoint = uri.getScheme() + "://" + uri.getHost();
6060
this.name = pathSegments[2];
6161
this.version = pathSegments.length == 4 ? pathSegments[3] : null;
62-
} catch (MalformedURLException e) {
62+
} catch (URISyntaxException e) {
6363
throw LOGGER.logThrowableAsError(
6464
new IllegalArgumentException("'sourceId' is not a valid Key Vault identifier.", e));
6565
}

sdk/keyvault/azure-security-keyvault-secrets-v2/src/main/java/module-info.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Code generated by Microsoft (R) TypeSpec Code Generator.
22

33
module com.azure.v2.security.keyvault.secrets {
4-
requires transitive io.clientcore.core;
5-
requires com.azure.v2.core;
4+
requires transitive com.azure.v2.core;
65

76
exports com.azure.v2.security.keyvault.secrets;
87
exports com.azure.v2.security.keyvault.secrets.models;

0 commit comments

Comments
 (0)