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

[Key Vault Admin] Selective Restore to Selective Key Restore #15354

Merged
3 commits merged into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions sdk/keyvault/keyvault-admin/review/keyvault-admin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class KeyVaultBackupClient {
constructor(vaultUrl: string, credential: TokenCredential, options?: KeyVaultBackupClientOptions);
beginBackup(blobStorageUri: string, sasToken: string, options?: KeyVaultBeginBackupOptions): Promise<PollerLike<KeyVaultBackupOperationState, KeyVaultBackupResult>>;
beginRestore(folderUri: string, sasToken: string, options?: KeyVaultBeginRestoreOptions): Promise<PollerLike<KeyVaultRestoreOperationState, KeyVaultRestoreResult>>;
beginSelectiveRestore(keyName: string, folderUri: string, sasToken: string, options?: KeyVaultBeginBackupOptions): Promise<PollerLike<KeyVaultSelectiveRestoreOperationState, KeyVaultRestoreResult>>;
beginSelectiveKeyRestore(keyName: string, folderUri: string, sasToken: string, options?: KeyVaultBeginBackupOptions): Promise<PollerLike<KeyVaultSelectiveRestoreOperationState, KeyVaultSelectiveKeyRestoreResult>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeyVaultSelectiveRestoreOperationState should also probably be KeyVaultSelectiveKeyRestoreOperationState. Rename with that pattern everywhere.

readonly vaultUrl: string;
}

