Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public final class KeyVaultBackupAsyncClient {
// for more information on Azure resource provider namespaces.
private static final String KEYVAULT_TRACING_NAMESPACE_VALUE = "Microsoft.KeyVault";

private static final Duration DEFAULT_POLLING_INTERVAL = Duration.ofSeconds(1);

/**
* The logger to be used.
*/
Expand All @@ -68,6 +70,10 @@ public final class KeyVaultBackupAsyncClient {
*/
private final String vaultUrl;

Duration getDefaultPollingInterval() {
return DEFAULT_POLLING_INTERVAL;
}

/**
* Package private constructor to be used by {@link KeyVaultBackupClientBuilder}.
*/
Expand Down Expand Up @@ -101,14 +107,28 @@ public String getVaultUrl() {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PollerFlux<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken) {
return beginBackup(blobStorageUrl, sasToken, getDefaultPollingInterval());
}

/**
* Initiates a full backup of the Key Vault.
*
* @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 PollerFlux} polling on the {@link KeyVaultBackupOperation backup operation} status.
* @throws NullPointerException if the {@code blobStorageUrl} or {@code sasToken} are {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PollerFlux<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken, Duration pollingInterval) {
Objects.requireNonNull(blobStorageUrl,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'blobStorageUrl'"));
Objects.requireNonNull(sasToken,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'sasToken'"));

return new PollerFlux<>(Duration.ofSeconds(1),
return new PollerFlux<>(pollingInterval,
backupActivationOperation(blobStorageUrl, sasToken),
backupPollOperation(),
(pollingContext, firstResponse) -> Mono.error(new RuntimeException("Cancellation is not supported")),
Expand Down Expand Up @@ -227,7 +247,7 @@ private static LongRunningOperationStatus toLongRunningOperationStatus(String op
* Gets a pending {@link KeyVaultBackupOperation backup operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @throws KeyVaultErrorException when a backup operation for a given {@code jobId} doesn't exist.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation backup operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Expand Down Expand Up @@ -265,6 +285,22 @@ private Function<PollingContext<KeyVaultBackupOperation>, Mono<PollResponse<KeyV
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PollerFlux<KeyVaultRestoreOperation, Void> beginRestore(String blobStorageUrl, String sasToken, String folderName) {
return beginRestore(blobStorageUrl, sasToken, folderName, getDefaultPollingInterval());
}

/**
* Initiates a full restore of the Key Vault.
*
* @param blobStorageUrl The URL for the Blob Storage resource where the backup is located.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @param folderName The name of the folder containing the backup data to restore.
* @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.
* @throws NullPointerException if the {@code blobStorageUrl}, {@code sasToken} or {@code folderName} are {@code
* null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PollerFlux<KeyVaultRestoreOperation, Void> beginRestore(String blobStorageUrl, String sasToken, String folderName, Duration pollingInterval) {
Objects.requireNonNull(blobStorageUrl,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'blobStorageUrl'"));
Expand All @@ -275,8 +311,7 @@ public PollerFlux<KeyVaultRestoreOperation, Void> beginRestore(String blobStorag
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'folderName'"));


return new PollerFlux<>(Duration.ofSeconds(1),
return new PollerFlux<>(pollingInterval,
restoreActivationOperation(blobStorageUrl, sasToken, folderName),
restorePollOperation(),
(pollingContext, firstResponse) -> Mono.empty(),
Expand Down Expand Up @@ -374,7 +409,7 @@ private static Mono<PollResponse<KeyVaultRestoreOperation>> processRestoreOperat
* Gets a pending {@link KeyVaultRestoreOperation full or selective restore operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @throws KeyVaultErrorException when a restore operation for a given {@code jobId} doesn't exist.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link PollerFlux} polling on the {@link KeyVaultRestoreOperation restore operation} status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Expand Down Expand Up @@ -414,6 +449,24 @@ private Function<PollingContext<KeyVaultRestoreOperation>, Mono<PollResponse<Key
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PollerFlux<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String blobStorageUrl, String sasToken, String folderName) {
return beginSelectiveRestore(keyName, blobStorageUrl, sasToken, folderName, getDefaultPollingInterval());
}

/**
* 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 blobStorageUrl The URL for the Blob Storage resource where the backup is located.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @param folderName The name of the folder containing the backup data to restore.
* @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.
* @throws NullPointerException if the {@code keyName}, {@code blobStorageUrl}, {@code sasToken} or {@code
* folderName} are {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PollerFlux<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String blobStorageUrl, String sasToken, String folderName, Duration pollingInterval) {
Objects.requireNonNull(keyName,
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'keyName'"));
Expand All @@ -427,7 +480,7 @@ public PollerFlux<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String k
String.format(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.PARAMETER_REQUIRED),
"'folderName'"));

return new PollerFlux<>(Duration.ofSeconds(1),
return new PollerFlux<>(pollingInterval,
selectiveRestoreActivationOperation(keyName, blobStorageUrl, sasToken, folderName),
selectiveRestorePollOperation(),
(pollingContext, firstResponse) -> Mono.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
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.implementation.models.KeyVaultErrorException;
import com.azure.security.keyvault.administration.models.KeyVaultBackupOperation;
import com.azure.security.keyvault.administration.models.KeyVaultRestoreOperation;

import java.time.Duration;

/**
* The {@link KeyVaultBackupClient} provides synchronous methods to perform full backup and restore of an Azure Key
* Vault.
Expand Down Expand Up @@ -51,11 +52,25 @@ public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorag
return asyncClient.beginBackup(blobStorageUrl, sasToken).getSyncPoller();
}

/**
* Initiates a full backup of the Key Vault.
*
* @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}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultBackupOperation, String> beginBackup(String blobStorageUrl, String sasToken, Duration pollingInterval) {
return asyncClient.beginBackup(blobStorageUrl, sasToken, pollingInterval).getSyncPoller();
}

/**
* Gets a pending {@link KeyVaultBackupOperation backup operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @throws KeyVaultErrorException when a backup operation for a given {@code jobId} doesn't exist.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} to poll on the backup operation status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Expand All @@ -78,11 +93,27 @@ public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String blobStorag
return asyncClient.beginRestore(blobStorageUrl, sasToken, folderName).getSyncPoller();
}

/**
* Initiates a full restore of the Key Vault.
*
* @param blobStorageUrl The URL for the Blob Storage resource where the backup is located.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @param folderName The name of the folder containing the backup data to restore.
* @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.
* @throws NullPointerException if the {@code blobStorageUrl}, {@code sasToken} or {@code folderName} are {@code
* null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultRestoreOperation, Void> beginRestore(String blobStorageUrl, String sasToken, String folderName, Duration pollingInterval) {
return asyncClient.beginRestore(blobStorageUrl, sasToken, folderName, pollingInterval).getSyncPoller();
}

/**
* Gets a pending {@link KeyVaultRestoreOperation full or selective restore operation} from the Key Vault.
*
* @param jobId The operation identifier.
* @throws KeyVaultErrorException when a restore operation for a given {@code jobId} doesn't exist.
* @throws NullPointerException if the {@code jobId} is null.
* @return A {@link SyncPoller} to poll on the restore operation status.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Expand All @@ -106,4 +137,22 @@ public SyncPoller<KeyVaultRestoreOperation, Void> getRestoreOperation(String job
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String blobStorageUrl, String sasToken, String folderName) {
return asyncClient.beginSelectiveRestore(keyName, blobStorageUrl, sasToken, folderName).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 blobStorageUrl The URL for the Blob Storage resource where the backup is located.
* @param sasToken A Shared Access Signature (SAS) token to authorize access to the blob.
* @param folderName The name of the folder containing the backup data to restore.
* @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.
* @throws NullPointerException if the {@code keyName}, {@code blobStorageUrl}, {@code sasToken} or {@code
* folderName} are {@code null}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public SyncPoller<KeyVaultRestoreOperation, Void> beginSelectiveRestore(String keyName, String blobStorageUrl, String sasToken, String folderName, Duration pollingInterval) {
return asyncClient.beginSelectiveRestore(keyName, blobStorageUrl, sasToken, folderName, pollingInterval).getSyncPoller();
}
}
Loading