/
identifier.ts
58 lines (51 loc) · 1.41 KB
/
identifier.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { parseKeyVaultIdentifier } from "../../keyvault-common/src";
/**
* Represents the segments that compose a Key Vault Key Id.
*/
export interface KeyVaultKeyIdentifier {
/**
* The complete representation of the Key Vault Key Id. For example:
*
* https://<keyvault-name>.vault.azure.net/keys/<key-name>/<unique-version-id>
*
*/
sourceId: string;
/**
* The URL of the Azure Key Vault instance to which the Key belongs.
*/
vaultUrl: string;
/**
* The version of Key Vault Key. Might be undefined.
*/
version?: string;
/**
* The name of the Key Vault Key.
*/
name: string;
}
/**
* Parses the given Key Vault Key Id. An example is:
*
* https://<keyvault-name>.vault.azure.net/keys/<key-name>/<unique-version-id>
*
* On parsing the above Id, this function returns:
*```ts
* {
* sourceId: "https://<keyvault-name>.vault.azure.net/keys/<key-name>/<unique-version-id>",
* vaultUrl: "https://<keyvault-name>.vault.azure.net",
* version: "<unique-version-id>",
* name: "<key-name>"
* }
*```
* @param id - The Id of the Key Vault Key.
*/
export function parseKeyVaultKeyIdentifier(id: string): KeyVaultKeyIdentifier {
const urlParts = id.split("/");
const collection = urlParts[3];
return {
sourceId: id,
...parseKeyVaultIdentifier(collection, id),
};
}