/
mappings.ts
66 lines (62 loc) · 1.67 KB
/
mappings.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { RoleAssignment, RoleDefinition } from "./generated/models";
import {
KeyVaultRoleAssignment,
KeyVaultRoleDefinition,
KeyVaultRoleScope
} from "./accessControlModels";
export const mappings = {
roleAssignment: {
generatedToPublic(roleAssignment: RoleAssignment): KeyVaultRoleAssignment {
const { id, name, type, properties } = roleAssignment;
const { scope, roleDefinitionId, principalId } = properties || {};
return {
id: id!,
name: name!,
kind: type!,
properties: {
scope: scope as KeyVaultRoleScope,
roleDefinitionId: roleDefinitionId!,
principalId: principalId!
}
};
}
},
roleDefinition: {
generatedToPublic(roleDefinition: RoleDefinition): KeyVaultRoleDefinition {
const {
id,
name,
type,
roleName,
description,
roleType,
permissions,
assignableScopes
} = roleDefinition;
return {
id: id!,
name: name!,
kind: type!,
roleName: roleName!,
description: description!,
roleType: roleType!,
permissions: permissions!,
assignableScopes: assignableScopes!
};
}
},
folderUriParts(folderUri: string): { folderName: string; folderUri: string } {
const uriParts = folderUri.split("/");
const folderName = uriParts.pop();
const storageUri = uriParts.join("/");
if (!folderName) {
throw new Error("The provided folder URI is missing the folder name.");
}
return {
folderName,
folderUri: storageUri
};
}
};