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 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
4 changes: 4 additions & 0 deletions sdk/keyvault/keyvault-admin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
- Removed `folderName` from `beginSelectiveRestore`. Now the folder name will be inferred from the `folderUri`.
- Reordered the parameters of `beginSelectiveRestore` to `keyName`, `folderUrl`, `sasToken`, `[options]`.
- Renamed `KeyVaultBackupResult`'s `backupFolderUri` to `folderUri`.
- Renamed `beginSelectiveRestore` to `beginSelectiveKeyRestore`.
- Renamed `KeyVaultBeginSelectiveRestoreOptions` to `KeyVaultBeginSelectiveKeyRestoreOptions`.
- Renamed `KeyVaultSelectiveRestoreOperationState` to `KeyVaultSelectiveKeyRestoreOperationState`.
- Renamed `KeyVaultSelectiveRestoreResult` to `KeyVaultSelectiveKeyRestoreResult`.

## 4.0.0-beta.3 (2021-04-06)

Expand Down
12 changes: 9 additions & 3 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?: KeyVaultBeginSelectiveKeyRestoreOptions): Promise<PollerLike<KeyVaultSelectiveKeyRestoreOperationState, KeyVaultSelectiveKeyRestoreResult>>;
readonly vaultUrl: string;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ export interface KeyVaultBeginRestoreOptions extends KeyVaultBackupPollerOptions
}

