/
keyVaultKeyPoller.ts
91 lines (80 loc) · 2.33 KB
/
keyVaultKeyPoller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { delay, OperationOptions } from "@azure/core-http";
import { Poller, PollOperation, PollOperationState } from "@azure/core-lro";
import { KeyVaultClient } from "../generated/keyVaultClient";
/**
* Common parameters to a Key Vault Key Poller.
*/
export interface KeyVaultKeyPollerOptions {
vaultUrl: string;
client: KeyVaultClient;
name: string;
operationOptions?: OperationOptions;
intervalInMs?: number;
resumeFrom?: string;
}
/**
* An interface representing the state of a Key Vault Key Poller's operation.
*/
export interface KeyVaultKeyPollOperationState<TResult> extends PollOperationState<TResult> {
/**
* The name of the key.
*/
name: string;
}
/**
* Common properties and methods of the Key Vault Key Pollers.
*/
export abstract class KeyVaultKeyPoller<
TState extends KeyVaultKeyPollOperationState<TResult>,
TResult
> extends Poller<TState, TResult> {
/**
* Defines how much time the poller is going to wait before making a new request to the service.
*/
public intervalInMs: number = 2000;
/**
* The method used by the poller to wait before attempting to update its operation.
*/
async delay(): Promise<void> {
return delay(this.intervalInMs);
}
}
/**
* Optional parameters to the KeyVaultKeyPollOperation
*/
export interface KeyVaultKeyPollOperationOptions {
cancelMessage?: string;
}
/**
* Common properties and methods of the Key Vault Key Poller operations.
*/
export class KeyVaultKeyPollOperation<TState, TResult> implements PollOperation<TState, TResult> {
private cancelMessage: string = "";
constructor(public state: TState, options: KeyVaultKeyPollOperationOptions = {}) {
if (options.cancelMessage) {
this.cancelMessage = options.cancelMessage;
}
}
/**
* Meant to reach to the service and update the Poller operation.
*/
public async update(): Promise<PollOperation<TState, TResult>> {
throw new Error("Operation not supported.");
}
/**
* Meant to reach to the service and cancel the Poller operation.
*/
public async cancel(): Promise<PollOperation<TState, TResult>> {
throw new Error(this.cancelMessage);
}
/**
* Serializes the Poller operation.
*/
public toString(): string {
return JSON.stringify({
state: this.state
});
}
}