Skip to content

Commit 0dc762a

Browse files
authored
Applied arch board feedback for Key Vault Administration (Azure#17284)
* Removed exposure of implementation package and any usage of KeyVaultErrorException from public APIs. * Renamed KeyVaultRoleAssignmentScope to KeyVaultRoleScope. Changed the name type from UUID to String in role assignment APIs. * Renamed APIs for re-hydrating LROs. * Added ServiceVersion support in the clients and their builders. Internally this will not be used until some changes in the code generation tool are applied. * Annotated read-only classes with @immutable. Added the "allowed" prefix to some KeyVaultPermission properties. Change the type of `startTime` and `endTime` in KeyVaultLongRunningOperation from Long to OffsetDateTime. * Changed the KeyVaultRoleScope enum from using URI to URL and added an overload that takes a the string representation of a URL. * Added overloads that allow passing a custom polling interval to LROs. * Removed the use of KeyVaultRoleAssignmentProperties in clients' public APIs in favor of using the `roleDefinitionId` and `servicePrincipalId` values directly. * Fixed Javadoc and test issues. * Fixed checkstyle issues. * Applied arch board meeting and PR feedback: * Renamed parameters containing the 'Uri' suffix to 'Url'. * Changed the type of `startTime` and `endTime` in the constructor of KeyVaultLongRunningOperation and its subtypes from `Long` to `OffsetDateTime`. * Removed unnecessary versions from KeyVaultAdministrationServiceVersion. Additional changes: * Renamed `scope` in KeyVaultRoleAssignment to `roleScope` to align with the access client APIs. * Polished Javadoc * Removed APIs to refresh LROs based on PR feedback. * Removed unused import in KeyVaultBackupAsyncClientTest.
1 parent f3676ac commit 0dc762a

31 files changed

+590
-1208
lines changed

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

Lines changed: 134 additions & 141 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: 67 additions & 65 deletions
Large diffs are not rendered by default.

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public final class KeyVaultAccessControlClientBuilder {
7474
private RetryPolicy retryPolicy;
7575
private Configuration configuration;
7676
private ClientOptions clientOptions;
77+
private KeyVaultAdministrationServiceVersion serviceVersion;
7778

7879
/**
7980
* Creates a {@link KeyVaultAccessControlClientBuilder} instance that is able to configure and construct
@@ -125,8 +126,10 @@ public KeyVaultAccessControlAsyncClient buildAsyncClient() {
125126
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)));
126127
}
127128

129+
serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest();
130+
128131
if (pipeline != null) {
129-
return new KeyVaultAccessControlAsyncClient(vaultUrl, pipeline);
132+
return new KeyVaultAccessControlAsyncClient(vaultUrl, pipeline, serviceVersion);
130133
}
131134

132135
// Closest to API goes first, closest to wire goes last.
@@ -158,7 +161,7 @@ public KeyVaultAccessControlAsyncClient buildAsyncClient() {
158161
.httpClient(httpClient)
159162
.build();
160163

161-
return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline);
164+
return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline, serviceVersion);
162165
}
163166

164167
/**
@@ -295,13 +298,28 @@ public KeyVaultAccessControlClientBuilder retryPolicy(RetryPolicy retryPolicy) {
295298
* <p>More About <a href="https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy">Azure Core: Telemetry policy</a>
296299
*
297300
* @param clientOptions the {@link ClientOptions} to be set on the client.
298-
* @return The updated KeyVaultAccessControlClientBuilder object.
301+
* @return The updated {@link KeyVaultAccessControlClientBuilder} object.
299302
*/
300303
public KeyVaultAccessControlClientBuilder clientOptions(ClientOptions clientOptions) {
301304
this.clientOptions = clientOptions;
302305
return this;
303306
}
304307

308+
/**
309+
* Sets the {@link KeyVaultAdministrationServiceVersion} that is used when making API requests.
310+
* <p>
311+
* If a service version is not provided, the service version that will be used will be the latest known service
312+
* version based on the version of the client library being used. If no service version is specified, updating to a
313+
* newer version the client library will have the result of potentially moving to a newer service version.
314+
*
315+
* @param serviceVersion {@link KeyVaultAdministrationServiceVersion} of the service API used when making requests.
316+
* @return The updated {@link KeyVaultAccessControlClientBuilder} object.
317+
*/
318+
public KeyVaultAccessControlClientBuilder serviceVersion(KeyVaultAdministrationServiceVersion serviceVersion) {
319+
this.serviceVersion = serviceVersion;
320+
return this;
321+
}
322+
305323
private URL getBuildEndpoint(Configuration configuration) {
306324
if (vaultUrl != null) {
307325
return vaultUrl;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.security.keyvault.administration;
5+
6+
import com.azure.core.util.ServiceVersion;
7+
8+
/**
9+
* The versions of Azure Key Vault Administration service supported by this client library.
10+
*/
11+
public enum KeyVaultAdministrationServiceVersion implements ServiceVersion {
12+
V7_2_PREVIEW("7.2-preview");
13+
14+
private final String version;
15+
16+
KeyVaultAdministrationServiceVersion(String version) {
17+
this.version = version;
18+
}
19+
20+
@Override
21+
public String getVersion() {
22+
return this.version;
23+
}
24+
25+
/**
26+
* Gets the latest service version supported by this client library.
27+
*
28+
* @return The latest {@link KeyVaultAdministrationServiceVersion}.
29+
*/
30+
public static KeyVaultAdministrationServiceVersion getLatest() {
31+
return V7_2_PREVIEW;
32+
}
33+
}

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

Lines changed: 94 additions & 116 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: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.azure.core.annotation.ReturnType;
77
import com.azure.core.annotation.ServiceClient;
88
import com.azure.core.annotation.ServiceMethod;
9-
import com.azure.core.util.polling.PollerFlux;
109
import com.azure.core.util.polling.SyncPoller;
1110
import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation;
1211
import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation;
@@ -66,26 +65,14 @@ public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorag
6665
return asyncClient.beginBackup(blobStorageUrl, sasToken, pollingInterval).getSyncPoller();
6766
}
6867

69-
/**
70-
* Gets a pending {@link KeyVaultBackupOperation backup operation} from the Key Vault.
71-
*
72-
* @param jobId The operation identifier.
73-
* @throws NullPointerException if the {@code jobId} is null.
74-
* @return A {@link SyncPoller} to poll on the backup operation status.
75-
*/
76-
@ServiceMethod(returns = ReturnType.SINGLE)
77-
public SyncPoller<KeyVaultBackupOperation, String> getBackupOperation(String jobId) {
78-
return asyncClient.getBackupOperation(jobId).getSyncPoller();
79-
}
80-
8168
/**
8269
* Initiates a full restore of the Key Vault.
8370
*
8471
* @param backupFolderUrl The URL for the Blob Storage resource where the backup is located, including the path to
8572
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
8673
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
8774
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
88-
* @return A {@link SyncPoller} polling on the {@link KeyVaultRestoreOperation backup operation} status.
75+
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
8976
* @throws NullPointerException if the {@code backupFolderUrl} or {@code sasToken} are {@code null}.
9077
*/
9178
@ServiceMethod(returns = ReturnType.SINGLE)
@@ -101,26 +88,14 @@ public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String backupFold
10188
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
10289
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
10390
* @param pollingInterval The interval at which the operation status will be polled for.
104-
* @return A {@link SyncPoller} polling on the {@link KeyVaultRestoreOperation backup operation} status.
91+
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
10592
* @throws NullPointerException if the {@code backupFolderUrl} or {@code sasToken} are {@code null}.
10693
*/
10794
@ServiceMethod(returns = ReturnType.SINGLE)
10895
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String backupFolderUrl, String sasToken, Duration pollingInterval) {
10996
return asyncClient.beginRestore(backupFolderUrl, sasToken, pollingInterval).getSyncPoller();
11097
}
11198

112-
/**
113-
* Gets a pending {@link KeyVaultRestoreOperation full or selective restore operation} from the Key Vault.
114-
*
115-
* @param jobId The operation identifier.
116-
* @throws NullPointerException if the {@code jobId} is null.
117-
* @return A {@link SyncPoller} to poll on the restore operation status.
118-
*/
119-
@ServiceMethod(returns = ReturnType.SINGLE)
120-
public SyncPoller<KeyVaultRestoreOperation, Void> getRestoreOperation(String jobId) {
121-
return asyncClient.getRestoreOperation(jobId).getSyncPoller();
122-
}
123-
12499
/**
125100
* Restores all versions of a given key using the supplied SAS token pointing to a previously stored Azure Blob
126101
* storage backup folder.
@@ -130,7 +105,7 @@ public SyncPoller<KeyVaultRestoreOperation, Void> getRestoreOperation(String job
130105
* the blob container where the backup resides. This would be the exact value that is returned as the result of a
131106
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
132107
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
133-
* @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status.
108+
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
134109
* @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code
135110
* null}.
136111
*/
@@ -149,7 +124,7 @@ public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String k
149124
* backup operation. An example of such a URL may look like the following: https://contoso.blob.core.windows.net/backup/mhsm-contoso-2020090117323313.
150125
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
151126
* @param pollingInterval The interval at which the operation status will be polled for.
152-
* @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status.
127+
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
153128
* @throws NullPointerException if the {@code keyName}, {@code backupFolderUrl} or {@code sasToken} are {@code
154129
* null}.
155130
*/

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public final class KeyVaultBackupClientBuilder {
7373
private RetryPolicy retryPolicy;
7474
private Configuration configuration;
7575
private ClientOptions clientOptions;
76+
private KeyVaultAdministrationServiceVersion serviceVersion;
7677

7778
/**
7879
* Creates a {@link KeyVaultBackupClientBuilder} instance that is able to configure and construct instances of
@@ -124,8 +125,10 @@ public KeyVaultBackupAsyncClient buildAsyncClient() {
124125
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)));
125126
}
126127

128+
serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest();
129+
127130
if (pipeline != null) {
128-
return new KeyVaultBackupAsyncClient(vaultUrl, pipeline);
131+
return new KeyVaultBackupAsyncClient(vaultUrl, pipeline, serviceVersion);
129132
}
130133

131134
// Closest to API goes first, closest to wire goes last.
@@ -157,7 +160,7 @@ public KeyVaultBackupAsyncClient buildAsyncClient() {
157160
.httpClient(httpClient)
158161
.build();
159162

160-
return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline);
163+
return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline, serviceVersion);
161164
}
162165

163166
/**
@@ -295,13 +298,28 @@ public KeyVaultBackupClientBuilder retryPolicy(RetryPolicy retryPolicy) {
295298
* <p>More About <a href="https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy">Azure Core: Telemetry policy</a>
296299
*
297300
* @param clientOptions the {@link ClientOptions} to be set on the client.
298-
* @return The updated KeyVaultBackupClientBuilder object.
301+
* @return The updated {@link KeyVaultBackupClientBuilder} object.
299302
*/
300303
public KeyVaultBackupClientBuilder clientOptions(ClientOptions clientOptions) {
301304
this.clientOptions = clientOptions;
302305
return this;
303306
}
304307

308+
/**
309+
* Sets the {@link KeyVaultAdministrationServiceVersion} that is used when making API requests.
310+
* <p>
311+
* If a service version is not provided, the service version that will be used will be the latest known service
312+
* version based on the version of the client library being used. If no service version is specified, updating to a
313+
* newer version the client library will have the result of potentially moving to a newer service version.
314+
*
315+
* @param serviceVersion {@link KeyVaultAdministrationServiceVersion} of the service API used when making requests.
316+
* @return The updated {@link KeyVaultBackupClientBuilder} object.
317+
*/
318+
public KeyVaultBackupClientBuilder serviceVersion(KeyVaultAdministrationServiceVersion serviceVersion) {
319+
this.serviceVersion = serviceVersion;
320+
return this;
321+
}
322+
305323
private URL getBuildEndpoint(Configuration configuration) {
306324
if (vaultUrl != null) {
307325
return vaultUrl;

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,39 @@
33

44
package com.azure.security.keyvault.administration.models;
55

6+
import com.azure.core.annotation.Immutable;
7+
8+
import java.time.OffsetDateTime;
9+
610
/**
711
* A class that contains the details of a backup operation.
812
*/
13+
@Immutable
914
public final class KeyVaultBackupOperation extends KeyVaultLongRunningOperation {
10-
private final String azureStorageBlobContainerUri;
15+
private final String azureStorageBlobContainerUrl;
1116

1217
/**
1318
* Creates an object containing the details of a {@link KeyVaultBackupOperation}.
1419
*
1520
* @param status Status of the {@link KeyVaultBackupOperation}.
1621
* @param statusDetails The status details of the {@link KeyVaultBackupOperation}.
1722
* @param error Error encountered, if any, during the {@link KeyVaultBackupOperation}.
18-
* @param startTime The start time of the {@link KeyVaultBackupOperation} in UTC.
19-
* @param endTime The end time of the {@link KeyVaultBackupOperation} in UTC.
23+
* @param startTime The start time of the {@link KeyVaultBackupOperation}.
24+
* @param endTime The end time of the {@link KeyVaultBackupOperation}.
2025
* @param jobId Identifier for the full {@link KeyVaultBackupOperation}.
21-
* @param azureStorageBlobContainerUri The Azure blob storage container URI which contains the backup.
26+
* @param azureStorageBlobContainerUrl The Azure blob storage container URI which contains the backup.
2227
*/
23-
public KeyVaultBackupOperation(String status, String statusDetails, KeyVaultError error, String jobId, Long startTime, Long endTime, String azureStorageBlobContainerUri) {
28+
public KeyVaultBackupOperation(String status, String statusDetails, KeyVaultError error, String jobId, OffsetDateTime startTime, OffsetDateTime endTime, String azureStorageBlobContainerUrl) {
2429
super(status, statusDetails, error, jobId, startTime, endTime);
25-
this.azureStorageBlobContainerUri = azureStorageBlobContainerUri;
30+
this.azureStorageBlobContainerUrl = azureStorageBlobContainerUrl;
2631
}
2732

2833
/**
2934
* Get the Azure Blob Storage container URI where the backup resides.
3035
*
3136
* @return The backup URI in {@link String} form.
3237
*/
33-
public String getAzureStorageBlobContainerUri() {
34-
return azureStorageBlobContainerUri;
38+
public String getAzureStorageBlobContainerUrl() {
39+
return azureStorageBlobContainerUrl;
3540
}
3641
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44
package com.azure.security.keyvault.administration.models;
55

6+
import com.azure.core.annotation.Immutable;
7+
68
/**
79
* A class that represents an error occurred in a Key Vault operation.
810
*/
11+
@Immutable
912
public final class KeyVaultError {
1013
private final String code;
1114
private final String message;

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@
33

44
package com.azure.security.keyvault.administration.models;
55

6+
import com.azure.core.annotation.Immutable;
7+
8+
import java.time.OffsetDateTime;
9+
610
/**
711
* A class that contains the details of a long running operation.
812
*/
13+
@Immutable
914
public class KeyVaultLongRunningOperation {
1015
private final String status;
1116
private final String statusDetails;
1217
private final KeyVaultError error;
1318
private final String jobId;
14-
private final Long startTime;
15-
private final Long endTime;
19+
private final OffsetDateTime startTime;
20+
private final OffsetDateTime endTime;
1621

1722
/**
1823
* Creates an object containing the details of a {@link KeyVaultLongRunningOperation}.
1924
*
2025
* @param status Status of the {@link KeyVaultLongRunningOperation}.
2126
* @param statusDetails The status details of the {@link KeyVaultLongRunningOperation}.
2227
* @param error Error encountered, if any, during the {@link KeyVaultLongRunningOperation}.
23-
* @param startTime The start time of the {@link KeyVaultLongRunningOperation} in UTC.
24-
* @param endTime The end time of the {@link KeyVaultLongRunningOperation} in UTC.
28+
* @param startTime The start time of the {@link KeyVaultLongRunningOperation}.
29+
* @param endTime The end time of the {@link KeyVaultLongRunningOperation}.
2530
* @param jobId Identifier for the full {@link KeyVaultLongRunningOperation}.
2631
*/
27-
public KeyVaultLongRunningOperation(String status, String statusDetails, KeyVaultError error, String jobId, Long startTime, Long endTime) {
32+
public KeyVaultLongRunningOperation(String status, String statusDetails, KeyVaultError error, String jobId, OffsetDateTime startTime, OffsetDateTime endTime) {
2833
this.status = status;
2934
this.statusDetails = statusDetails;
3035
this.error = error;
@@ -61,20 +66,20 @@ public KeyVaultError getError() {
6166
}
6267

6368
/**
64-
* Get the start time of the {@link KeyVaultLongRunningOperation} in UTC.
69+
* Get the start time of the {@link KeyVaultLongRunningOperation}.
6570
*
66-
* @return The start time in UTC.
71+
* @return The start time.
6772
*/
68-
public Long getStartTime() {
73+
public OffsetDateTime getStartTime() {
6974
return startTime;
7075
}
7176

7277
/**
73-
* Get the end time of the {@link KeyVaultLongRunningOperation} in UTC.
78+
* Get the end time of the {@link KeyVaultLongRunningOperation}.
7479
*
75-
* @return The end time in UTC.
80+
* @return The end time.
7681
*/
77-
public Long getEndTime() {
82+
public OffsetDateTime getEndTime() {
7883
return endTime;
7984
}
8085

0 commit comments

Comments
 (0)