// @public
export interface KeyVaultBeginSelectiveRestoreOptions extends KeyVaultBackupPollerOptions {
export interface KeyVaultBeginSelectiveKeyRestoreOptions extends KeyVaultBackupPollerOptions {
}

// @public
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 KeyVaultSelectiveKeyRestoreOperationState extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {
}

// @public
export interface KeyVaultSelectiveKeyRestoreResult {
endTime?: Date;
startTime: Date;
}

// @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
8 changes: 4 additions & 4 deletions sdk/keyvault/keyvault-admin/samples/v4/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ These sample programs show how to use the JavaScript client libraries for Azure

| **File Name** | **Description** |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [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
| [accessControlHelloWorld.js][accesscontrolhelloworld] | Uses an KeyVaultAccessControlClient to list, create, and assign roles to users. |
| [backupRestoreHelloWorld.js][backuprestorehelloworld] | Uses a KeyVaultBackupClient to backup and fully restore an Azure Key Vault using Azure Storage Blob. |
| [backupSelectiveKeyRestore.js][backupselectiveKeyrestore] | Uses a KeyVaultBackupClient 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
8 changes: 4 additions & 4 deletions sdk/keyvault/keyvault-admin/samples/v4/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ These sample programs show how to use the TypeScript client libraries for Azure

| **File Name** | **Description** |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [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. |
| [accessControlHelloWorld.ts][accesscontrolhelloworld] | Uses an KeyVaultAccessControlClient to list, create, and assign roles to users. |
| [backupRestoreHelloWorld.ts][backuprestorehelloworld] | Uses a KeyVaultBackupClient to backup and fully restore an Azure Key Vault using Azure Storage Blob. |
| [backupSelectiveKeyRestore.ts][backupselectiveKeyrestore] | Uses a KeyVaultBackupClient 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
24 changes: 14 additions & 10 deletions sdk/keyvault/keyvault-admin/src/backupClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ import {
KeyVaultBackupResult,
KeyVaultBeginBackupOptions,
KeyVaultBeginRestoreOptions,
KeyVaultRestoreResult
KeyVaultBeginSelectiveKeyRestoreOptions,
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 { KeyVaultSelectiveKeyRestoreOperationState } from "./lro/selectiveKeyRestore/operation";
import { KeyVaultClientOptionalParams } from "./generated/models";
import { mappings } from "./mappings";

export {
KeyVaultBackupOperationState,
KeyVaultRestoreOperationState,
KeyVaultSelectiveRestoreOperationState,
KeyVaultSelectiveKeyRestoreOperationState,
KeyVaultAdminPollOperationState
};

Expand Down Expand Up @@ -233,15 +235,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 +255,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({
options: KeyVaultBeginSelectiveKeyRestoreOptions = {}
): Promise<
PollerLike<KeyVaultSelectiveKeyRestoreOperationState, KeyVaultSelectiveKeyRestoreResult>
> {
const poller = new KeyVaultSelectiveKeyRestorePoller({
...mappings.folderUriParts(folderUri),
keyName,
sasToken,
Expand Down
19 changes: 17 additions & 2 deletions sdk/keyvault/keyvault-admin/src/backupClientModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export interface KeyVaultBeginRestoreOptions extends KeyVaultBackupPollerOptions

/**
* An interface representing the optional parameters that can be
* passed to {@link beginSelectiveRestore}
* passed to {@link beginSelectiveKeyRestore}
*/
export interface KeyVaultBeginSelectiveRestoreOptions extends KeyVaultBackupPollerOptions {}
export interface KeyVaultBeginSelectiveKeyRestoreOptions extends KeyVaultBackupPollerOptions {}

/**
* An interface representing the result of a backup operation.
Expand Down 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> {}
export interface KeyVaultSelectiveKeyRestoreOperationState
extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {}

/**
* An internal interface representing the state of a restore Key Vault's poll operation.
*/
export interface KeyVaultSelectiveRestorePollOperationState
extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {
export interface KeyVaultSelectiveKeyRestorePollOperationState
extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {
/**
* The name of a Key Vault Key.
*/
Expand All @@ -49,12 +49,12 @@ export interface KeyVaultSelectiveRestorePollOperationState
/**
* The selective restore Key Vault's poll operation.
*/
export class KeyVaultSelectiveRestorePollOperation extends KeyVaultAdminPollOperation<
KeyVaultSelectiveRestorePollOperationState,
export class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollOperation<
KeyVaultSelectiveKeyRestorePollOperationState,
string
> {
constructor(
public state: KeyVaultSelectiveRestorePollOperationState,
public state: KeyVaultSelectiveKeyRestorePollOperationState,
private vaultUrl: string,
private client: KeyVaultClient,
private requestOptions: RequestOptionsBase = {}
Expand Down Expand Up @@ -92,9 +92,9 @@ export class KeyVaultSelectiveRestorePollOperation extends KeyVaultAdminPollOper
async update(
options: {
abortSignal?: AbortSignalLike;
fireProgress?: (state: KeyVaultSelectiveRestorePollOperationState) => void;
fireProgress?: (state: KeyVaultSelectiveKeyRestorePollOperationState) => void;
} = {}
): Promise<KeyVaultSelectiveRestorePollOperation> {
): Promise<KeyVaultSelectiveKeyRestorePollOperation> {
const state = this.state;
const { keyName, folderUri, sasToken, folderName } = state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Licensed under the MIT license.

import {
KeyVaultSelectiveRestorePollOperation,
KeyVaultSelectiveRestoreOperationState,
KeyVaultSelectiveRestorePollOperationState
KeyVaultSelectiveKeyRestorePollOperation,
KeyVaultSelectiveKeyRestoreOperationState,
KeyVaultSelectiveKeyRestorePollOperationState
} 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 {
export interface KeyVaultSelectiveKeyRestorePollerOptions extends KeyVaultAdminPollerOptions {
keyName: string;
folderUri: string;
sasToken: string;
Expand All @@ -20,16 +20,18 @@ export interface KeyVaultSelectiveRestorePollerOptions extends KeyVaultAdminPoll
/**
* @internal
*/
export const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultSelectiveRestorePoller");
export const withTrace = createTraceFunction(
"Azure.KeyVault.Admin.KeyVaultSelectiveKeyRestorePoller"
);

/**
* Class that creates a poller that waits until a key of a Key Vault backup ends up being restored.
*/
export class KeyVaultSelectiveRestorePoller extends KeyVaultAdminPoller<
KeyVaultSelectiveRestoreOperationState,
KeyVaultRestoreResult
export class KeyVaultSelectiveKeyRestorePoller extends KeyVaultAdminPoller<
KeyVaultSelectiveKeyRestoreOperationState,
KeyVaultSelectiveKeyRestoreResult
> {
constructor(options: KeyVaultSelectiveRestorePollerOptions) {
constructor(options: KeyVaultSelectiveKeyRestorePollerOptions) {
const {
client,
vaultUrl,
Expand All @@ -42,13 +44,13 @@ export class KeyVaultSelectiveRestorePoller extends KeyVaultAdminPoller<
resumeFrom
} = options;

let state: KeyVaultSelectiveRestorePollOperationState | undefined;
let state: KeyVaultSelectiveKeyRestorePollOperationState | undefined;

if (resumeFrom) {
state = JSON.parse(resumeFrom).state;
}

const operation = new KeyVaultSelectiveRestorePollOperation(
const operation = new KeyVaultSelectiveKeyRestorePollOperation(
{
...state,
keyName,
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
Loading