Skip to content

Commit 7641fcd

Browse files
authored
Added support for creating, updating, retrieving and deleting role definitions 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.
1 parent 238f4c8 commit 7641fcd

File tree

85 files changed

+4848
-968
lines changed

Some content is hidden

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

85 files changed

+4848
-968
lines changed

sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlAsyncClient.java

Lines changed: 525 additions & 107 deletions
Large diffs are not rendered by default.

sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultAccessControlClient.java

Lines changed: 197 additions & 12 deletions
Large diffs are not rendered by default.

sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupAsyncClient.java

Lines changed: 136 additions & 80 deletions
Large diffs are not rendered by default.

sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/KeyVaultBackupClient.java

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.azure.core.annotation.ServiceMethod;
99
import com.azure.core.util.polling.SyncPoller;
1010
import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation;
11+
import com.azure.security.keyvault.administration.models.KeyVaultAdministrationException;
1112
import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation;
1213

1314
import java.time.Duration;
@@ -43,8 +44,11 @@ public String getVaultUrl() {
4344
*
4445
* @param blobStorageUrl The URL for the Blob Storage resource where the backup will be located.
4546
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
47+
*
4648
* @return A {@link SyncPoller} polling on the {@link KeyVaultBackupOperation backup operation} status.
47-
* @throws NullPointerException if the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
49+
*
50+
* @throws KeyVaultAdministrationException If the given {@code blobStorageUrl} or {@code sasToken} are invalid.
51+
* @throws NullPointerException If the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
4852
*/
4953
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
5054
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken) {
@@ -57,79 +61,102 @@ public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorag
5761
* @param blobStorageUrl The URL for the Blob Storage resource where the backup will be located.
5862
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
5963
* @param pollingInterval The interval at which the operation status will be polled for.
64+
*
6065
* @return A {@link SyncPoller} polling on the {@link KeyVaultBackupOperation backup operation} status.
61-
* @throws NullPointerException if the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
66+
*
67+
* @throws KeyVaultAdministrationException If the given {@code blobStorageUrl} or {@code sasToken} are invalid.
68+
* @throws NullPointerException If the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
6269
*/
6370
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
64-
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken, Duration pollingInterval) {
71+
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken,
72+
Duration pollingInterval) {
6573
return asyncClient.beginBackup(blobStorageUrl, sasToken, pollingInterval).getSyncPoller();
6674
}
6775

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

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

99116
/**
100117
* Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob
101118
* storage backup folder.
102119
*
103120
* @param keyName The name of the key to be restored.
104-
* @param backupFolderUrl The URL for the Blob Storage resource where the backup is located, including the path to
121+
* @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to
105122
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
106-
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
123+
* backup operation. An example of such a URL may look like the following:
124+
* https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
107125
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
126+
*
108127
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
109-
* @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code
128+
*
129+
* @throws KeyVaultAdministrationException If the given {@code folderUrl} or {@code sasToken} are invalid.
130+
* @throws NullPointerException If the {@code keyName}, {@code folderUrl} or {@code sasToken} are {@code
110131
* null}.
111132
*/
112133
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
113-
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String backupFolderUrl, String sasToken) {
114-
return asyncClient.beginSelectiveRestore(keyName, backupFolderUrl, sasToken).getSyncPoller();
134+
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String folderUrl,
135+
String sasToken) {
136+
return asyncClient.beginSelectiveRestore(keyName, folderUrl, sasToken).getSyncPoller();
115137
}
116138

117139
/**
118140
* Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob
119141
* storage backup folder.
120142
*
121143
* @param keyName The name of the key to be restored.
122-
* @param backupFolderUrl The URL for the Blob Storage resource where the backup is located, including the path to
144+
* @param folderUrl The URL for the Blob Storage resource where the backup is located, including the path to
123145
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
124-
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
146+
* backup operation. An example of such a URL may look like the following:
147+
* https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
125148
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
126149
* @param pollingInterval The interval at which the operation status will be polled for.
150+
*
127151
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
128-
* @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code
152+
*
153+
* @throws KeyVaultAdministrationException If the given {@code folderUrl} or {@code sasToken} are invalid.
154+
* @throws NullPointerException If the {@code keyName}, {@code folderUrl} or {@code sasToken} are {@code
129155
* null}.
130156
*/
131157
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
132-
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String backupFolderUrl, String sasToken, Duration pollingInterval) {
133-
return asyncClient.beginSelectiveRestore(keyName, backupFolderUrl, sasToken, pollingInterval).getSyncPoller();
158+
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String folderUrl,
159+
String sasToken, Duration pollingInterval) {
160+
return asyncClient.beginSelectiveRestore(keyName, folderUrl, sasToken, pollingInterval).getSyncPoller();
134161
}
135162
}

sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultAccessControlClientImpl.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,41 @@ public RoleAssignmentsImpl getRoleAssignments() {
7474
return this.roleAssignments;
7575
}
7676

77-
/** Initializes an instance of KeyVaultAccessControlClient client. */
78-
KeyVaultAccessControlClientImpl() {
77+
/**
78+
* Initializes an instance of KeyVaultAccessControlClient client.
79+
*
80+
* @param apiVersion Api Version.
81+
*/
82+
KeyVaultAccessControlClientImpl(String apiVersion) {
7983
this(
8084
new HttpPipelineBuilder()
8185
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
8286
.build(),
83-
JacksonAdapter.createDefaultSerializerAdapter());
87+
JacksonAdapter.createDefaultSerializerAdapter(),
88+
apiVersion);
8489
}
8590

8691
/**
8792
* Initializes an instance of KeyVaultAccessControlClient client.
8893
*
8994
* @param httpPipeline The HTTP pipeline to send requests through.
95+
* @param apiVersion Api Version.
9096
*/
91-
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline) {
92-
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter());
97+
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline, String apiVersion) {
98+
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), apiVersion);
9399
}
94100

95101
/**
96102
* Initializes an instance of KeyVaultAccessControlClient client.
97103
*
98104
* @param httpPipeline The HTTP pipeline to send requests through.
99105
* @param serializerAdapter The serializer to serialize an object into a string.
106+
* @param apiVersion Api Version.
100107
*/
101-
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter) {
108+
KeyVaultAccessControlClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String apiVersion) {
102109
this.httpPipeline = httpPipeline;
103110
this.serializerAdapter = serializerAdapter;
104-
this.apiVersion = "7.2-preview";
111+
this.apiVersion = apiVersion;
105112
this.roleDefinitions = new RoleDefinitionsImpl(this);
106113
this.roleAssignments = new RoleAssignmentsImpl(this);
107114
}

sdk/keyvault/azure-security-keyvault-administration/src/main/java/com/azure/security/keyvault/administration/implementation/KeyVaultAccessControlClientImplBuilder.java

Lines changed: 150 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,54 @@
55
package com.azure.security.keyvault.administration.implementation;
66

77
import com.azure.core.annotation.ServiceClientBuilder;
8+
import com.azure.core.http.HttpClient;
89
import com.azure.core.http.HttpPipeline;
910
import com.azure.core.http.HttpPipelineBuilder;
1011
import com.azure.core.http.policy.CookiePolicy;
12+
import com.azure.core.http.policy.HttpLogOptions;
13+
import com.azure.core.http.policy.HttpLoggingPolicy;
14+
import com.azure.core.http.policy.HttpPipelinePolicy;
15+
import com.azure.core.http.policy.HttpPolicyProviders;
1116
import com.azure.core.http.policy.RetryPolicy;
1217
import com.azure.core.http.policy.UserAgentPolicy;
18+
import com.azure.core.util.Configuration;
1319
import com.azure.core.util.serializer.JacksonAdapter;
1420
import com.azure.core.util.serializer.SerializerAdapter;
21+
import java.util.ArrayList;
22+
import java.util.HashMap;
23+
import java.util.List;
24+
import java.util.Map;
1525

