Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied arch board feedback for Key Vault Administration #17284

Merged
merged 13 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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 @@ -74,6 +74,7 @@ public final class KeyVaultAccessControlClientBuilder {
private RetryPolicy retryPolicy;
private Configuration configuration;
private ClientOptions clientOptions;
private KeyVaultAdministrationServiceVersion serviceVersion;

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

serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest();

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

// Closest to API goes first, closest to wire goes last.
Expand Down Expand Up @@ -158,7 +161,7 @@ public KeyVaultAccessControlAsyncClient buildAsyncClient() {
.httpClient(httpClient)
.build();

return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline);
return new KeyVaultAccessControlAsyncClient(vaultUrl, buildPipeline, serviceVersion);
}

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

/**
* Sets the {@link KeyVaultAdministrationServiceVersion} that is used when making API requests.
* <p>
* If a service version is not provided, the service version that will be used will be the latest known service
* version based on the version of the client library being used. If no service version is specified, updating to a
* newer version the client library will have the result of potentially moving to a newer service version.
*
* @param serviceVersion {@link KeyVaultAdministrationServiceVersion} of the service API used when making requests.
* @return The updated {@link KeyVaultAccessControlClientBuilder} object.
*/
public KeyVaultAccessControlClientBuilder serviceVersion(KeyVaultAdministrationServiceVersion serviceVersion) {
this.serviceVersion = serviceVersion;
return this;
}