Expand Down Expand Up @@ -152,7 +152,13 @@ export interface KeyVaultRoleDefinition {
export type KeyVaultRoleScope = "/" | "/keys" | string;

// @public
export interface KeyVaultSelectiveRestoreOperationState extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {
export interface KeyVaultSelectiveKeyRestoreResult {
endTime?: Date;
startTime: Date;
}

// @public
export interface KeyVaultSelectiveRestoreOperationState extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export async function main(): Promise<void> {
const backupPoller = await client.beginBackup(blobStorageUri, sasToken);
await backupPoller.pollUntilDone();

const selectiveRestorePoller = await client.beginSelectiveRestore(
const selectiveKeyRestorePoller = await client.beginSelectiveKeyRestore(
key.name,
blobStorageUri,
sasToken
);
await selectiveRestorePoller.pollUntilDone();
await selectiveKeyRestorePoller.pollUntilDone();

// Deleting and purging the key, just in case we want to create the same key again.
const deleteKeyPoller = await keyClient.beginDeleteKey(keyName);
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-admin/samples/v4/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ These sample programs show how to use the JavaScript client libraries for Azure
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [accessControlHelloWorld.js][accesscontrolhelloworld] | Uses an AccessControlClient to list, create, and assign roles to users. |
| [backupRestoreHelloWorld.js][backuprestorehelloworld] | Uses a BackupClient to backup and fully restore an Azure Key Vault using Azure Storage Blob. |
| [backupSelectiveRestore.js][backupselectiverestore] | Uses a BackupClient to backup and restore a specific key in Azure Key Vault using Azure Storage Blob. |
sadasant marked this conversation as resolved.
Show resolved Hide resolved
| [backupSelectiveKeyRestore.js][backupselectiveKeyrestore] | Uses a BackupClient to backup and restore a specific key in Azure Key Vault using Azure Storage Blob. |

## Prerequisites

Expand Down Expand Up @@ -66,7 +66,7 @@ Take a look at our [API Documentation][apiref] for more information about the AP

[accesscontrolhelloworld]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/javascript/accessControlHelloWorld.js
[backuprestorehelloworld]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/javascript/backupRestoreHelloWorld.js
[backupselectiverestore]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/javascript/backupSelectiveRestore.js
[backupselectiveKeyrestore]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/javascript/backupSelectiveKeyRestore.js
[apiref]: https://docs.microsoft.com/javascript/api/@azure/keyvault-admin
[freesub]: https://azure.microsoft.com/free/
[createinstance_azurekeyvault]: https://docs.microsoft.com/azure/key-vault/quick-create-portal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ async function main() {
const backupPoller = await client.beginBackup(blobStorageUri, sasToken);
await backupPoller.pollUntilDone();

const selectiveRestorePoller = await client.beginSelectiveRestore(
const selectiveKeyRestorePoller = await client.beginSelectiveKeyRestore(
key.name,
blobStorageUri,
sasToken
);
await selectiveRestorePoller.pollUntilDone();
await selectiveKeyRestorePoller.pollUntilDone();

// Deleting and purging the key, just in case we want to create the same key again.
const deleteKeyPoller = await keyClient.beginDeleteKey(keyName);
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-admin/samples/v4/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ These sample programs show how to use the TypeScript client libraries for Azure
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [accessControlHelloWorld.ts][accesscontrolhelloworld] | Uses an AccessControlClient to list, create, and assign roles to users. |
| [backupRestoreHelloWorld.ts][backuprestorehelloworld] | Uses a BackupClient to backup and fully restore an Azure Key Vault using Azure Storage Blob. |
| [backupSelectiveRestore.ts][backupselectiverestore] | Uses a BackupClient to backup and restore a specific key in Azure Key Vault using Azure Storage Blob. |
| [backupSelectiveKeyRestore.ts][backupselectiveKeyrestore] | Uses a BackupClient to backup and restore a specific key in Azure Key Vault using Azure Storage Blob. |

## Prerequisites

Expand Down Expand Up @@ -78,7 +78,7 @@ Take a look at our [API Documentation][apiref] for more information about the AP

[accesscontrolhelloworld]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/typescript/src/accessControlHelloWorld.ts
[backuprestorehelloworld]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/typescript/src/backupRestoreHelloWorld.ts
[backupselectiverestore]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/typescript/src/backupSelectiveRestore.ts
[backupselectiveKeyrestore]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/keyvault/keyvault-admin/samples/v4/typescript/src/backupSelectiveKeyRestore.ts
[apiref]: https://docs.microsoft.com/javascript/api/@azure/keyvault-admin
[freesub]: https://azure.microsoft.com/free/
[createinstance_azurekeyvault]: https://docs.microsoft.com/azure/key-vault/quick-create-portal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export async function main(): Promise<void> {
const backupPoller = await client.beginBackup(blobStorageUri, sasToken);
await backupPoller.pollUntilDone();

const selectiveRestorePoller = await client.beginSelectiveRestore(
const selectiveKeyRestorePoller = await client.beginSelectiveKeyRestore(
key.name,
blobStorageUri,
sasToken
);
await selectiveRestorePoller.pollUntilDone();
await selectiveKeyRestorePoller.pollUntilDone();

// Deleting and purging the key, just in case we want to create the same key again.
const deleteKeyPoller = await keyClient.beginDeleteKey(keyName);
Expand Down
19 changes: 11 additions & 8 deletions sdk/keyvault/keyvault-admin/src/backupClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ import {
KeyVaultBackupResult,
KeyVaultBeginBackupOptions,
KeyVaultBeginRestoreOptions,
KeyVaultRestoreResult
KeyVaultRestoreResult,
KeyVaultSelectiveKeyRestoreResult
} from "./backupClientModels";
import { LATEST_API_VERSION, SDK_VERSION } from "./constants";
import { logger } from "./log";
import { KeyVaultBackupPoller } from "./lro/backup/poller";
import { KeyVaultRestorePoller } from "./lro/restore/poller";
import { KeyVaultSelectiveRestorePoller } from "./lro/selectiveRestore/poller";
import { KeyVaultSelectiveKeyRestorePoller } from "./lro/selectiveKeyRestore/poller";
import { KeyVaultBackupOperationState } from "./lro/backup/operation";
import { KeyVaultRestoreOperationState } from "./lro/restore/operation";
import { KeyVaultAdminPollOperationState } from "./lro/keyVaultAdminPoller";
import { KeyVaultSelectiveRestoreOperationState } from "./lro/selectiveRestore/operation";
import { KeyVaultSelectiveRestoreOperationState } from "./lro/selectiveKeyRestore/operation";
import { KeyVaultClientOptionalParams } from "./generated/models";
import { mappings } from "./mappings";

Expand Down Expand Up @@ -233,15 +234,15 @@ export class KeyVaultBackupClient {
* const blobStorageUri = "<blob-storage-uri>";
* const sasToken = "<sas-token>";
* const keyName = "<key-name>";
* const poller = await client.beginSelectiveRestore(keyName, blobStorageUri, sasToken);
* const poller = await client.beginSelectiveKeyRestore(keyName, blobStorageUri, sasToken);
*
* // Serializing the poller
* //
* // const serialized = poller.toString();
* //
* // A new poller can be created with:
* //
* // await client.beginSelectiveRestore(keyName, blobStorageUri, sasToken, { resumeFrom: serialized });
* // await client.beginSelectiveKeyRestore(keyName, blobStorageUri, sasToken, { resumeFrom: serialized });
* //
*
* // Waiting until it's done
Expand All @@ -253,13 +254,15 @@ export class KeyVaultBackupClient {
* @param sasToken - The SAS token.
* @param options - The optional parameters.
*/
public async beginSelectiveRestore(
public async beginSelectiveKeyRestore(
keyName: string,
folderUri: string,
sasToken: string,
options: KeyVaultBeginBackupOptions = {}
): Promise<PollerLike<KeyVaultSelectiveRestoreOperationState, KeyVaultRestoreResult>> {
const poller = new KeyVaultSelectiveRestorePoller({
): Promise<
PollerLike<KeyVaultSelectiveRestoreOperationState, KeyVaultSelectiveKeyRestoreResult>
> {
const poller = new KeyVaultSelectiveKeyRestorePoller({
...mappings.folderUriParts(folderUri),
keyName,
sasToken,
Expand Down
15 changes: 15 additions & 0 deletions sdk/keyvault/keyvault-admin/src/backupClientModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,18 @@ export interface KeyVaultRestoreResult {
*/
endTime?: Date;
}

/**
* An interface representing the result of a selective key restore operation.
*/
export interface KeyVaultSelectiveKeyRestoreResult {
/**
* The start time of the selective key restore operation.
*/
startTime: Date;

/**
* The end time of the selective key restore operation.
*/
endTime?: Date;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ import {
KeyVaultAdminPollOperation,
KeyVaultAdminPollOperationState
} from "../keyVaultAdminPoller";
import { KeyVaultRestoreResult } from "../../backupClientModels";
import { KeyVaultSelectiveKeyRestoreResult } from "../../backupClientModels";
import { withTrace } from "./poller";

/**
* An interface representing the publicly available properties of the state of a restore Key Vault's poll operation.
*/
export interface KeyVaultSelectiveRestoreOperationState
extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {}
extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {}

/**
* An internal interface representing the state of a restore Key Vault's poll operation.
*/
export interface KeyVaultSelectiveRestorePollOperationState
extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {
extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {
/**
* The name of a Key Vault Key.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
KeyVaultSelectiveRestorePollOperationState
} from "./operation";
import { KeyVaultAdminPollerOptions, KeyVaultAdminPoller } from "../keyVaultAdminPoller";
import { KeyVaultRestoreResult } from "../../backupClientModels";
import { KeyVaultSelectiveKeyRestoreResult } from "../../backupClientModels";
import { createTraceFunction } from "../../../../keyvault-common/src";

export interface KeyVaultSelectiveRestorePollerOptions extends KeyVaultAdminPollerOptions {
Expand All @@ -25,9 +25,9 @@ export const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultSelec
/**
* Class that creates a poller that waits until a key of a Key Vault backup ends up being restored.
*/
export class KeyVaultSelectiveRestorePoller extends KeyVaultAdminPoller<
export class KeyVaultSelectiveKeyRestorePoller extends KeyVaultAdminPoller<
KeyVaultSelectiveRestoreOperationState,
KeyVaultRestoreResult
KeyVaultSelectiveKeyRestoreResult
> {
constructor(options: KeyVaultSelectiveRestorePollerOptions) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ describe("Aborting KeyVaultBackupClient's requests", () => {
});
});

it("can abort beginSelectiveRestore", async function() {
it("can abort beginSelectiveKeyRestore", async function() {
const backupURI = `${blobStorageUri}/${generateFakeUUID()}`;

const controller = new AbortController();
controller.abort();

await assertThrowsAbortError(async () => {
await client.beginSelectiveRestore("key-name", backupURI, blobSasToken, {
await client.beginSelectiveKeyRestore("key-name", backupURI, blobSasToken, {
...testPollerProperties,
abortSignal: controller.signal
});
Expand Down
16 changes: 8 additions & 8 deletions sdk/keyvault/keyvault-admin/test/public/backupClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe("KeyVaultBackupClient", () => {
}
});

it("selectiveRestore completes successfully", async function() {
it("selectiveKeyRestore completes successfully", async function() {
// This test can only be run in playback mode because running a backup
// or restore puts the instance in a bad state (tracked in IcM).
if (!isPlaybackMode()) {
Expand All @@ -136,32 +136,32 @@ describe("KeyVaultBackupClient", () => {
await (await keyClient.beginDeleteKey(keyName, testPollerProperties)).pollUntilDone();
await keyClient.purgeDeletedKey(keyName);

const selectiveRestorePoller = await client.beginSelectiveRestore(
const selectiveKeyRestorePoller = await client.beginSelectiveKeyRestore(
keyName,
backupURI.folderUri!,
blobSasToken,
testPollerProperties
);
await selectiveRestorePoller.poll();
await selectiveKeyRestorePoller.poll();

// A poller can be serialized and then resumed
const resumedPoller = await client.beginSelectiveRestore(
const resumedPoller = await client.beginSelectiveKeyRestore(
keyName,
blobStorageUri,
blobSasToken,
{
...testPollerProperties,
resumeFrom: selectiveRestorePoller.toString()
resumeFrom: selectiveKeyRestorePoller.toString()
}
);
assert.isTrue(resumedPoller.getOperationState().isStarted); // without polling
assert.equal(
resumedPoller.getOperationState().jobId,
selectiveRestorePoller.getOperationState().jobId
selectiveKeyRestorePoller.getOperationState().jobId
);

await selectiveRestorePoller.pollUntilDone();
const operationState = selectiveRestorePoller.getOperationState();
await selectiveKeyRestorePoller.pollUntilDone();
const operationState = selectiveKeyRestorePoller.getOperationState();
assert.equal(operationState.isCompleted, true);

await keyClient.getKey(keyName);
Expand Down