1626
/** A builder for creating a new instance of the KeyVaultAccessControlClient type. */
1727
@ServiceClientBuilder(serviceClients = {KeyVaultAccessControlClientImpl.class})
1828
public final class KeyVaultAccessControlClientImplBuilder {
29+
private static final String SDK_NAME = "name";
30+
31+
private static final String SDK_VERSION = "version";
32+
33+
private final Map<String, String> properties = new HashMap<>();
34+
35+
/** Create an instance of the KeyVaultAccessControlClientImplBuilder. */
36+
public KeyVaultAccessControlClientImplBuilder() {
37+
this.pipelinePolicies = new ArrayList<>();
38+
}
39+
40+
/*
41+
* Api Version
42+
*/
43+
private String apiVersion;
44+
45+
/**
46+
* Sets Api Version.
47+
*
48+
* @param apiVersion the apiVersion value.
49+
* @return the KeyVaultAccessControlClientImplBuilder.
50+
*/
51+
public KeyVaultAccessControlClientImplBuilder apiVersion(String apiVersion) {
52+
this.apiVersion = apiVersion;
53+
return this;
54+
}
55+
1956
/*
2057
* The HTTP pipeline to send requests through
2158
*/
@@ -48,22 +85,130 @@ public KeyVaultAccessControlClientImplBuilder serializerAdapter(SerializerAdapte
4885
return this;
4986
}
5087

88+
/*
89+
* The HTTP client used to send the request.
90+
*/
91+
private HttpClient httpClient;
92+
93+
/**
94+
* Sets The HTTP client used to send the request.
95+
*
96+
* @param httpClient the httpClient value.
97+
* @return the KeyVaultAccessControlClientImplBuilder.
98+
*/
99+
public KeyVaultAccessControlClientImplBuilder httpClient(HttpClient httpClient) {
100+
this.httpClient = httpClient;
101+
return this;
102+
}
103+
104+
/*
105+
* The configuration store that is used during construction of the service
106+
* client.
107+
*/
108+
private Configuration configuration;
109+
110+
/**
111+
* Sets The configuration store that is used during construction of the service client.
112+
*
113+
* @param configuration the configuration value.
114+
* @return the KeyVaultAccessControlClientImplBuilder.
115+
*/
116+
public KeyVaultAccessControlClientImplBuilder configuration(Configuration configuration) {
117+
this.configuration = configuration;
118+
return this;
119+
}
120+
121+
/*
122+
* The logging configuration for HTTP requests and responses.
123+
*/
124+
private HttpLogOptions httpLogOptions;
125+
126+
/**
127+
* Sets The logging configuration for HTTP requests and responses.
128+
*
129+
* @param httpLogOptions the httpLogOptions value.
130+
* @return the KeyVaultAccessControlClientImplBuilder.
131+
*/
132+
public KeyVaultAccessControlClientImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
133+
this.httpLogOptions = httpLogOptions;
134+
return this;
135+
}
136+
137+
/*
138+
* The retry policy that will attempt to retry failed requests, if
139+
* applicable.
140+
*/
141+
private RetryPolicy retryPolicy;
142+
143+
/**
144+
* Sets The retry policy that will attempt to retry failed requests, if applicable.
145+
*
146+
* @param retryPolicy the retryPolicy value.
147+
* @return the KeyVaultAccessControlClientImplBuilder.
148+
*/
149+
public KeyVaultAccessControlClientImplBuilder retryPolicy(RetryPolicy retryPolicy) {
150+
this.retryPolicy = retryPolicy;
151+
return this;
152+
}
153+
154+
/*
155+
* The list of Http pipeline policies to add.
156+
*/
157+
private final List<HttpPipelinePolicy> pipelinePolicies;
158+
159+
/**
160+
* Adds a custom Http pipeline policy.
161+
*
162+
* @param customPolicy The custom Http pipeline policy to add.
163+
* @return the KeyVaultAccessControlClientImplBuilder.
164+
*/
165+
public KeyVaultAccessControlClientImplBuilder addPolicy(HttpPipelinePolicy customPolicy) {
166+
pipelinePolicies.add(customPolicy);
167+
return this;
168+
}
169+
51170
/**
52171
* Builds an instance of KeyVaultAccessControlClientImpl with the provided parameters.
53172
*
54173
* @return an instance of KeyVaultAccessControlClientImpl.
55174
*/
56175
public KeyVaultAccessControlClientImpl buildClient() {
176+
if (apiVersion == null) {
177+
this.apiVersion = "7.2";
178+
}
57179
if (pipeline == null) {
58-
this.pipeline =
59-
new HttpPipelineBuilder()
60-
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
61-
.build();
180+
this.pipeline = createHttpPipeline();
62181
}
63182
if (serializerAdapter == null) {
64183
this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter();
65184
}
66-
KeyVaultAccessControlClientImpl client = new KeyVaultAccessControlClientImpl(pipeline, serializerAdapter);
185+
KeyVaultAccessControlClientImpl client =
186+
new KeyVaultAccessControlClientImpl(pipeline, serializerAdapter, apiVersion);
67187
return client;
68188
}
189+
190+
private HttpPipeline createHttpPipeline() {
191+
Configuration buildConfiguration =
192+
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
193+
if (httpLogOptions == null) {
194+
httpLogOptions = new HttpLogOptions();
195+
}
196+
List<HttpPipelinePolicy> policies = new ArrayList<>();
197+
String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
198+
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
199+
policies.add(
200+
new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration));
201+
HttpPolicyProviders.addBeforeRetryPolicies(policies);
202+
policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy);
203+
policies.add(new CookiePolicy());
204+
policies.addAll(this.pipelinePolicies);
205+
HttpPolicyProviders.addAfterRetryPolicies(policies);
206+
policies.add(new HttpLoggingPolicy(httpLogOptions));
207+
HttpPipeline httpPipeline =
208+
new HttpPipelineBuilder()
209+
.policies(policies.toArray(new HttpPipelinePolicy[0]))
210+
.httpClient(httpClient)
211+
.build();
212+
return httpPipeline;
213+
}
69214
}

0 commit comments

Comments
 (0)