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] Convenience layer - KeyVaultBackupClient #11009

Merged
merged 13 commits into from
Sep 9, 2020
Merged
Prev Previous commit
Next Next commit
moving the internal properties to an options bag
  • Loading branch information
sadasant committed Sep 9, 2020
commit d3400ebce2663be6a14ec066ce1bc98b63d88004
54 changes: 28 additions & 26 deletions sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { AbortSignalLike } from "@azure/abort-controller";
import { PollOperationState, PollOperation } from "@azure/core-lro";
import { RequestOptionsBase } from "@azure/core-http";
import { KeyVaultClient } from "../../generated/keyVaultClient";
import {
KeyVaultClientFullBackupOptionalParams,
Expand Down Expand Up @@ -36,33 +37,39 @@ export interface BackupOperationState extends PollOperationState<string> {
* The end time of the backup operation in UTC
*/
endTime?: Date;
/**
* Internal request parameters
*/
requestParameters?: any;
}

/**
* An internal interface representing the state of a backup Key Vault's poll operation.
* @internal
*/
export interface BackupPollOperationState extends PollOperationState<string> {
/**
* Options for the core-http requests.
*/
requestOptions?: BeginBackupOptions;
/**
* An interface representing the internal KeyVaultClient.
*/
client?: KeyVaultClient;
/**
* The base URL to the vault.
*/
vaultUrl?: string;
/**
* The URI of the blob storage account.
*/
blobStorageUri?: string;
/**
* The SAS token.
*/
sasToken?: string;
requestParameters?: {
/**
* Options for the core-http requests.
*/
requestOptions: RequestOptionsBase;
/**
* An interface representing the internal KeyVaultClient.
*/
client: KeyVaultClient;
/**
* The base URL to the vault.
*/
vaultUrl: string;
/**
* The URI of the blob storage account.
*/
blobStorageUri: string;
/**
* The SAS token.
*/
sasToken: string;
};
/**
* The id returned as part of the backup request
*/
Expand Down Expand Up @@ -143,13 +150,8 @@ async function update(
} = {}
): Promise<BackupPollOperation> {
const state = this.state;
const { vaultUrl, blobStorageUri, sasToken } = state;

// Internal properties,
// the reference is only potentially undefined in the public representation of the poller.
const client = state.client!;
const { requestOptions, vaultUrl, blobStorageUri, sasToken, client } = state.requestParameters!;

const requestOptions = state.requestOptions || {};
if (options.abortSignal) {
requestOptions.abortSignal = options.abortSignal;
}
Expand Down
12 changes: 7 additions & 5 deletions sdk/keyvault/keyvault-admin/src/lro/backup/poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export class BackupPoller extends Poller<BackupPollOperationState, string> {

const operation = makeBackupPollOperation({
...state,
blobStorageUri,
sasToken,
requestOptions,
client,
vaultUrl
requestParameters: {
blobStorageUri,
sasToken,
requestOptions: requestOptions || {},
client,
vaultUrl
}
});

super(operation);
Expand Down
84 changes: 38 additions & 46 deletions sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ import { KeyVaultClientFullRestoreOperationResponse } from "../../generated/mode
* An interface representing the publicly available properties of the state of a restore Key Vault's poll operation.
*/
export interface RestoreOperationState extends PollOperationState<undefined> {
/**
* The base URL to the vault
*/
vaultUrl: string;
/**
* The URI of the blob storage account.
*/
blobStorageUri: string;
/**
* The SAS token.
*/
sasToken: string;
/**
* The Folder name of the blob where the previous successful full backup was stored.
*/
folderName: string;
/**
* Identifier for the full restore operation.
*/
Expand All @@ -52,37 +36,43 @@ export interface RestoreOperationState extends PollOperationState<undefined> {
* The end time of the restore operation in UTC
*/
endTime?: Date;
/**
* Internal request parameters
*/
requestParameters?: any;
}

/**
* An internal interface representing the state of a restore Key Vault's poll operation.
* @internal
*/
export interface RestorePollOperationState extends PollOperationState<undefined> {
/**
* Options for the core-http requests.
*/
requestOptions?: RequestOptionsBase;
/**
* An interface representing the internal KeyVaultClient.
*/
client?: KeyVaultClient;
/**
* The base URL to the vault
*/
vaultUrl: string;
/**
* The URI of the blob storage account.
*/
blobStorageUri: string;
/**
* The SAS token.
*/
sasToken: string;
/**
* The Folder name of the blob where the previous successful full backup was stored
*/
folderName: string;
requestParameters?: {
/**
* Options for the core-http requests.
*/
requestOptions: RequestOptionsBase;
/**
* An interface representing the internal KeyVaultClient.
*/
client: KeyVaultClient;
/**
* The base URL to the vault.
*/
vaultUrl: string;
/**
* The URI of the blob storage account.
*/
blobStorageUri: string;
/**
* The SAS token.
*/
sasToken: string;
/**
* The Folder name of the blob where the previous successful full backup was stored
*/
folderName: string;
};
/**
* The id returned as part of the restore request
*/
Expand Down Expand Up @@ -163,13 +153,15 @@ async function update(
} = {}
): Promise<RestorePollOperation> {
const state = this.state;
const { vaultUrl, blobStorageUri, sasToken, folderName } = state;

// Internal properties,
// the reference is only potentially undefined in the public representation of the poller.
const client = state.client!;
const {
client,
requestOptions,
vaultUrl,
blobStorageUri,
sasToken,
folderName
} = state.requestParameters!;

const requestOptions = state.requestOptions || {};
if (options.abortSignal) {
requestOptions.abortSignal = options.abortSignal;
}
Expand Down
23 changes: 10 additions & 13 deletions sdk/keyvault/keyvault-admin/src/lro/restore/poller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { delay } from "@azure/core-http";
import { delay, RequestOptionsBase } from "@azure/core-http";
import { Poller } from "@azure/core-lro";
import { BeginRestoreOptions } from "../..";
import { KeyVaultClient } from "../../generated/keyVaultClient";
import {
RestoreOperationState,
Expand All @@ -17,7 +16,7 @@ export interface RestorePollerOptions {
blobStorageUri: string;
sasToken: string;
folderName: string;
requestOptions?: BeginRestoreOptions;
requestOptions?: RequestOptionsBase;
intervalInMs?: number;
resumeFrom?: string;
}
Expand Down Expand Up @@ -51,12 +50,14 @@ export class RestorePoller extends Poller<RestorePollOperationState, undefined>

const operation = makeRestorePollOperation({
...state,
blobStorageUri,
sasToken,
folderName,
requestOptions,
client,
vaultUrl
requestParameters: {
blobStorageUri,
sasToken,
folderName,
requestOptions: requestOptions || {},
client,
vaultUrl
}
});

super(operation);
Expand All @@ -78,10 +79,6 @@ export class RestorePoller extends Poller<RestorePollOperationState, undefined>
public getOperationState(): RestoreOperationState {
const state: RestoreOperationState = this.operation.state;
return {
vaultUrl: state.vaultUrl,
blobStorageUri: state.blobStorageUri,
sasToken: state.sasToken,
folderName: state.folderName,
isStarted: state.isStarted,
isCompleted: state.isCompleted,
isCancelled: state.isCancelled,
Expand Down