Skip to content

Commit

Permalink
Added support for creating, updating, retrieving and deleting role de…
Browse files Browse the repository at this point in the history
…finitions in Key Vault Administration (Azure#21125)

* Updated Swagger configuration file.

* Re-generated RBAC-related classes and added some public models to reflect changes in the implementation layer. Added public APIs for setting, retrieving and deleting role definitions, including an options class for these operations.

* Re-generated classes related to backup and restore and added some public models to reflect changes in the implementation layer.

* Applied some PR feedback.

* Updated license for a couple files.

* Added the KeyVaultRoleDefinitionType and included it in SetKeyVaultRoleDefinitionOptions and KeyVaultRoleDefinition.

* Added the public KeyVaultAdministrationException and updated the JavaDoc in all clients to better reflect when it can be thrown.

* Re-recorded all tests.

* Fixed JavaDoc and Checkstyle issues.

* Made it so that NullPointerExceptions for null service method arguments are logged in all clients.

* Removed the roleType argument in SetKeyVaultRoleDefinitionOptions.

* Removed unused import.

* Renamed SetKeyVaultRoleDefinitionOptions to SetRoleDefinitionOptions.

* Renamed some arguments and members for consistency with other languages. Applied other PR feedback.
  • Loading branch information
vcolin7 authored May 9, 2021
1 parent 238f4c8 commit 7641fcd
Show file tree
Hide file tree
Showing 85 changed files with 4,848 additions and 968 deletions.

Large diffs are not rendered by default.

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 @@ -8,6 +8,7 @@
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.util.polling.SyncPoller;
import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation;
import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException;
import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation;

import java.time.Duration;
Expand Down Expand Up @@ -43,8 +44,11 @@ public String getVaultUrl() {
*
* @param blobStorageUrl The URL for the Blob Storage resource where the backup will be located.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
*
* @return A {@link SyncPoller} polling on the {@link KeyVaultBackupOperation backup operation} status.
* @throws NullPointerException if the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
*
* @throws KeyVaultAdministrationException If the given {@code blobStorageUrl} or {@code sasToken} are invalid.
* @throws NullPointerException If the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken) {
Expand All @@ -57,79 +61,102 @@ public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorag
* @param blobStorageUrl The URL for the Blob Storage resource where the backup will be located.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @param pollingInterval The interval at which the operation status will be polled for.
*
* @return A {@link SyncPoller} polling on the {@link KeyVaultBackupOperation backup operation} status.
* @throws NullPointerException if the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
*
* @throws KeyVaultAdministrationException If the given {@code blobStorageUrl} or {@code sasToken} are invalid.
* @throws NullPointerException If the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken, Duration pollingInterval) {
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken,
Duration pollingInterval) {
return asyncClient.beginBackup(blobStorageUrl, sasToken, pollingInterval).getSyncPoller();
}

/**
* Initiates a full restore of the Key Vault.
*
* @param backupFolderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* backup operation. An example of such a URL may look like the following:
* https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
*
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
* @throws NullPointerException if the {@code backupFolderUrl} or {@code sasToken} are {@code null}.
*
* @throws KeyVaultAdministrationException If the given {@code folderUrl} or {@code sasToken} are invalid.
* @throws NullPointerException If the {@code folderUrl} or {@code sasToken} are {@code null}.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String backupFolderUrl, String sasToken) {
return asyncClient.beginRestore(backupFolderUrl, sasToken).getSyncPoller();
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String folderUrl, String sasToken) {
return asyncClient.beginRestore(folderUrl, sasToken).getSyncPoller();
}

/**
* Initiates a full restore of the Key Vault.
*
* @param backupFolderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* backup operation. An example of such a URL may look like the following:
* https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @param pollingInterval The interval at which the operation status will be polled for.
*
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
* @throws NullPointerException if the {@code backupFolderUrl} or {@code sasToken} are {@code null}.
*
* @throws KeyVaultAdministrationException If the given {@code folderUrl} or {@code sasToken} are invalid.
* @throws NullPointerException If the {@code folderUrl} or {@code sasToken} are {@code null}.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String backupFolderUrl, String sasToken, Duration pollingInterval) {
return asyncClient.beginRestore(backupFolderUrl, sasToken, pollingInterval).getSyncPoller();
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String folderUrl, String sasToken,
Duration pollingInterval) {
return asyncClient.beginRestore(folderUrl, sasToken, pollingInterval).getSyncPoller();
}

/**
* Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob
* storage backup folder.
*
* @param keyName The name of the key to be restored.
* @param backupFolderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* backup operation. An example of such a URL may look like the following:
* https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
*
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
* @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code
*
* @throws KeyVaultAdministrationException If the given {@code folderUrl} or {@code sasToken} are invalid.
* @throws NullPointerException If the {@code keyName}, {@code folderUrl} or {@code sasToken} are {@code
* null}.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String backupFolderUrl, String sasToken) {
return asyncClient.beginSelectiveRestore(keyName, backupFolderUrl, sasToken).getSyncPoller();
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String folderUrl,
String sasToken) {
return asyncClient.beginSelectiveRestore(keyName, folderUrl, sasToken).getSyncPoller();
}

/**
* Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob
* storage backup folder.
*
* @param keyName The name of the key to be restored.
* @param backupFolderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* backup operation. An example of such a URL may look like the following:
* https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @param pollingInterval The interval at which the operation status will be polled for.
*
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
* @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code
*
* @throws KeyVaultAdministrationException If the given {@code folderUrl} or {@code sasToken} are invalid.
* @throws NullPointerException If the {@code keyName}, {@code folderUrl} or {@code sasToken} are {@code
* null}.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String backupFolderUrl, String sasToken, Duration pollingInterval) {
return asyncClient.beginSelectiveRestore(keyName, backupFolderUrl, sasToken, pollingInterval).getSyncPoller();
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String folderUrl,
String sasToken, Duration pollingInterval) {
return asyncClient.beginSelectiveRestore(keyName, folderUrl, sasToken, pollingInterval).getSyncPoller();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,41 @@ public RoleAssignmentsImpl getRoleAssignments() {
return this.roleAssignments;
}

/** Initializes an instance of KeyVaultAccessControlClient client. */
KeyVaultAccessControlClientImpl() {
/**
* Initializes an instance of KeyVaultAccessControlClient client.
*
* @param apiVersion Api Version.
*/
KeyVaultAccessControlClientImpl(String apiVersion) {
this(
new HttpPipelineBuilder()
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
.build(),
JacksonAdapter.createDefaultSerializerAdapter());
JacksonAdapter.createDefaultSerializerAdapter(),
apiVersion);
}

/**
* Initializes an instance of KeyVaultAccessControlClient client.
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param apiVersion Api Version.
*/
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline) {
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter());
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline, String apiVersion) {
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), apiVersion);
}

