Skip to content

Commit 27b2616

Browse files
authored
Apply Traits to Attestation. (Azure#26949)
* Update Log4j to 2.17.0 * attestation. * search * changelog * don't include this.
1 parent 0b45b19 commit 27b2616

File tree

3 files changed

+224
-39
lines changed

3 files changed

+224
-39
lines changed

sdk/attestation/azure-security-attestation/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## 1.1.0-beta.1 (Unreleased)
44

55
### Features Added
6+
* Added interfaces from `com.azure.core.client.traits` to `AttestationClientBuilder`
7+
and `AttestationAdministrationClientBuilder`
68

79
### Breaking Changes
810

sdk/attestation/azure-security-attestation/src/main/java/com/azure/security/attestation/AttestationAdministrationClientBuilder.java

Lines changed: 110 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
package com.azure.security.attestation;
55

66
import com.azure.core.annotation.ServiceClientBuilder;
7+
import com.azure.core.client.traits.ConfigurationTrait;
8+
import com.azure.core.client.traits.EndpointTrait;
9+
import com.azure.core.client.traits.HttpTrait;
10+
import com.azure.core.client.traits.TokenCredentialTrait;
711
import com.azure.core.credential.TokenCredential;
812
import com.azure.core.http.HttpClient;
913
import com.azure.core.http.HttpHeader;
@@ -15,16 +19,20 @@
1519
import com.azure.core.http.policy.AddHeadersFromContextPolicy;
1620
import com.azure.core.http.policy.AddHeadersPolicy;
1721
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
22+
import com.azure.core.http.policy.HttpLogDetailLevel;
1823
import com.azure.core.http.policy.HttpLogOptions;
1924
import com.azure.core.http.policy.HttpLoggingPolicy;
2025
import com.azure.core.http.policy.HttpPipelinePolicy;
2126
import com.azure.core.http.policy.HttpPolicyProviders;
2227
import com.azure.core.http.policy.RequestIdPolicy;
28+
import com.azure.core.http.policy.RetryOptions;
2329
import com.azure.core.http.policy.RetryPolicy;
2430
import com.azure.core.http.policy.UserAgentPolicy;
2531
import com.azure.core.util.ClientOptions;
2632
import com.azure.core.util.Configuration;
2733
import com.azure.core.util.CoreUtils;
34+
import com.azure.core.util.HttpClientOptions;
35+
import com.azure.core.util.builder.ClientBuilderUtil;
2836
import com.azure.core.util.logging.ClientLogger;
2937
import com.azure.core.util.serializer.JacksonAdapter;
3038
import com.azure.security.attestation.implementation.AttestationClientImpl;
@@ -115,7 +123,11 @@
115123
AttestationAdministrationClient.class,
116124
AttestationAdministrationAsyncClient.class,
117125
})
118-
public final class AttestationAdministrationClientBuilder {
126+
public final class AttestationAdministrationClientBuilder implements
127+
ConfigurationTrait<AttestationAdministrationClientBuilder>,
128+
EndpointTrait<AttestationAdministrationClientBuilder>,
129+
HttpTrait<AttestationAdministrationClientBuilder>,
130+
TokenCredentialTrait<AttestationAdministrationClientBuilder> {
119131
private static final String SDK_NAME = "name";
120132
private static final String SDK_VERSION = "version";
121133
private static final RetryPolicy DEFAULT_RETRY_POLICY = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS);
@@ -134,6 +146,7 @@ public final class AttestationAdministrationClientBuilder {
134146
private HttpLogOptions httpLogOptions;
135147
private HttpPipeline pipeline;
136148
private HttpPipelinePolicy retryPolicy;
149+
private RetryOptions retryOptions;
137150
private Configuration configuration;
138151
private AttestationServiceVersion serviceVersion;
139152
private AttestationTokenValidationOptions tokenValidationOptions;
@@ -170,6 +183,8 @@ public AttestationAdministrationClientBuilder() {
170183
* </pre>
171184
* <!-- end com.azure.security.attestation.AttestationAdministrationClientBuilder.buildClient -->
172185
* @return an instance of {@link AttestationClient}.
186+
* @throws IllegalStateException If both {@link #retryOptions(RetryOptions)}
187+
* and {@link #retryPolicy(RetryPolicy)} have been set.
173188
*/
174189
public AttestationAdministrationClient buildClient() {
175190
return new AttestationAdministrationClient(buildAsyncClient());
@@ -189,6 +204,8 @@ public AttestationAdministrationClient buildClient() {
189204
* </pre>
190205
* <!-- end com.azure.security.attestation.AttestationAdministrationClientBuilder.buildAsyncClient -->
191206
* @return an instance of {@link AttestationClient}.
207+
* @throws IllegalStateException If both {@link #retryOptions(RetryOptions)}
208+
* and {@link #retryPolicy(RetryPolicy)} have been set.
192209
*/
193210
public AttestationAdministrationAsyncClient buildAsyncClient() {
194211
return new AttestationAdministrationAsyncClient(buildInnerClient(), this.tokenValidationOptions);
@@ -201,6 +218,7 @@ public AttestationAdministrationAsyncClient buildAsyncClient() {
201218
* @param endpoint The endpoint to connect to.
202219
* @return the AttestationClientBuilder.
203220
*/
221+
@Override
204222
public AttestationAdministrationClientBuilder endpoint(String endpoint) {
205223
Objects.requireNonNull(endpoint);
206224
try {
@@ -223,55 +241,87 @@ public AttestationAdministrationClientBuilder serviceVersion(AttestationServiceV
223241
return this;
224242
}
225243
/**
226-
* Sets the credential to be used for communicating with the service.
227-
* @param credential Specifies the credential to be used for authentication.
244+
* Sets the {@link TokenCredential} used to authorize requests sent to the service. Refer to the Azure SDK for Java
245+
* <a href="https://aka.ms/azsdk/java/docs/identity">identity and authentication</a>
246+
* documentation for more details on proper usage of the {@link TokenCredential} type.
247+
*
248+
* @param credential {@link TokenCredential} used to authorize requests sent to the service.
228249
* @return the AttestationClientBuilder.
229250
*/
251+
@Override
230252
public AttestationAdministrationClientBuilder credential(TokenCredential credential) {
231253
Objects.requireNonNull(credential);
232254
this.tokenCredential = credential;
233255
return this;
234256
}
235257

236258
/**
237-
* Sets The HTTP pipeline to send requests through.
259+
* Sets the {@link HttpPipeline} to use for the service client.
260+
*
261+
* <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
262+
* particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
263+
* they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
264+
* based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
265+
* trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
266+
* documentation of types that implement this trait to understand the full set of implications.</p>
238267
*
239-
* @param pipeline the pipeline value.
268+
* @param pipeline {@link HttpPipeline} to use for sending service requests and receiving responses.
240269
* @return the AttestationClientBuilder.
241270
*/
271+
@Override
242272
public AttestationAdministrationClientBuilder pipeline(HttpPipeline pipeline) {
243273
this.pipeline = pipeline;
244274
return this;
245275
}
246276

247277
/**
248-
* Sets The HTTP client used to send the request.
278+
* Sets the {@link HttpClient} to use for sending and receiving requests to and from the service.
279+
*
280+
* <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
281+
* particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
282+
* they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
283+
* based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
284+
* trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
285+
* documentation of types that implement this trait to understand the full set of implications.</p>
249286
*
250-
* @param httpClient the httpClient value.
287+
* @param httpClient The {@link HttpClient} to use for requests.
251288
* @return the AttestationClientBuilder.
252289
*/
290+
@Override
253291
public AttestationAdministrationClientBuilder httpClient(HttpClient httpClient) {
254292
this.httpClient = httpClient;
255293
return this;
256294
}
257295

258296
/**
259-
* Sets The configuration store that is used during construction of the service client.
297+
* Sets the client-specific configuration used to retrieve client or global configuration properties
298+
* when building a client.
260299
*
261-
* @param configuration the configuration value.
300+
* @param configuration Configuration store used to retrieve client configurations.
262301
* @return the AttestationClientBuilder.
263302
*/
303+
@Override
264304
public AttestationAdministrationClientBuilder configuration(Configuration configuration) {
265305
this.configuration = configuration;
266306
return this;
267307
}
268308

269309
/**
270-
* Sets The logging configuration for HTTP requests and responses.
310+
* Sets the {@link HttpLogOptions logging configuration} to use when sending and receiving requests to and from
311+
* the service. If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set.
271312
*
272-
* @param httpLogOptions the httpLogOptions value.
313+
* <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
314+
* particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
315+
* they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
316+
* based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
317+
* trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
318+
* documentation of types that implement this trait to understand the full set of implications.</p>
319+
*
320+
* @param httpLogOptions The {@link HttpLogOptions logging configuration} to use when sending and receiving requests
321+
* to and from the service.
273322
* @return the AttestationClientBuilder.
274323
*/
324+
@Override
275325
public AttestationAdministrationClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
276326
this.httpLogOptions = httpLogOptions;
277327
return this;
@@ -280,6 +330,9 @@ public AttestationAdministrationClientBuilder httpLogOptions(HttpLogOptions http
280330
/**
281331
* Sets The retry policy that will attempt to retry failed requests, if applicable.
282332
*
333+
* <p>
334+
* Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}.
335+
*
283336
* @param retryPolicy the retryPolicy value.
284337
* @return the AttestationClientBuilder.
285338
*/
@@ -289,27 +342,65 @@ public AttestationAdministrationClientBuilder retryPolicy(RetryPolicy retryPolic
289342
}
290343

291344
/**
292-
* Sets the {@link ClientOptions} which enables various options to be set on the client. For example setting an
293-
* {@code applicationId} using {@link ClientOptions#setApplicationId(String)} to configure
294-
* the {@link UserAgentPolicy} for telemetry/monitoring purposes.
345+
* Sets the {@link RetryOptions} for all the requests made through the client.
346+
*
347+
* <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
348+
* particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
349+
* they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
350+
* based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
351+
* trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
352+
* documentation of types that implement this trait to understand the full set of implications.</p>
353+
* <p>
354+
* Setting this is mutually exclusive with using {@link #retryPolicy(RetryPolicy)}.
295355
*
296-
* <p>More About <a href="https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy">Azure Core: Telemetry policy</a>
356+
* @param retryOptions The {@link RetryOptions} to use for all the requests made through the client.
357+
* @return the AttestationAdministrationClientBuilder.
358+
*/
359+
@Override
360+
public AttestationAdministrationClientBuilder retryOptions(RetryOptions retryOptions) {
361+
this.retryOptions = retryOptions;
362+
return this;
363+
}
364+
365+
/**
366+
* Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is
367+
* recommended that this method be called with an instance of the {@link HttpClientOptions}
368+
* class (a subclass of the {@link ClientOptions} base class). The HttpClientOptions subclass provides more
369+
* configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait
370+
* interface.
297371
*
298-
* @param clientOptions {@link ClientOptions}.
372+
* <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
373+
* particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
374+
* they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
375+
* based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
376+
* trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
377+
* documentation of types that implement this trait to understand the full set of implications.</p>
299378
*
379+
* @param clientOptions A configured instance of {@link HttpClientOptions}.
300380
* @return the updated {@link AttestationAdministrationClientBuilder} object
381+
* @see HttpClientOptions
301382
*/
383+
@Override
302384
public AttestationAdministrationClientBuilder clientOptions(ClientOptions clientOptions) {
303385
this.clientOptions = clientOptions;
304386
return this;
305387
}
306388

307389
/**
308-
* Adds a custom Http pipeline policy.
390+
* Adds a {@link HttpPipelinePolicy pipeline policy} to apply on each request sent.
391+
*
392+
* <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
393+
* particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
394+
* they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
395+
* based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
396+
* trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
397+
* documentation of types that implement this trait to understand the full set of implications.</p>
309398
*
310-
* @param policy The custom Http pipeline policy to add.
399+
* @param policy A {@link HttpPipelinePolicy pipeline policy}.
311400
* @return this {@link AttestationAdministrationClientBuilder}.
401+
* @throws NullPointerException If {@code pipelinePolicy} is {@code null}.
312402
*/
403+
@Override
313404
public AttestationAdministrationClientBuilder addPolicy(HttpPipelinePolicy policy) {
314405
Objects.requireNonNull(policy, "'policy' cannot be null.");
315406

@@ -389,7 +480,7 @@ private AttestationClientImpl buildInnerClient() {
389480
policies.addAll(perCallPolicies);
390481
HttpPolicyProviders.addBeforeRetryPolicies(policies);
391482

392-
policies.add(retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy);
483+
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, DEFAULT_RETRY_POLICY));
393484

394485
policies.add(new AddDatePolicy());
395486

0 commit comments

Comments
 (0)