Skip to content

Commit

Permalink
Kv cert api updates (#6136)
Browse files Browse the repository at this point in the history
KV Certificate API updates
  • Loading branch information
g2vinay authored Nov 1, 2019
1 parent bbf1cbd commit 8cee5a3
Show file tree
Hide file tree
Showing 33 changed files with 819 additions and 2,063 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@
<Class name="com.azure.security.keyvault.certificates.models.DeletedCertificate"/>
<Class name="com.azure.security.keyvault.certificates.models.Certificate"/>
<Class name="com.azure.security.keyvault.certificates.models.CertificateProperties"/>
<Class name="com.azure.security.keyvault.certificates.models.IssuerBase"/>
<Class name="com.azure.security.keyvault.certificates.models.Issuer"/>
<Class name="com.azure.security.keyvault.certificates.models.IssuerProperties"/>
<Class name="com.azure.security.keyvault.certificates.models.CertificateIssuer"/>
<Class name="com.azure.security.keyvault.certificates.models.CertificatePolicy"/>
<Class name="com.azure.security.keyvault.certificates.models.LifetimeAction"/>
<Class name="com.azure.security.keyvault.certificates.models.LifeTimeAction"/>
<Class name="com.azure.security.keyvault.certificates.models.CertificateOperation"/>
</Or>
<Bug pattern="UPM_UNCALLED_PRIVATE_METHOD"/>
Expand Down Expand Up @@ -532,6 +532,10 @@
<Class name="com.azure.security.keyvault.certificates.models.webkey.ByteExtensions"/>
<Method name="clone"/>
</And>
<And>
<Class name="com.azure.security.keyvault.certificates.models.CertificateProperties"/>
<Method name="getX509Thumbprint"/>
</And>
</Or>
<Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS"/>
</Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.security.keyvault.certificates;

import com.azure.security.keyvault.certificates.models.LifetimeActionType;
import com.azure.security.keyvault.certificates.models.CertificatePolicyAction;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -15,25 +15,25 @@ class Action {
* 'AutoRenew'.
*/
@JsonProperty(value = "action_type")
private LifetimeActionType lifetimeActionType;
private CertificatePolicyAction certificatePolicyAction;

/**
* Get the lifetimeActionType value.
* Get the certificatePolicyAction value.
*
* @return the updated lifetimeActionType value
* @return the updated certificatePolicyAction value
*/
LifetimeActionType getActionType() {
return this.lifetimeActionType;
CertificatePolicyAction getActionType() {
return this.certificatePolicyAction;
}

/**
* Set the lifetimeActionType value.
* Set the certificatePolicyAction value.
*
* @param lifetimeActionType the lifetimeActionType value to set
* @param certificatePolicyAction the certificatePolicyAction value to set
* @return the Action object itself.
*/
Action setActionType(LifetimeActionType lifetimeActionType) {
this.lifetimeActionType = lifetimeActionType;
Action setActionType(CertificatePolicyAction certificatePolicyAction) {
this.certificatePolicyAction = certificatePolicyAction;
return this;
}
}

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 @@ -30,7 +30,7 @@
* It constructs an instance of the desired client.
*
* <p> The minimal configuration options required by {@link CertificateClientBuilder} to build {@link CertificateAsyncClient}
* are {@link String endpoint} and {@link TokenCredential credential}. </p>
* are {@link String vaultUrl} and {@link TokenCredential credential}. </p>
*
* {@codesnippet com.azure.security.keyvault.certificates.CertificateAsyncClient.instantiation}
*
Expand All @@ -39,13 +39,13 @@
* {@codesnippet com.azure.security.keyvault.certificates.CertificateAsyncClient.withhttpclient.instantiation}
*
* <p>Alternatively, custom {@link HttpPipeline http pipeline} with custom {@link HttpPipelinePolicy} policies and {@link String endpoint}
* <p>Alternatively, custom {@link HttpPipeline http pipeline} with custom {@link HttpPipelinePolicy} policies and {@link String vaultUrl}
* can be specified. It provides finer control over the construction of {@link CertificateAsyncClient} and {@link CertificateClient}</p>
*
* {@codesnippet com.azure.security.keyvault.certificates.CertificateAsyncClient.pipeline.instantiation}
*
* <p> The minimal configuration options required by {@link CertificateClientBuilder certificateClientBuilder} to build {@link CertificateClient}
* are {@link String endpoint} and {@link TokenCredential credential}. </p>
* are {@link String vaultUrl} and {@link TokenCredential credential}. </p>
*
* {@codesnippet com.azure.security.keyvault.certificates.CertificateClient.instantiation}
*
Expand All @@ -59,7 +59,7 @@ public final class CertificateClientBuilder {
private final List<HttpPipelinePolicy> policies;
private TokenCredential credential;
private HttpPipeline pipeline;
private URL endpoint;
private URL vaultUrl;
private HttpClient httpClient;
private HttpLogOptions httpLogOptions;
private final RetryPolicy retryPolicy;
Expand All @@ -80,14 +80,14 @@ public CertificateClientBuilder() {
* Every time {@code buildClient()} is called, a new instance of {@link CertificateClient} is created.
*
* <p>If {@link CertificateClientBuilder#pipeline(HttpPipeline) pipeline} is set, then the {@code pipeline} and
* {@link CertificateClientBuilder#endpoint(String) serviceEndpoint} are used to create the
* {@link CertificateClientBuilder#vaultUrl(String) serviceEndpoint} are used to create the
* {@link CertificateClientBuilder client}. All other builder settings are ignored. If {@code pipeline} is not set,
* then {@link CertificateClientBuilder#credential(TokenCredential) key vault credential} and
* {@link CertificateClientBuilder#endpoint(String) key vault endpoint} are required to build the {@link CertificateClient client}.</p>
* {@link CertificateClientBuilder#vaultUrl(String) key vault url} are required to build the {@link CertificateClient client}.</p>
*
* @return A {@link CertificateClient} with the options set from the builder.
* @throws IllegalStateException If {@link CertificateClientBuilder#credential(TokenCredential)} or
* {@link CertificateClientBuilder#endpoint(String)} have not been set.
* {@link CertificateClientBuilder#vaultUrl(String)} have not been set.
*/
public CertificateClient buildClient() {
return new CertificateClient(buildAsyncClient());
Expand All @@ -98,14 +98,14 @@ public CertificateClient buildClient() {
* Every time {@code buildAsyncClient()} is called, a new instance of {@link CertificateAsyncClient} is created.
*
* <p>If {@link CertificateClientBuilder#pipeline(HttpPipeline) pipeline} is set, then the {@code pipeline} and
* {@link CertificateClientBuilder#endpoint(String) serviceEndpoint} are used to create the
* {@link CertificateClientBuilder#vaultUrl(String) serviceEndpoint} are used to create the
* {@link CertificateClientBuilder client}. All other builder settings are ignored. If {@code pipeline} is not set,
* then {@link CertificateClientBuilder#credential(TokenCredential) key vault credential and
* {@link CertificateClientBuilder#endpoint(String)} key vault endpoint are required to build the {@link CertificateAsyncClient client}.}</p>
* {@link CertificateClientBuilder#vaultUrl(String)} key vault url are required to build the {@link CertificateAsyncClient client}.}</p>
*
* @return A {@link CertificateAsyncClient} with the options set from the builder.
* @throws IllegalStateException If {@link CertificateClientBuilder#credential(TokenCredential)} or
* {@link CertificateClientBuilder#endpoint(String)} have not been set.
* {@link CertificateClientBuilder#vaultUrl(String)} have not been set.
*/
public CertificateAsyncClient buildAsyncClient() {
Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration().clone() : configuration;
Expand All @@ -117,7 +117,7 @@ public CertificateAsyncClient buildAsyncClient() {
CertificateServiceVersion serviceVersion = version != null ? version : CertificateServiceVersion.getLatest();

if (pipeline != null) {
return new CertificateAsyncClient(endpoint, pipeline, serviceVersion);
return new CertificateAsyncClient(vaultUrl, pipeline, serviceVersion);
}

if (credential == null) {
Expand All @@ -139,19 +139,19 @@ public CertificateAsyncClient buildAsyncClient() {
.httpClient(httpClient)
.build();

return new CertificateAsyncClient(endpoint, pipeline, serviceVersion);
return new CertificateAsyncClient(vaultUrl, pipeline, serviceVersion);
}

/**
* Sets the vault endpoint url to send HTTP requests to.
*
* @param endpoint The vault endpoint url is used as destination on Azure to send requests to.
* @param vaultUrl The vault endpoint url is used as destination on Azure to send requests to.
* @return the updated ServiceClientBuilder object.
* @throws IllegalArgumentException if {@code endpoint} is null or it cannot be parsed into a valid URL.
* @throws IllegalArgumentException if {@code vaultUrl} is null or it cannot be parsed into a valid URL.
*/
public CertificateClientBuilder endpoint(String endpoint) {
public CertificateClientBuilder vaultUrl(String vaultUrl) {
try {
this.endpoint = new URL(endpoint);
this.vaultUrl = new URL(vaultUrl);
} catch (MalformedURLException e) {
throw logger.logExceptionAsError(new IllegalArgumentException("The Azure Key Vault endpoint url is malformed."));
}
Expand Down Expand Up @@ -214,7 +214,7 @@ public CertificateClientBuilder httpClient(HttpClient client) {
* Sets the HTTP pipeline to use for the service client.
*
* If {@code pipeline} is set, all other settings are ignored, aside from
* {@link CertificateClientBuilder#endpoint(String) endpoint} to build {@link CertificateClient} or {@link CertificateAsyncClient}.
* {@link CertificateClientBuilder#vaultUrl(String) vaultUrl} to build {@link CertificateClient} or {@link CertificateAsyncClient}.
*
* @param pipeline The HTTP pipeline to use for sending service requests and receiving responses.
* @return the updated {@link CertificateClientBuilder} object.
Expand Down Expand Up @@ -255,8 +255,8 @@ public CertificateClientBuilder serviceVersion(CertificateServiceVersion version
}

private URL getBuildEndpoint(Configuration configuration) {
if (endpoint != null) {
return endpoint;
if (vaultUrl != null) {
return vaultUrl;
}

String configEndpoint = configuration.get("AZURE_KEYVAULT_ENDPOINT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.security.keyvault.certificates;

import com.azure.security.keyvault.certificates.models.CertificatePolicy;
import com.azure.security.keyvault.certificates.models.LifetimeAction;
import com.azure.security.keyvault.certificates.models.LifeTimeAction;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
Expand All @@ -20,13 +20,13 @@ class CertificatePolicyRequest {
this.x509CertificateProperties = new X509CertificateProperties(certificatePolicy);
this.secretProperties = certificatePolicy.getContentType() != null ? new SecretProperties(certificatePolicy.getContentType().toString()) : null;
this.issuerParameters = new IssuerParameters(certificatePolicy);
this.lifetimeActionRequests = certificatePolicy.getLifetimeActions() != null ? parseLifeTimeActions(certificatePolicy.getLifetimeActions()) : null;
this.lifetimeActionRequests = certificatePolicy.getLifeTimeActions() != null ? parseLifeTimeActions(certificatePolicy.getLifeTimeActions()) : null;
this.attributes = new CertificateRequestAttributes().enabled(certificatePolicy.isEnabled());
}

private List<LifetimeActionRequest> parseLifeTimeActions(List<LifetimeAction> input) {
private List<LifetimeActionRequest> parseLifeTimeActions(List<LifeTimeAction> input) {
List<LifetimeActionRequest> output = new ArrayList<>();
for (LifetimeAction action : input) {
for (LifeTimeAction action : input) {
output.add(new LifetimeActionRequest(action));
}
return output;
Expand Down
Loading

0 comments on commit 8cee5a3

Please sign in to comment.