Skip to content

Commit

Permalink
Migrate azure-security-keyvault-certificates to Autorest and stream-s…
Browse files Browse the repository at this point in the history
…tyle serialization (#36724)

Migrate azure-security-keyvault-certificates to Autorest and stream-style serialization
  • Loading branch information
alzimmermsft committed Oct 25, 2023
1 parent bc1589d commit df52c89
Show file tree
Hide file tree
Showing 115 changed files with 14,129 additions and 6,693 deletions.
17 changes: 3 additions & 14 deletions eng/code-quality-reports/src/main/resources/revapi/revapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,9 @@
{
"regex": true,
"code": "java\\.annotation\\.removed",
"old": ".*? com\\.azure\\.containers\\.containerregistry\\.models.*",
"justification": "Removing Jackson annotations from ACR in transition to stream-style."
},
{
"regex": true,
"code": "java\\.annotation\\.removed",
"old": ".*? com\\.azure\\.search\\.documents(\\.indexes)?\\.models.*",
"justification": "Removing Jackson annotations from Search in transition to stream-style."
"old": ".*? (com\\.azure\\.containers\\.containerregistry\\.models.*|com\\.azure\\.search\\.documents(\\.indexes)?\\.models.*|com\\.azure\\.security\\.keyvault\\.(administration|certificates)\\.models.*)",
"description": ".*com.fasterxml.jackson.*",
"justification": "Removing Jackson annotations from ACR, KeyVault, and Search in transition to stream-style."
},
{
"code": "java.field.removed",
Expand All @@ -289,12 +284,6 @@
"new" : "class com.azure.spring.cloud.autoconfigure.aad.configuration.(AadResourceServerConfiguration.DefaultAadResourceServerWebSecurityConfigurerAdapter|AadWebApplicationConfiguration.DefaultAadWebSecurityConfigurerAdapter)",
"justification": "Element newly annotated with 'org.springframework.boot.autoconfigure.security.ConditionalOnDefaultWebSecurity"
},
{
"regex": true,
"code": "java\\.annotation\\.removed",
"old": ".*? com\\.azure\\.security\\.keyvault\\.administration\\.models.*",
"justification": "Removing Jackson annotations from KeyVault Administration in transition to stream-style."
},
{
"regex": true,
"code" : "java.field.enumConstantOrderChanged",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/keyvault/azure-security-keyvault-certificates",
"Tag": "java/keyvault/azure-security-keyvault-certificates_1e177cf1ed"
"Tag": "java/keyvault/azure-security-keyvault-certificates_13a9135895"
}
18 changes: 6 additions & 12 deletions sdk/keyvault/azure-security-keyvault-certificates/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
<artifactId>azure-core</artifactId>
<version>1.44.1</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-json</artifactId>
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-json;dependency} -->
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
Expand All @@ -74,12 +80,6 @@
<version>5.9.3</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-params;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>2.2</version> <!-- {x-version-update;org.hamcrest:hamcrest-library;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
Expand All @@ -104,12 +104,6 @@
<version>1.10.4</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version> <!-- {x-version-update;org.mockito:mockito-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-lts8on</artifactId>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeader;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
Expand Down Expand Up @@ -106,18 +105,23 @@ public final class CertificateClientBuilder implements
HttpTrait<CertificateClientBuilder>,
ConfigurationTrait<CertificateClientBuilder> {
private static final ClientLogger LOGGER = new ClientLogger(CertificateClientBuilder.class);
// This is properties file's name.
private static final String AZURE_KEY_VAULT_CERTIFICATES_PROPERTIES = "azure-key-vault-certificates.properties";
private static final String SDK_NAME = "name";
private static final String SDK_VERSION = "version";

private static final String CLIENT_NAME;
private static final String CLIENT_VERSION;

static {
// This is properties file's name.
Map<String, String> properties = CoreUtils.getProperties("azure-key-vault-certificates.properties");
CLIENT_NAME = properties.getOrDefault("name", "UnknownName");
CLIENT_VERSION = properties.getOrDefault("version", "UnknownVersion");
}

// Please see <a href=https://docs.microsoft.com/azure/azure-resource-manager/management/azure-services-resource-providers>here</a>
// for more information on Azure resource provider namespaces.
private static final String KEYVAULT_TRACING_NAMESPACE_VALUE = "Microsoft.KeyVault";
private static final ClientOptions DEFAULT_CLIENT_OPTIONS = new ClientOptions();
private final List<HttpPipelinePolicy> perCallPolicies;
private final List<HttpPipelinePolicy> perRetryPolicies;
private final Map<String, String> properties;

private TokenCredential credential;
private HttpPipeline pipeline;
Expand All @@ -138,7 +142,6 @@ public CertificateClientBuilder() {
httpLogOptions = new HttpLogOptions();
perCallPolicies = new ArrayList<>();
perRetryPolicies = new ArrayList<>();
properties = CoreUtils.getProperties(AZURE_KEY_VAULT_CERTIFICATES_PROPERTIES);
}

/**
Expand All @@ -160,7 +163,7 @@ public CertificateClientBuilder() {
* and {@link #retryPolicy(RetryPolicy)} have been set.
*/
public CertificateClient buildClient() {
return new CertificateClient(buildInnerClient());
return new CertificateClient(buildInnerClient(), vaultUrl);
}

/**
Expand All @@ -182,7 +185,7 @@ public CertificateClient buildClient() {
* and {@link #retryPolicy(RetryPolicy)} have been set.
*/
public CertificateAsyncClient buildAsyncClient() {
return new CertificateAsyncClient(buildInnerClient());
return new CertificateAsyncClient(buildInnerClient(), vaultUrl);
}

private CertificateClientImpl buildInnerClient() {
Expand All @@ -199,7 +202,7 @@ private CertificateClientImpl buildInnerClient() {
CertificateServiceVersion serviceVersion = version != null ? version : CertificateServiceVersion.getLatest();

if (pipeline != null) {
return new CertificateClientImpl(vaultUrl, pipeline, serviceVersion);
return new CertificateClientImpl(pipeline, serviceVersion.getVersion());
}

if (credential == null) {
Expand All @@ -210,20 +213,16 @@ private CertificateClientImpl buildInnerClient() {
// Closest to API goes first, closest to wire goes last.
final List<HttpPipelinePolicy> policies = new ArrayList<>();

String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");

httpLogOptions = (httpLogOptions == null) ? new HttpLogOptions() : httpLogOptions;

ClientOptions localClientOptions = clientOptions != null ? clientOptions : DEFAULT_CLIENT_OPTIONS;
policies.add(new UserAgentPolicy(CoreUtils.getApplicationId(localClientOptions, httpLogOptions), CLIENT_NAME,
CLIENT_VERSION, buildConfiguration));

policies.add(new UserAgentPolicy(CoreUtils.getApplicationId(localClientOptions, httpLogOptions), clientName,
clientVersion, buildConfiguration));

List<HttpHeader> httpHeaderList = new ArrayList<>();
localClientOptions.getHeaders().forEach(header ->
httpHeaderList.add(new HttpHeader(header.getName(), header.getValue())));
policies.add(new AddHeadersPolicy(new HttpHeaders(httpHeaderList)));
HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions);
if (headers != null) {
policies.add(new AddHeadersPolicy(headers));
}

// Add per call additional policies.
policies.addAll(perCallPolicies);
Expand All @@ -242,7 +241,7 @@ private CertificateClientImpl buildInnerClient() {

TracingOptions tracingOptions = localClientOptions.getTracingOptions();
Tracer tracer = TracerProvider.getDefaultProvider()
.createTracer(clientName, clientVersion, KEYVAULT_TRACING_NAMESPACE_VALUE, tracingOptions);
.createTracer(CLIENT_NAME, CLIENT_VERSION, KEYVAULT_TRACING_NAMESPACE_VALUE, tracingOptions);

HttpPipeline pipeline = new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
Expand All @@ -251,7 +250,7 @@ private CertificateClientImpl buildInnerClient() {
.clientOptions(localClientOptions)
.build();

return new CertificateClientImpl(vaultUrl, pipeline, serviceVersion);
return new CertificateClientImpl(pipeline, serviceVersion.getVersion());
}

/**
Expand Down Expand Up @@ -401,7 +400,7 @@ public CertificateClientBuilder pipeline(HttpPipeline pipeline) {

/**
* Sets the configuration store that is used during construction of the service client.
*
* <p>
* The default configuration store is a clone of the {@link Configuration#getGlobalConfiguration() global
* configuration store}, use {@link Configuration#NONE} to bypass using configuration settings during construction.
*
Expand Down Expand Up @@ -435,9 +434,9 @@ public CertificateClientBuilder serviceVersion(CertificateServiceVersion version

/**
* Sets the {@link RetryPolicy} that is used when each request is sent.
*
* <p>
* The default retry policy will be used in the pipeline, if not provided.
*
* <p>
* Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}.
*
* @param retryPolicy user's retry policy applied to each request.
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit df52c89

Please sign in to comment.