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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
import {Router, Request, Response, NextFunction} from 'express';
const Files = null;//require('../data');
export class FileRouter {
router: Router
/**
* Initialize the FileRouter
*/
constructor() {
this.router = Router();
this.init();
}
/*
* Returns the supported Protocols
*
* The server's unwrapped response MUST match:
exactly({
"supported": array(string),
"required": array(string)
})
*/
public getProtocols(req: Request, res: Response, next: NextFunction){
}
/*
* Logging Endpoint for all components:
*
* with a request matching
array({
"component": string,
"level": alternative(["info", "security", "warning", "error", "critical"]),
"value": anything
})
*/
public postLog(req: Request, res: Response, next: NextFunction){
}
/*
* Clients authorised as a user with the admin privilege can access
*
* http://backend.endpoint/log?before=<datetime>&after=<datetime>&level=<level>
*
* the server response should match
array({
"component": string,
"level": alternative(["info", "security", "warning", "error", "critical"]),
"value": anything,
"username": string,
"timestamp": string
})
*/
public getLog(req: Request, res: Response, next: NextFunction){
}
/*
* Any authenticated client can access
*
* http://backend.endpoint/properties
*
* the server SHOULD respond with a list of properties, with the unwrapped response matching
array({
"id": string,
"display": optional({
"category": string,
"group": string,
"display_name": string,
"description": string
}),
"read_only": boolean,
"type": alternative(["string", "integer", "boolean"]),
"value": alternative([string, integer, boolean])
})
*/
public getProperties(req: Request, res: Response, next: NextFunction){
}
/*
* To update properties the client POSTs to
*
* http://backend.endpoint/properties?action=update
*
* with body
array({
"id": string,
"value": alternative([string, integer, boolean])
})
*/
public postProperties(req: Request, res: Response, next: NextFunction){
}
/*
* Listing available privileges
*
* And the server's response, unwrapped, must match
array({
"privilege": string,
"description": string,
"internal": boolean
})
*/
public getUserPriveleges(req: Request, res: Response, next: NextFunction){
}
/*
* Listing users
*
* If the client is authorised as a user with the admin privilege
* the server MUST respond with a list of users, with the unwrapped response matching
array({
"username": string,
"privileges": array(string),
"projects": array({
"project_name": string,
"access_level": string
}),
"public_user_metadata": metadata,
"private_user_metadata": metadata,
"public_admin_metadata": metadata,
"private_admin_metadata": metadata
})
*/
public getUsers(req: Request, res: Response, next: NextFunction){
}
/*
* expose additional configuration options for individual users
*
*
*/
public getUserProperties(req: Request, res: Response, next: NextFunction, user?: String){
}
/*
* Listing a particular User
*
* If the client is authorised as a user with the admin privilege the server MUST respond with details of the particular user if they exist (unwrapped response):
{
"username": string,
"privileges": array(string),
"projects": array({
"project_name": string,
"access_level": string
}),
"public_user_metadata": metadata,
"private_user_metadata": metadata,
"public_admin_metadata": metadata,
"private_admin_metadata": metadata
}
*/
public getUsername(req: Request, res: Response, next: NextFunction, user?: String){
}
public getCurUser(req: Request, res: Response, next: NextFunction){
let curUser : String = "";
this.getUsername(req, res, next, curUser);
}
/*
* Updating the current user
*
* http://backend.endpoint/current_user?action=update
*
* with body matching
{
"password": optional({
"old": string,
"new": string
}),
"public_user_metadata": optional(metadata),
"private_user_metadata": optional(metadata),
"public_admin_metadata": not_present,
"private_admin_metadata": not_present
}
*/
public postCurUser(req: Request, res: Response, next: NextFunction){
}
/*
* Creating a User/updating a user
*
* http://backend.endpoint/users/<username>?action=create
*
* with body matching
{
"privileges": array(string),
"password": string,
"public_user_metadata": optional(metadata),
"private_user_metadata": optional(metadata),
"public_admin_metadata": optional(metadata),
"private_admin_metadata": optional(metadata)
}
*/
public postUsername(req: Request, res: Response, next: NextFunction){
}
/*
* Listing available Roles
*
* The servers response, unwrapped, must match
array({
"role": string,
"description": string,
"internal": boolean
})
*/
public getProjectRoles(req: Request, res: Response, next: NextFunction){
}
/*
* Listing Projects
*
* The server MUST respond with a list of projects, with the unwrapped response matching
array({
"project_name": string,
"users": array({
"username": string,
"access_level": string
}),
"public_metadata": metadata,
"private_metadata": optional(metadata),
"admin_metadata": optional(metadata)
})
*/
public getProjects(req: Request, res: Response, next: NextFunction){
}
/*
* Listing a specific Project
*
* The server MUST respond with details of the particular project if it exists (unwrapped response):
{
"project_name": string,
"users": array({
"username": string,
"access_level": string
}),
"public_metadata": metadata,
"private_metadata": metadata,
"admin_metadata": optional(metadata)
}
*/
public getProjectName(req: Request, res: Response, next: NextFunction){
}
/*
* Creating a Project / updating a project / deleting / Project grants
*
* http://backend.endpoint/projects/<project_name>?action=create
*
* with body matching
{
"public_metadata": optional(metadata),
"private_metadata": optional(metadata),
"admin_metadata": optional(metadata)
}
*/
public postProjectName(req: Request, res: Response, next: NextFunction){
}
/*
* additional configuration options for individual projects
*/
public getProjectProperties(req: Request, res: Response, next: NextFunction){
}
/**
* GET a File.
*/
public getFile_path(req: Request, res: Response, next: NextFunction) {
let fileID = req.params.file;
res.send("File");
}
/**
* GET a File.
*/
public getFile_id(req: Request, res: Response, next: NextFunction) {
let fileID = req.params.file;
res.send("File");
}
/**
* Post a File. / delete / move / etc
*/
public postFile_path(req: Request, res: Response, next: NextFunction) {
let fileID = req.params.file;
res.send("File");
}
/**
* Take each handler, and attach to one of the Express.Router's
* endpoints.
*/
init() {
// General
this.router.get ('/_supported_protocols_', this.getProtocols);
this.router.get ('/log', this.getLog);
this.router.post('/log', this.postLog);
this.router.get ('/properties', this.getProperties);
this.router.post('/properties', this.postProperties);
this.router.get ('/user_privileges', this.getUserPriveleges);
this.router.get ('/users', this.getUsers);
this.router.get ('/users/:username', this.getUsername);
this.router.post('/users/:username', this.postUsername);
this.router.get ('/users/:username/properties', this.getUserProperties);
this.router.get ('/current_user', this.getCurUser);
this.router.post('/current_user', this.postCurUser);
// Projects
this.router.get ('/project_roles', this.getProjectRoles);
this.router.get ('/projects', this.getProjects);
this.router.get ('/projects/:project_name', this.getProjectName);
this.router.post('/projects/:project_name', this.postProjectName);
this.router.get ('/projects/:project_name/properties', this.getProjectProperties);
// File access
this.router.get ('/projects/:project_name/files/:path', this.getFile_path);
this.router.post('/projects/:project_name/files/:id', this.postFile_path);
this.router.get ('/projects/:project_name/files_by_id/:id', this.getFile_id);
}
}
// Create the FileRouter, and export its configured Express.Router
const fileRoutes = new FileRouter();
fileRoutes.init();
export default fileRoutes.router;
|