Skip to content

Commit

Permalink
Added support for clientOptions in generated code; Fixed several ApiV…
Browse files Browse the repository at this point in the history
…iew issues (Azure#26226)

* Cleaned up some autorest generation; Removed some unnecessary methods

* Updated autorest version; Added support for ClientOptions

* Corrected User-Agent string by building HTTP pipeline manually

* Removed the impl Builder class since it no longer provides any value

* Fixed typo in ServiceVersion.java file; removed a couple of unneeded imports

* Added telemetry tests to attestation SDK

* Version goes on version node

* Bumped opentelemetry to version 18
  • Loading branch information
LarryOsterman authored Jan 21, 2022
1 parent 5b2adff commit 7cbe7a5
Show file tree
Hide file tree
Showing 32 changed files with 524 additions and 1,623 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,12 @@ the main ServiceBusClientBuilder. -->
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck"
files="com.azure.search.documents.(SearchIndexingBufferedAsyncSender|SearchIndexingBufferedSender)"/>

<!-- Allow Attestation Service use of OpenTelemetry -->
<suppress checks="IllegalImport" files=".*[/\\]src[/\\]test[/\\]java[/\\]com[/\\]azure[/\\]security[/\\]attestation[/\\]AttestationClientTestBase.java"/>
<suppress checks="IllegalImport" files=".*[/\\]src[/\\]test[/\\]java[/\\]com[/\\]azure[/\\]security[/\\]attestation[/\\]AttestationTest.java"/>

<!-- Suppress checks on AutoRest generated Attestation service code -->
<suppress checks="ThrowFromClientLogger"
files="com.azure.security.attestation.models.JsonWebKey.java"/>
<suppress checks="WhitespaceAround|ThrowFromClientLogger"
<suppress checks="WhitespaceAround|ThrowFromClientLogger"
files="com.azure.security.attestation.implementation.models.*\.java"/>

<suppress checks="com.azure.tools.checkstyle.checks.GoodLoggingCheck"
Expand Down
33 changes: 33 additions & 0 deletions sdk/attestation/azure-security-attestation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.10.1</version> <!-- {x-version-update;com.nimbusds:nimbus-jose-jwt;external_dependency} -->
</dependency>
<!-- Added this dependency to include necessary annotations used by reactor core.
Without this dependency, java throws a warning about the GuardedBy attribute. -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version> <!-- {x-version-update;com.google.code.findbugs:jsr305;external_dependency} -->
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand All @@ -60,6 +68,28 @@
<version>1.7.7</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-tracing-opentelemetry</artifactId>
<version>1.0.0-beta.19</version> <!-- {x-version-update;com.azure:azure-core-tracing-opentelemetry;dependency} -->
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>1.0.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-logging</artifactId>
<version>1.0.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-exporter-logging;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
<version>1.0.0</version> <!-- {x-version-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -117,6 +147,9 @@
<bannedDependencies>
<includes>
<include>com.nimbusds:nimbus-jose-jwt:[9.10.1]</include> <!-- {x-include-update;com.nimbusds:nimbus-jose-jwt;external_dependency} -->
<include>io.opentelemetry:opentelemetry-api:[1.0.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-api;external_dependency} -->
<include>io.opentelemetry:opentelemetry-sdk:[1.0.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-sdk;external_dependency} -->
<include>io.opentelemetry:opentelemetry-exporter-logging:[1.0.0]</include> <!-- {x-include-update;io.opentelemetry:opentelemetry-exporter-logging;external_dependency} -->
</includes>
</bannedDependencies>
</rules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Mono<Response<String>> getAttestationPolicyWithResponse(AttestationType attestat
.onErrorMap(Utilities::mapException)
.flatMap(response -> {
Response<AttestationTokenImpl> token = Utilities.generateResponseFromModelType(response, new AttestationTokenImpl(response.getValue().getToken()));
return getCachedAttestationSigners()
return getCachedAttestationSigners(context)
.map(signers -> {
token.getValue().validate(signers, validationOptionsToUse);
String policyJwt = token.getValue().getBody(com.azure.security.attestation.implementation.models.PolicyResult.class).getPolicy();
Expand Down Expand Up @@ -406,7 +406,7 @@ Mono<Response<PolicyResult>> setAttestationPolicyWithResponse(AttestationType at
.onErrorMap(Utilities::mapException)
.flatMap(response -> {
Response<AttestationTokenImpl> token = Utilities.generateResponseFromModelType(response, new AttestationTokenImpl(response.getValue().getToken()));
return getCachedAttestationSigners()
return getCachedAttestationSigners(context)
.map(signers -> {
token.getValue().validate(signers, finalOptions);
PolicyResult policyResult = PolicyResultImpl.fromGenerated(token.getValue().getBody(com.azure.security.attestation.implementation.models.PolicyResult.class));
Expand Down Expand Up @@ -626,7 +626,7 @@ Mono<Response<PolicyResult>> resetAttestationPolicyWithResponse(AttestationType
.onErrorMap(Utilities::mapException)
.flatMap(response -> {
Response<AttestationTokenImpl> token = Utilities.generateResponseFromModelType(response, new AttestationTokenImpl(response.getValue().getToken()));
return getCachedAttestationSigners()
return getCachedAttestationSigners(context)
.map(signers -> {
token.getValue().validate(signers, finalOptions);
PolicyResult policyResult = PolicyResultImpl.fromGenerated(token.getValue().getBody(com.azure.security.attestation.implementation.models.PolicyResult.class));
Expand Down Expand Up @@ -729,7 +729,7 @@ Mono<Response<List<AttestationSigner>>> listPolicyManagementCertificatesWithResp
.onErrorMap(Utilities::mapException)
.flatMap(response -> {
Response<AttestationTokenImpl> responseWithToken = Utilities.generateResponseFromModelType(response, new AttestationTokenImpl(response.getValue().getToken()));
return getCachedAttestationSigners()
return getCachedAttestationSigners(context)
.map(signers -> {
responseWithToken.getValue().validate(signers, optionsToUse);
JsonWebKeySet policyJwks = responseWithToken.getValue().getBody(com.azure.security.attestation.implementation.models.PolicyCertificatesResult.class).getPolicyCertificates();
Expand Down Expand Up @@ -861,7 +861,7 @@ Mono<Response<PolicyCertificatesModificationResult>> addPolicyManagementCertific
.onErrorMap(Utilities::mapException)
.flatMap(response -> {
Response<AttestationTokenImpl> token = Utilities.generateResponseFromModelType(response, new AttestationTokenImpl(response.getValue().getToken()));
return getCachedAttestationSigners()
return getCachedAttestationSigners(context)
.map(signers -> {
token.getValue().validate(signers, finalOptions);
PolicyCertificatesModificationResult addResult = PolicyCertificatesModificationResultImpl.fromGenerated(token.getValue().getBody(com.azure.security.attestation.implementation.models.PolicyCertificatesModificationResult.class));
Expand Down Expand Up @@ -1000,7 +1000,7 @@ Mono<Response<PolicyCertificatesModificationResult>> removePolicyManagementCerti
.onErrorMap(Utilities::mapException)
.flatMap(response -> {
Response<AttestationTokenImpl> token = Utilities.generateResponseFromModelType(response, new AttestationTokenImpl(response.getValue().getToken()));
return getCachedAttestationSigners()
return getCachedAttestationSigners(context)
.map(signers -> {
token.getValue().validate(signers, finalOptions);
PolicyCertificatesModificationResult addResult = PolicyCertificatesModificationResultImpl.fromGenerated(token.getValue().getBody(com.azure.security.attestation.implementation.models.PolicyCertificatesModificationResult.class));
Expand All @@ -1026,14 +1026,15 @@ Mono<Response<PolicyCertificatesModificationResult>> removePolicyManagementCerti
* because the `compareAndSet` API won't capture a reference to the second `signers` object.
*
* </p>
* @param context Context for the operation.
* @return cached signers.
*/
Mono<List<AttestationSigner>> getCachedAttestationSigners() {
Mono<List<AttestationSigner>> getCachedAttestationSigners(Context context) {
if (this.cachedSigners.get() != null) {
return Mono.just(this.cachedSigners.get());
} else {
return this.signingCertificatesImpl.getAsync()
.map(AttestationSignerImpl::attestationSignersFromJwks)
return this.signingCertificatesImpl.getWithResponseAsync(context)
.map(response -> AttestationSignerImpl.attestationSignersFromJwks(response.getValue()))
.map(signers -> {
this.cachedSigners.compareAndSet(null, signers);
return this.cachedSigners.get();
Expand Down
Loading

0 comments on commit 7cbe7a5

Please sign in to comment.