private URL getBuildEndpoint(Configuration configuration) {
if (vaultUrl != null) {
return vaultUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.security.keyvault.administration;

import com.azure.core.util.ServiceVersion;

/**
* The versions of Azure Key Vault Administration service supported by this client library.
*/
public enum KeyVaultAdministrationServiceVersion implements ServiceVersion {
V7_0("7.0"),
V7_1("7.1"),
vcolin7 marked this conversation as resolved.
Show resolved Hide resolved
V7_2_PREVIEW("7.2-preview");

private final String version;

KeyVaultAdministrationServiceVersion(String version) {
this.version = version;
}

@Override
public String getVersion() {
return this.version;
}

/**
* Gets the latest service version supported by this client library.
*
* @return The latest {@link KeyVaultAdministrationServiceVersion}.
*/
public static KeyVaultAdministrationServiceVersion getLatest() {
return V7_2_PREVIEW;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation;
import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation;
Expand Down Expand Up @@ -71,11 +70,24 @@ public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorag
*
* @param jobId The operation identifier.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} to poll on the backup operation status.
* @return A {@link SyncPoller} polling on the {@link KeyVaultBackupOperation backup operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultBackupOperation, String> getBackupOperation(String jobId) {
return asyncClient.getBackupOperation(jobId).getSyncPoller();
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String jobId) {
return asyncClient.beginBackup(jobId).getSyncPoller();
}

/**
* Gets a pending {@link KeyVaultBackupOperation backup operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @param pollingInterval The interval at which the operation status will be polled for.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} polling on the {@link KeyVaultBackupOperation backup operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String jobId, Duration pollingInterval) {
return asyncClient.beginBackup(jobId, pollingInterval).getSyncPoller();
}

/**
Expand All @@ -85,7 +97,7 @@ public SyncPoller<KeyVaultBackupOperation, String> getBackupOperation(String job
* 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.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @return A {@link SyncPoller} polling on the {@link KeyVaultRestoreOperation backup operation} status.
* @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}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Expand All @@ -101,7 +113,7 @@ public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String backupFold
* 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} polling on the {@link KeyVaultRestoreOperation backup operation} status.
* @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}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Expand All @@ -110,15 +122,28 @@ public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String backupFold
}

/**
* Gets a pending {@link KeyVaultRestoreOperation full or selective restore operation} from the Key Vault.
* Gets a pending {@link KeyVaultRestoreOperation full restore operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String jobId) {
return asyncClient.beginRestore(jobId).getSyncPoller();
}

/**
* Gets a pending {@link KeyVaultRestoreOperation full restore operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @param pollingInterval The interval at which the operation status will be polled for.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} to poll on the restore operation status.
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultRestoreOperation, Void> getRestoreOperation(String jobId) {
return asyncClient.getRestoreOperation(jobId).getSyncPoller();
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String jobId, Duration pollingInterval) {
return asyncClient.beginRestore(jobId, pollingInterval).getSyncPoller();
}

/**
Expand All @@ -130,7 +155,7 @@ public SyncPoller<KeyVaultRestoreOperation, Void> getRestoreOperation(String job
* 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.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status.
* @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
* null}.
*/
Expand All @@ -149,12 +174,37 @@ public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String k
* 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 PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status.
* @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
* null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String backupFolderUrl, String sasToken, Duration pollingInterval) {
return asyncClient.beginSelectiveRestore(keyName, backupFolderUrl, sasToken, pollingInterval).getSyncPoller();
}

/**
* Gets a pending {@link KeyVaultRestoreOperation selective restore operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String jobId) {
return asyncClient.beginSelectiveRestore(jobId).getSyncPoller();
}

/**
* Gets a pending {@link KeyVaultRestoreOperation selective restore operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @param pollingInterval The interval at which the operation status will be polled for.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} to poll on the {@link KeyVaultRestoreOperation restore operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String jobId, Duration pollingInterval) {
return asyncClient.beginSelectiveRestore(jobId, pollingInterval).getSyncPoller();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public final class KeyVaultBackupClientBuilder {
private RetryPolicy retryPolicy;
private Configuration configuration;
private ClientOptions clientOptions;
private KeyVaultAdministrationServiceVersion serviceVersion;

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

serviceVersion = serviceVersion != null ? serviceVersion : KeyVaultAdministrationServiceVersion.getLatest();

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

// Closest to API goes first, closest to wire goes last.
Expand Down Expand Up @@ -157,7 +160,7 @@ public KeyVaultBackupAsyncClient buildAsyncClient() {
.httpClient(httpClient)
.build();

return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline);
return new KeyVaultBackupAsyncClient(vaultUrl, buildPipeline, serviceVersion);
}

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

/**
* Sets the {@link KeyVaultAdministrationServiceVersion} that is used when making API requests.
* <p>
* If a service version is not provided, the service version that will be used will be the latest known service
* version based on the version of the client library being used. If no service version is specified, updating to a
* newer version the client library will have the result of potentially moving to a newer service version.
*
* @param serviceVersion {@link KeyVaultAdministrationServiceVersion} of the service API used when making requests.
* @return The updated {@link KeyVaultBackupClientBuilder} object.
*/
public KeyVaultBackupClientBuilder serviceVersion(KeyVaultAdministrationServiceVersion serviceVersion) {
this.serviceVersion = serviceVersion;
return this;
}

private URL getBuildEndpoint(Configuration configuration) {
if (vaultUrl != null) {
return vaultUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

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

import com.azure.core.annotation.Immutable;

/**
* A class that contains the details of a backup operation.
*/
@Immutable
public final class KeyVaultBackupOperation extends KeyVaultLongRunningOperation {
private final String azureStorageBlobContainerUri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

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

import com.azure.core.annotation.Immutable;

/**
* A class that represents an error occurred in a Key Vault operation.
*/
@Immutable
public final class KeyVaultError {
private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@

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

import com.azure.core.annotation.Immutable;

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

/**
* A class that contains the details of a long running operation.
*/
@Immutable
public class KeyVaultLongRunningOperation {
private final String status;
private final String statusDetails;
private final KeyVaultError error;
private final String jobId;
private final Long startTime;
private final Long endTime;
private final OffsetDateTime startTime;
private final OffsetDateTime endTime;

/**
* Creates an object containing the details of a {@link KeyVaultLongRunningOperation}.
*
* @param status Status of the {@link KeyVaultLongRunningOperation}.
* @param statusDetails The status details of the {@link KeyVaultLongRunningOperation}.
* @param error Error encountered, if any, during the {@link KeyVaultLongRunningOperation}.
* @param startTime The start time of the {@link KeyVaultLongRunningOperation} in UTC.
* @param endTime The end time of the {@link KeyVaultLongRunningOperation} in UTC.
* @param startTime The start time of the {@link KeyVaultLongRunningOperation} in seconds for the UTC timezone.
* @param endTime The end time of the {@link KeyVaultLongRunningOperation} in seconds for the UTC timezone.
* @param jobId Identifier for the full {@link KeyVaultLongRunningOperation}.
*/
public KeyVaultLongRunningOperation(String status, String statusDetails, KeyVaultError error, String jobId, Long startTime, Long endTime) {
this.status = status;
this.statusDetails = statusDetails;
this.error = error;
this.startTime = startTime;
this.endTime = endTime;
this.startTime = startTime == null ? null
: OffsetDateTime.ofInstant(Instant.ofEpochSecond(startTime), ZoneOffset.UTC);
this.endTime = endTime == null ? null
: OffsetDateTime.ofInstant(Instant.ofEpochSecond(endTime), ZoneOffset.UTC);
this.jobId = jobId;
}

Expand Down Expand Up @@ -65,7 +74,7 @@ public KeyVaultError getError() {
*
* @return The start time in UTC.
*/
public Long getStartTime() {
public OffsetDateTime getStartTime() {
return startTime;
}

Expand All @@ -74,7 +83,7 @@ public Long getStartTime() {
*
* @return The end time in UTC.
*/
public Long getEndTime() {
public OffsetDateTime getEndTime() {
return endTime;
}

Expand Down
Loading