Skip to content

Commit fdb0e62

Browse files
Updated swagger to split implementation and client (Azure#22989)
* Updated swagger * Checkpoint * Fixed a bunch of autorest options * Fixed all tests with generated client; updated recordings * Cleaned up use of map on simple methods * Missed an implementation type
1 parent 7a794cd commit fdb0e62

File tree

118 files changed

+3949
-605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3949
-605
lines changed

eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,10 @@ the main ServiceBusClientBuilder. -->
551551
files="com.azure.search.documents.SearchIndexingBufferedSender"/>
552552

553553
<!-- Suppress checks on AutoRest generated Attestation service code -->
554-
<suppress checks="(MissingJavadocMethod|EnforceFinalFields)"
555-
files=".*[/\\]azure[/\\]security[/\\]attestation[/\\]AttestationClientBuilder.java"/>
554+
<suppress checks="ThrowFromClientLogger"
555+
files="com.azure.security.attestation.models.JsonWebKey.java"/>
556556
<suppress checks="WhitespaceAround|ThrowFromClientLogger"
557-
files="com.azure.security.attestation.models.*\.java"/>
557+
files="com.azure.security.attestation.implementation.models.*\.java"/>
558558

559559
<suppress checks="com.azure.tools.checkstyle.checks.GoodLoggingCheck"
560560
files="com.azure.core.test.AzureTestWatcher.java"/>

eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,8 +2459,14 @@
24592459

24602460
<!-- Machine generated classes for MAA service generate spotBugs errors -->
24612461
<Match>
2462-
<Class name="~com.azure.security.attestation.models\.[\w]+"/>
2463-
<Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS"/>
2462+
<Or>
2463+
<Class name="~com.azure.security.attestation.implementation.models.*"/>
2464+
<Class name="~com.azure.security.attestation.models.*+"/>
2465+
</Or>
2466+
<Or>
2467+
<Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS"/>
2468+
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/>
2469+
</Or>
24642470
</Match>
24652471

24662472
<!-- Generated implementation of Anomaly Detector is using an inline class -->

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
import com.azure.security.attestation.models.AttestSgxEnclaveRequest;
1414
import com.azure.security.attestation.models.AttestationResponse;
1515
import com.azure.security.attestation.models.CloudErrorException;
16-
import com.azure.security.attestation.models.TpmAttestationRequest;
17-
import com.azure.security.attestation.models.TpmAttestationResponse;
1816
import reactor.core.publisher.Mono;
1917

20-
/** Initializes a new instance of the asynchronous AttestationClient type. */
18+
import java.nio.charset.StandardCharsets;
19+
import java.util.Objects;
20+
21+
/** Initializes a new instance of the asynchronous AzureAttestationRestClient type. */
2122
@ServiceClient(builder = AttestationClientBuilder.class, isAsync = true)
2223
public final class AttestationAsyncClient {
2324
private final AttestationsImpl serviceClient;
@@ -43,7 +44,8 @@ public final class AttestationAsyncClient {
4344
*/
4445
@ServiceMethod(returns = ReturnType.SINGLE)
4546
public Mono<Response<AttestationResponse>> attestOpenEnclaveWithResponse(AttestOpenEnclaveRequest request) {
46-
return this.serviceClient.attestOpenEnclaveWithResponseAsync(request);
47+
return this.serviceClient.attestOpenEnclaveWithResponseAsync(request.toGenerated())
48+
.map(response -> Utilities.generateResponseFromModelType(response, AttestationResponse.fromGenerated(response.getValue())));
4749
}
4850

4951
/**
@@ -58,7 +60,8 @@ public Mono<Response<AttestationResponse>> attestOpenEnclaveWithResponse(AttestO
5860
*/
5961
@ServiceMethod(returns = ReturnType.SINGLE)
6062
public Mono<AttestationResponse> attestOpenEnclave(AttestOpenEnclaveRequest request) {
61-
return this.serviceClient.attestOpenEnclaveAsync(request);
63+
return serviceClient.attestOpenEnclaveAsync(request.toGenerated())
64+
.map(AttestationResponse::fromGenerated);
6265
}
6366

6467
/**
@@ -73,7 +76,8 @@ public Mono<AttestationResponse> attestOpenEnclave(AttestOpenEnclaveRequest requ
7376
*/
7477
@ServiceMethod(returns = ReturnType.SINGLE)
7578
public Mono<Response<AttestationResponse>> attestSgxEnclaveWithResponse(AttestSgxEnclaveRequest request) {
76-
return this.serviceClient.attestSgxEnclaveWithResponseAsync(request);
79+
return this.serviceClient.attestSgxEnclaveWithResponseAsync(request.toGenerated())
80+
.map(response -> Utilities.generateResponseFromModelType(response, AttestationResponse.fromGenerated(response.getValue())));
7781
}
7882

7983
/**
@@ -88,7 +92,8 @@ public Mono<Response<AttestationResponse>> attestSgxEnclaveWithResponse(AttestSg
8892
*/
8993
@ServiceMethod(returns = ReturnType.SINGLE)
9094
public Mono<AttestationResponse> attestSgxEnclave(AttestSgxEnclaveRequest request) {
91-
return this.serviceClient.attestSgxEnclaveAsync(request);
95+
return this.serviceClient.attestSgxEnclaveAsync(request.toGenerated())
96+
.map(AttestationResponse::fromGenerated);
9297
}
9398

9499
/**
@@ -102,8 +107,9 @@ public Mono<AttestationResponse> attestSgxEnclave(AttestSgxEnclaveRequest reques
102107
* @return attestation response for Trusted Platform Module (TPM) attestation.
103108
*/
104109
@ServiceMethod(returns = ReturnType.SINGLE)
105-
public Mono<Response<TpmAttestationResponse>> attestTpmWithResponse(TpmAttestationRequest request) {
106-
return this.serviceClient.attestTpmWithResponseAsync(request);
110+
public Mono<Response<String>> attestTpmWithResponse(String request) {
111+
return this.serviceClient.attestTpmWithResponseAsync(new com.azure.security.attestation.implementation.models.TpmAttestationRequest().setData(request.getBytes(StandardCharsets.UTF_8)))
112+
.map(response -> Utilities.generateResponseFromModelType(response, new String(Objects.requireNonNull(response.getValue().getData()), StandardCharsets.UTF_8)));
107113
}
108114

109115
/**
@@ -117,7 +123,8 @@ public Mono<Response<TpmAttestationResponse>> attestTpmWithResponse(TpmAttestati
117123
* @return attestation response for Trusted Platform Module (TPM) attestation.
118124
*/
119125
@ServiceMethod(returns = ReturnType.SINGLE)
120-
public Mono<TpmAttestationResponse> attestTpm(TpmAttestationRequest request) {
121-
return this.serviceClient.attestTpmAsync(request);
126+
public Mono<String> attestTpm(String request) {
127+
return this.serviceClient.attestTpmAsync(new com.azure.security.attestation.implementation.models.TpmAttestationRequest().setData(request.getBytes(StandardCharsets.UTF_8)))
128+
.map(response -> new String(response.getData(), StandardCharsets.UTF_8));
122129
}
123130
}

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
import com.azure.core.http.rest.Response;
1111
import com.azure.core.util.Context;
1212
import com.azure.security.attestation.implementation.AttestationsImpl;
13+
import com.azure.security.attestation.implementation.models.TpmAttestationRequest;
14+
import com.azure.security.attestation.implementation.models.TpmAttestationResponse;
1315
import com.azure.security.attestation.models.AttestOpenEnclaveRequest;
1416
import com.azure.security.attestation.models.AttestSgxEnclaveRequest;
1517
import com.azure.security.attestation.models.AttestationResponse;
1618
import com.azure.security.attestation.models.CloudErrorException;
17-
import com.azure.security.attestation.models.TpmAttestationRequest;
18-
import com.azure.security.attestation.models.TpmAttestationResponse;
1919

20-
/** Initializes a new instance of the synchronous AttestationClient type. */
20+
import java.nio.charset.StandardCharsets;
21+
import java.util.Objects;
22+
23+
/** Initializes a new instance of the synchronous AzureAttestationRestClient type. */
2124
@ServiceClient(builder = AttestationClientBuilder.class)
2225
public final class AttestationClient {
2326
private final AttestationsImpl serviceClient;
@@ -43,7 +46,7 @@ public final class AttestationClient {
4346
*/
4447
@ServiceMethod(returns = ReturnType.SINGLE)
4548
public AttestationResponse attestOpenEnclave(AttestOpenEnclaveRequest request) {
46-
return this.serviceClient.attestOpenEnclave(request);
49+
return AttestationResponse.fromGenerated(this.serviceClient.attestOpenEnclave(request.toGenerated()));
4750
}
4851

4952
/**
@@ -60,7 +63,8 @@ public AttestationResponse attestOpenEnclave(AttestOpenEnclaveRequest request) {
6063
@ServiceMethod(returns = ReturnType.SINGLE)
6164
public Response<AttestationResponse> attestOpenEnclaveWithResponse(
6265
AttestOpenEnclaveRequest request, Context context) {
63-
return this.serviceClient.attestOpenEnclaveWithResponse(request, context);
66+
Response<com.azure.security.attestation.implementation.models.AttestationResponse> response = this.serviceClient.attestOpenEnclaveWithResponse(request.toGenerated(), context);
67+
return Utilities.generateResponseFromModelType(response, AttestationResponse.fromGenerated(response.getValue()));
6468
}
6569

6670
/**
@@ -75,7 +79,7 @@ public Response<AttestationResponse> attestOpenEnclaveWithResponse(
7579
*/
7680
@ServiceMethod(returns = ReturnType.SINGLE)
7781
public AttestationResponse attestSgxEnclave(AttestSgxEnclaveRequest request) {
78-
return this.serviceClient.attestSgxEnclave(request);
82+
return AttestationResponse.fromGenerated(serviceClient.attestSgxEnclave(request.toGenerated()));
7983
}
8084

8185
/**
@@ -92,7 +96,8 @@ public AttestationResponse attestSgxEnclave(AttestSgxEnclaveRequest request) {
9296
@ServiceMethod(returns = ReturnType.SINGLE)
9397
public Response<AttestationResponse> attestSgxEnclaveWithResponse(
9498
AttestSgxEnclaveRequest request, Context context) {
95-
return this.serviceClient.attestSgxEnclaveWithResponse(request, context);
99+
Response<com.azure.security.attestation.implementation.models.AttestationResponse> response = this.serviceClient.attestSgxEnclaveWithResponse(request.toGenerated(), context);
100+
return Utilities.generateResponseFromModelType(response, AttestationResponse.fromGenerated(response.getValue()));
96101
}
97102

98103
/**
@@ -106,8 +111,10 @@ public Response<AttestationResponse> attestSgxEnclaveWithResponse(
106111
* @return attestation response for Trusted Platform Module (TPM) attestation.
107112
*/
108113
@ServiceMethod(returns = ReturnType.SINGLE)
109-
public TpmAttestationResponse attestTpm(TpmAttestationRequest request) {
110-
return this.serviceClient.attestTpm(request);
114+
public String attestTpm(String request) {
115+
return new String(Objects.requireNonNull(this.serviceClient.attestTpm(
116+
new TpmAttestationRequest()
117+
.setData(request.getBytes(StandardCharsets.UTF_8))).getData()), StandardCharsets.UTF_8);
111118
}
112119

113120
/**
@@ -122,7 +129,9 @@ public TpmAttestationResponse attestTpm(TpmAttestationRequest request) {
122129
* @return attestation response for Trusted Platform Module (TPM) attestation.
123130
*/
124131
@ServiceMethod(returns = ReturnType.SINGLE)
125-
public Response<TpmAttestationResponse> attestTpmWithResponse(TpmAttestationRequest request, Context context) {
126-
return this.serviceClient.attestTpmWithResponse(request, context);
132+
public Response<String> attestTpmWithResponse(String request, Context context) {
133+
134+
Response<TpmAttestationResponse> response = this.serviceClient.attestTpmWithResponse(new TpmAttestationRequest().setData(request.getBytes(StandardCharsets.UTF_8)), context);
135+
return Utilities.generateResponseFromModelType(response, new String(Objects.requireNonNull(response.getValue().getData()), StandardCharsets.UTF_8));
127136
}
128137
}

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
import com.azure.core.util.Configuration;
1919
import com.azure.core.util.serializer.JacksonAdapter;
2020
import com.azure.core.util.serializer.SerializerAdapter;
21+
import com.azure.security.attestation.implementation.AttestationClientImplBuilder;
2122
import com.azure.security.attestation.implementation.AttestationClientImpl;
23+
2224
import java.util.ArrayList;
2325
import java.util.HashMap;
2426
import java.util.List;
2527
import java.util.Map;
28+
import java.util.Objects;
2629

2730
/** A builder for creating a new instance of the AttestationClient type. */
2831
@ServiceClientBuilder(
@@ -45,6 +48,9 @@ public final class AttestationClientBuilder {
4548

4649
private final Map<String, String> properties = new HashMap<>();
4750

51+
/**
52+
* Creates a new instance of the AttestationClientBuilder class.
53+
*/
4854
public AttestationClientBuilder() {
4955
this.pipelinePolicies = new ArrayList<>();
5056
}
@@ -53,23 +59,23 @@ public AttestationClientBuilder() {
5359
* The attestation instance base URI, for example
5460
* https://mytenant.attest.azure.net.
5561
*/
56-
private String instanceUrl;
62+
private String endpoint;
5763

5864
/**
59-
* Sets The attestation instance base URI, for example https://mytenant.attest.azure.net.
65+
* Sets The attestation endpoint URI, for example https://mytenant.attest.azure.net.
6066
*
61-
* @param instanceUrl the instanceUrl value.
67+
* @param endpoint The endpoint to connect to.
6268
* @return the AttestationClientBuilder.
6369
*/
64-
public AttestationClientBuilder instanceUrl(String instanceUrl) {
65-
this.instanceUrl = instanceUrl;
70+
public AttestationClientBuilder endpoint(String endpoint) {
71+
this.endpoint = endpoint;
6672
return this;
6773
}
6874

6975
/*
7076
* The HTTP pipeline to send requests through
7177
*/
72-
private HttpPipeline pipeline;
78+
private HttpPipeline httpPipeline;
7379

7480
/**
7581
* Sets The HTTP pipeline to send requests through.
@@ -78,7 +84,7 @@ public AttestationClientBuilder instanceUrl(String instanceUrl) {
7884
* @return the AttestationClientBuilder.
7985
*/
8086
public AttestationClientBuilder pipeline(HttpPipeline pipeline) {
81-
this.pipeline = pipeline;
87+
this.httpPipeline = pipeline;
8288
return this;
8389
}
8490

@@ -167,7 +173,7 @@ public AttestationClientBuilder retryPolicy(RetryPolicy retryPolicy) {
167173
/*
168174
* The list of Http pipeline policies to add.
169175
*/
170-
private List<HttpPipelinePolicy> pipelinePolicies;
176+
private final List<HttpPipelinePolicy> pipelinePolicies;
171177

172178
/**
173179
* Adds a custom Http pipeline policy.
@@ -186,14 +192,22 @@ public AttestationClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
186192
* @return an instance of AttestationClientImpl.
187193
*/
188194
private AttestationClientImpl buildInnerClient() {
189-
if (pipeline == null) {
190-
this.pipeline = createHttpPipeline();
195+
Objects.requireNonNull(endpoint);
196+
197+
HttpPipeline pipeline;
198+
if (httpPipeline != null) {
199+
pipeline = httpPipeline;
200+
} else {
201+
pipeline = createHttpPipeline();
191202
}
192203
if (serializerAdapter == null) {
193204
this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter();
194205
}
195-
AttestationClientImpl client = new AttestationClientImpl(pipeline, serializerAdapter, instanceUrl);
196-
return client;
206+
AttestationClientImplBuilder client = new AttestationClientImplBuilder()
207+
.pipeline(pipeline)
208+
.instanceUrl(endpoint)
209+
.serializerAdapter(serializerAdapter);
210+
return client.buildClient();
197211
}
198212

199213
private HttpPipeline createHttpPipeline() {
@@ -213,12 +227,10 @@ private HttpPipeline createHttpPipeline() {
213227
policies.addAll(this.pipelinePolicies);
214228
HttpPolicyProviders.addAfterRetryPolicies(policies);
215229
policies.add(new HttpLoggingPolicy(httpLogOptions));
216-
HttpPipeline httpPipeline =
217-
new HttpPipelineBuilder()
218-
.policies(policies.toArray(new HttpPipelinePolicy[0]))
219-
.httpClient(httpClient)
220-
.build();
221-
return httpPipeline;
230+
return new HttpPipelineBuilder()
231+
.policies(policies.toArray(new HttpPipelinePolicy[0]))
232+
.httpClient(httpClient)
233+
.build();
222234
}
223235

224236
/**

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import com.azure.security.attestation.models.PolicyResponse;
1515
import reactor.core.publisher.Mono;
1616

17-
/** Initializes a new instance of the asynchronous AttestationClient type. */
17+
/** Initializes a new instance of the asynchronous AzureAttestationRestClient type. */
1818
@ServiceClient(builder = AttestationClientBuilder.class, isAsync = true)
1919
public final class PolicyAsyncClient {
2020
private final PoliciesImpl serviceClient;
@@ -39,7 +39,8 @@ public final class PolicyAsyncClient {
3939
*/
4040
@ServiceMethod(returns = ReturnType.SINGLE)
4141
public Mono<Response<PolicyResponse>> getWithResponse(AttestationType attestationType) {
42-
return this.serviceClient.getWithResponseAsync(attestationType);
42+
return this.serviceClient.getWithResponseAsync(attestationType)
43+
.map(response -> Utilities.generateResponseFromModelType(response, PolicyResponse.fromGenerated(response.getValue())));
4344
}
4445

4546
/**
@@ -53,7 +54,9 @@ public Mono<Response<PolicyResponse>> getWithResponse(AttestationType attestatio
5354
*/
5455
@ServiceMethod(returns = ReturnType.SINGLE)
5556
public Mono<PolicyResponse> get(AttestationType attestationType) {
56-
return this.serviceClient.getAsync(attestationType);
57+
return serviceClient.getAsync(attestationType)
58+
.map(PolicyResponse::fromGenerated);
59+
5760
}
5861

5962
/**
@@ -69,7 +72,8 @@ public Mono<PolicyResponse> get(AttestationType attestationType) {
6972
@ServiceMethod(returns = ReturnType.SINGLE)
7073
public Mono<Response<PolicyResponse>> setWithResponse(
7174
AttestationType attestationType, String newAttestationPolicy) {
72-
return this.serviceClient.setWithResponseAsync(attestationType, newAttestationPolicy);
75+
return serviceClient.setWithResponseAsync(attestationType, newAttestationPolicy)
76+
.map(response -> Utilities.generateResponseFromModelType(response, PolicyResponse.fromGenerated(response.getValue())));
7377
}
7478

7579
/**
@@ -84,7 +88,8 @@ public Mono<Response<PolicyResponse>> setWithResponse(
8488
*/
8589
@ServiceMethod(returns = ReturnType.SINGLE)
8690
public Mono<PolicyResponse> set(AttestationType attestationType, String newAttestationPolicy) {
87-
return this.serviceClient.setAsync(attestationType, newAttestationPolicy);
91+
return this.serviceClient.setAsync(attestationType, newAttestationPolicy)
92+
.map(PolicyResponse::fromGenerated);
8893
}
8994

9095
/**
@@ -99,7 +104,8 @@ public Mono<PolicyResponse> set(AttestationType attestationType, String newAttes
99104
*/
100105
@ServiceMethod(returns = ReturnType.SINGLE)
101106
public Mono<Response<PolicyResponse>> resetWithResponse(AttestationType attestationType, String policyJws) {
102-
return this.serviceClient.resetWithResponseAsync(attestationType, policyJws);
107+
return this.serviceClient.resetWithResponseAsync(attestationType, policyJws)
108+
.map(response -> Utilities.generateResponseFromModelType(response, PolicyResponse.fromGenerated(response.getValue())));
103109
}
104110

105111
/**
@@ -114,6 +120,7 @@ public Mono<Response<PolicyResponse>> resetWithResponse(AttestationType attestat
114120
*/
115121
@ServiceMethod(returns = ReturnType.SINGLE)
116122
public Mono<PolicyResponse> reset(AttestationType attestationType, String policyJws) {
117-
return this.serviceClient.resetAsync(attestationType, policyJws);
123+
return this.serviceClient.resetAsync(attestationType, policyJws)
124+
.map(PolicyResponse::fromGenerated);
118125
}
119126
}

0 commit comments

Comments
 (0)