/**
* Initializes an instance of KeyVaultAccessControlClient client.
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param serializerAdapter The serializer to serialize an object into a string.
* @param apiVersion Api Version.
*/
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter) {
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String apiVersion) {
this.httpPipeline = httpPipeline;
this.serializerAdapter = serializerAdapter;
this.apiVersion = "7.2-preview";
this.apiVersion = apiVersion;
this.roleDefinitions = new RoleDefinitionsImpl(this);
this.roleAssignments = new RoleAssignmentsImpl(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,54 @@
package com.azure.security.keyvault.administration.implementation;

import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.Configuration;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** A builder for creating a new instance of the KeyVaultAccessControlClient type. */
@ServiceClientBuilder(serviceClients = {KeyVaultAccessControlClientImpl.class})
public final class KeyVaultAccessControlClientImplBuilder {
private static final String SDK_NAME = "name";

private static final String SDK_VERSION = "version";

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

/** Create an instance of the KeyVaultAccessControlClientImplBuilder. */
public KeyVaultAccessControlClientImplBuilder() {
this.pipelinePolicies = new ArrayList<>();
}

/*
* Api Version
*/
private String apiVersion;

/**
* Sets Api Version.
*
* @param apiVersion the apiVersion value.
* @return the KeyVaultAccessControlClientImplBuilder.
*/
public KeyVaultAccessControlClientImplBuilder apiVersion(String apiVersion) {
this.apiVersion = apiVersion;
return this;
}

/*
* The HTTP pipeline to send requests through
*/
Expand Down Expand Up @@ -48,22 +85,130 @@ public KeyVaultAccessControlClientImplBuilder serializerAdapter(SerializerAdapte
return this;
}

/*
* The HTTP client used to send the request.
*/
private HttpClient httpClient;

/**
* Sets The HTTP client used to send the request.
*
* @param httpClient the httpClient value.
* @return the KeyVaultAccessControlClientImplBuilder.
*/
public KeyVaultAccessControlClientImplBuilder httpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}

/*
* The configuration store that is used during construction of the service
* client.
*/
private Configuration configuration;

/**
* Sets The configuration store that is used during construction of the service client.
*
* @param configuration the configuration value.
* @return the KeyVaultAccessControlClientImplBuilder.
*/
public KeyVaultAccessControlClientImplBuilder configuration(Configuration configuration) {
this.configuration = configuration;
return this;
}

/*
* The logging configuration for HTTP requests and responses.
*/
private HttpLogOptions httpLogOptions;

/**
* Sets The logging configuration for HTTP requests and responses.
*
* @param httpLogOptions the httpLogOptions value.
* @return the KeyVaultAccessControlClientImplBuilder.
*/
public KeyVaultAccessControlClientImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
this.httpLogOptions = httpLogOptions;
return this;
}

/*
* The retry policy that will attempt to retry failed requests, if
* applicable.
*/
private RetryPolicy retryPolicy;

/**
* Sets The retry policy that will attempt to retry failed requests, if applicable.
*
* @param retryPolicy the retryPolicy value.
* @return the KeyVaultAccessControlClientImplBuilder.
*/
public KeyVaultAccessControlClientImplBuilder retryPolicy(RetryPolicy retryPolicy) {
this.retryPolicy = retryPolicy;
return this;
}

/*
* The list of Http pipeline policies to add.
*/
private final List<HttpPipelinePolicy> pipelinePolicies;

/**
* Adds a custom Http pipeline policy.
*
* @param customPolicy The custom Http pipeline policy to add.
* @return the KeyVaultAccessControlClientImplBuilder.
*/
public KeyVaultAccessControlClientImplBuilder addPolicy(HttpPipelinePolicy customPolicy) {
pipelinePolicies.add(customPolicy);
return this;
}

/**
* Builds an instance of KeyVaultAccessControlClientImpl with the provided parameters.
*
* @return an instance of KeyVaultAccessControlClientImpl.
*/
public KeyVaultAccessControlClientImpl buildClient() {
if (apiVersion == null) {
this.apiVersion = "7.2";
}
if (pipeline == null) {
this.pipeline =
new HttpPipelineBuilder()
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
.build();
this.pipeline = createHttpPipeline();
}
if (serializerAdapter == null) {
this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter();
}
KeyVaultAccessControlClientImpl client = new KeyVaultAccessControlClientImpl(pipeline, serializerAdapter);
KeyVaultAccessControlClientImpl client =
new KeyVaultAccessControlClientImpl(pipeline, serializerAdapter, apiVersion);
return client;
}

private HttpPipeline createHttpPipeline() {
Configuration buildConfiguration =
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
if (httpLogOptions == null) {
httpLogOptions = new HttpLogOptions();
}
List<HttpPipelinePolicy> policies = new ArrayList<>();
String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
policies.add(
new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy);
policies.add(new CookiePolicy());
policies.addAll(this.pipelinePolicies);
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
HttpPipeline httpPipeline =
new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient)
.build();
return httpPipeline;
}
}
Loading

0 comments on commit 7641fcd

Please sign in to comment.