/
models.ts
315 lines (271 loc) · 9.2 KB
/
models.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { FileSystemAttributes } from "./FileSystemAttributes";
import { truncatedISO8061Date } from "./utils/utils.common";
import { logger } from "./log";
export interface Metadata {
[propertyName: string]: string;
}
export interface FileHttpHeaders {
/**
* Optional. Sets the file's cache
* control. If specified, this property is stored with the file and returned
* with a read request.
*/
fileCacheControl?: string;
/**
* Optional. Sets the file's content type.
* If specified, this property is stored with the file and returned with a
* read request.
*/
fileContentType?: string;
/**
* Optional. An MD5 hash of the file
* content. Note that this hash is not validated, as the hashes for the
* individual blocks were validated when each was uploaded.
*/
fileContentMD5?: Uint8Array;
/**
* Optional. Sets the file's content
* encoding. If specified, this property is stored with the file and returned
* with a read request.
*/
fileContentEncoding?: string;
/**
* Optional. Set the file's content
* language. If specified, this property is stored with the file and returned
* with a read request.
*/
fileContentLanguage?: string;
/**
* Optional. Sets the file's
* Content-Disposition header.
*/
fileContentDisposition?: string;
}
/**
* Indicates inherit file permission from the parent directory.
*/
export type FilePermissionInheritType = "inherit";
/**
* Indicates keep existing file permission value unchanged.
*/
export type FilePermissionPreserveType = "preserve";
/**
* Indicates setting as the time of the request.
*/
export type TimeNowType = "now";
/**
* Indicates keep existing time value unchanged.
*/
export type TimePreserveType = "preserve";
/**
* Indicates keep existing file attributes unchanged.
*/
export type FileAttributesPreserveType = "preserve";
export interface FileAndDirectoryCreateCommonOptions {
/**
* The permission(security descriptor) to be set for the file or directory in the
* Security Descriptor Definition Language (SDDL). If specified, it must have an owner, group, and discretionary access control list (DACL).
* A value of inherit may be passed to inherit from the parent directory.
*
* Note that only one of filePermission or filePermissionKey can be specified.
* And if both are not specified, inherit will be set to filePermission as default value by client library.
*/
filePermission?: string | FilePermissionInheritType;
/**
* The key of the permission to be set for the file or directory. This can be created using the Create-Permission API.
*
* Note that only one of filePermission or filePermissionKey can be specified.
*/
filePermissionKey?: string;
/**
* The file system attributes to be set on the file or directory.
*/
fileAttributes?: FileSystemAttributes;
/**
* The Coordinated Universal Time (UTC) creation time property for the directory.
* A value of now may be used to indicate the time of the request.
* By default, the value will be set as now.
*/
creationTime?: Date | TimeNowType;
/**
* The Coordinated Universal Time (UTC) last write property for the directory.
* A value of now may be used to indicate the time of the request.
* By default, the value will be set as now.
*/
lastWriteTime?: Date | TimeNowType;
}
export interface FileAndDirectorySetPropertiesCommonOptions {
/**
* The permission(security descriptor) to be set for the file or directory in the
* Security Descriptor Definition Language (SDDL). If specified, it must have an owner, group, and discretionary access control list (DACL).
* A value of inherit may be passed to inherit from the parent directory.
* A value of preserve may be passed to keep the value unchanged.
*
* Note that only one of filePermission or filePermissionKey can be specified.
* And if both are not specified, preserve will be set to filePermission as default value by client library.
*/
filePermission?: string | FilePermissionInheritType | FilePermissionPreserveType;
/**
* The key of the permission to be set for the file or directory. This can be created using the Create-Permission API.
*
* Note that only one of filePermission or filePermissionKey can be specified.
*/
filePermissionKey?: string;
/**
* The file system attributes to be set on the file or directory.
*/
fileAttributes?: FileSystemAttributes | FileAttributesPreserveType;
/**
* The Coordinated Universal Time (UTC) creation time property for the directory.
* A value of now may be used to indicate the time of the request.
* A value of preserve may be passed to keep an existing value unchanged.
* By default, the value will be set as preserve.
*/
creationTime?: Date | TimeNowType | TimePreserveType;
/**
* The Coordinated Universal Time (UTC) last write property for the directory.
* A value of now may be used to indicate the time of the request.
* A value of preserve may be passed to keep an existing value unchanged.
* By default, the value will be set as preserve.
*/
lastWriteTime?: Date | TimeNowType | TimePreserveType;
}
/**
* Close handles result information.
*/
export interface CloseHandlesInfo {
closedHandlesCount: number;
/**
* Contains count of number of handles that failed to close.
*/
closeFailureCount?: number;
}
/**
* Protocols to enable on the share. For now, only support SMB or NFS.
*/
export interface ShareProtocols {
/**
* The share can be accessed by SMBv3.0, SMBv2.1 and REST.
*/
smbEnabled?: boolean;
/**
* The share can be accessed by NFSv4.1.
*/
nfsEnabled?: boolean;
}
/**
* Convert protocols from joined string to ShareProtocols.
*
* @param protocolsString -
*/
export function toShareProtocols(protocolsString?: string): ShareProtocols | undefined {
if (protocolsString === undefined) {
return undefined;
}
const protocolStrArray = protocolsString.split(";");
const protocols: ShareProtocols = {};
for (const protocol of protocolStrArray) {
if (protocol === "SMB") {
protocols.smbEnabled = true;
} else if (protocol === "NFS") {
protocols.nfsEnabled = true;
}
}
return protocols;
}
/**
* Convert ShareProtocols to joined string.
*
* @param protocols -
*/
export function toShareProtocolsString(protocols: ShareProtocols = {}): string | undefined {
let protocolStr = undefined;
if (protocols.smbEnabled === true) {
protocolStr = "SMB";
}
if (protocols.nfsEnabled === true) {
logger.info(
`Using "NFS" in favor of "SMB" for the share protocol as currently they can't be supported at the same time.`
);
protocolStr = "NFS";
}
return protocolStr;
}
export function validateFilePermissionOptions(
filePermission?: string,
filePermissionKey?: string
): void {
if (filePermission && filePermissionKey) {
throw new RangeError("Only one of filePermission or filePermissionKey can be specified.");
}
}
export function validateAndSetDefaultsForFileAndDirectoryCreateCommonOptions(
options: FileAndDirectoryCreateCommonOptions
): FileAndDirectoryCreateCommonOptions {
// Would better deep copy params set by user.
if (!options) {
options = {};
}
validateFilePermissionOptions(options.filePermission, options.filePermissionKey);
if (!options.creationTime) {
options.creationTime = "now";
}
if (!options.lastWriteTime) {
options.lastWriteTime = "now";
}
if (!options.filePermission && !options.filePermissionKey) {
options.filePermission = "inherit";
}
return options;
}
export function validateAndSetDefaultsForFileAndDirectorySetPropertiesCommonOptions(
options: FileAndDirectorySetPropertiesCommonOptions
): FileAndDirectorySetPropertiesCommonOptions {
// Would better deep copy params set by user.
if (!options) {
options = {};
}
validateFilePermissionOptions(options.filePermission, options.filePermissionKey);
if (!options.creationTime) {
options.creationTime = "preserve";
}
if (!options.lastWriteTime) {
options.lastWriteTime = "preserve";
}
if (!options.fileAttributes) {
options.fileAttributes = "preserve";
}
if (!options.filePermission && !options.filePermissionKey) {
options.filePermission = "preserve";
}
return options;
}
export function fileAttributesToString(
fileAttributes: FileSystemAttributes | FileAttributesPreserveType
): string {
return fileAttributes instanceof FileSystemAttributes
? fileAttributes.toString()
: fileAttributes;
}
export function fileCreationTimeToString(time: Date | TimeNowType | TimePreserveType): string {
return time instanceof Date ? truncatedISO8061Date(time) : time;
}
export function fileLastWriteTimeToString(time: Date | TimeNowType | TimePreserveType): string {
return time instanceof Date ? truncatedISO8061Date(time) : time;
}
/**
* Represents authentication information in Authorization, ProxyAuthorization,
* WWW-Authenticate, and Proxy-Authenticate header values.
*/
export interface HttpAuthorization {
/**
* The scheme to use for authorization.
*/
scheme: string;
/**
* the credentials containing the authentication information of the user agent for the resource being requested.
*/
value: string;
}