-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathaccess.ts
144 lines (101 loc) · 3.88 KB
/
access.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
/* eslint-disable */
import bindings = require("bindings");
const uplink = bindings("uplink");
import {ProjectResultStruct} from "./project.js";
const errorhandle = require("./error.js");
export class AccessResultStruct {
access: any;
constructor (access: any) {
this.access = access;
}
/*
* Function opens Storj(V3) project using access grant.
* Input : None
* Output : Project(Object)
*/
async openProject (): Promise<ProjectResultStruct> {
const project = await uplink.open_project(this.access).catch((error: any) => {
errorhandle.storjException(
error.error.code,
error.error.message
);
}),
projectResultReturn = new ProjectResultStruct(project.project);
return projectResultReturn;
}
/*
* Function opens Storj(V3) project using access grant and custom configuration.
* Input : None
* Output : Project(Object)
*/
async configOpenProject (): Promise<ProjectResultStruct> {
const project = await uplink.config_open_project(this.access).catch((error: any) => {
errorhandle.storjException(
error.error.code,
error.error.message
);
}),
projectResultReturn = new ProjectResultStruct(project.project);
return projectResultReturn;
}
/*
*
* Function Share creates a new access grant with specific permissions.
* Access grants can only have their existing permissions restricted, and the resulting
* access grant will only allow for the intersection of all previous Share calls in the
* access grant construction chain.
* Prefixes, if provided, restrict the access grant (and internal encryption information)
* to only contain enough information to allow access to just those prefixes.
* Input : Permission (Object) , sharePrefixListArray (Array) , sharePrefixListArraylength (Int)
* Output : Project(Object)
*/
async share (permission: Record<string, any>, sharePrefixListArray: Array<any>, sharePrefixListArraylength: number): Promise<AccessResultStruct> {
const sharedAccess = await uplink.access_share(
this.access,
permission,
sharePrefixListArray,
sharePrefixListArraylength
).catch((error: any) => {
errorhandle.storjException(
error.error.code,
error.error.message
);
}),
sharedAccessResultReturn = new AccessResultStruct(sharedAccess.access);
return sharedAccessResultReturn;
}
/*
* Function serializes an access grant such that it can be used later with ParseAccess or other tools.
* Input : None
* Output : SharedString (String)
*/
async serialize (): Promise<string> {
const stringResult = await uplink.access_serialize(this.access).catch((error: any) => {
errorhandle.storjException(
error.error.code,
error.error.message
);
});
return stringResult;
}
/*
* Function serializes an access grant such that it can be used later with ParseAccess or other tools.
* Input : bucket (String) , prefix (String) and Encrption key
* Output : None
*/
async overrideEncryptionKey (bucket: string, prefix:string, encryption_key:any): Promise<string> {
const stringResult = await uplink.access_override_encryption_key(
this.access,
bucket,
prefix,
encryption_key
).catch((error:any) => {
errorhandle.storjException(
error.error.code,
error.error.message
);
});
return stringResult;
}
}
/* eslint-enable */