-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.js
More file actions
99 lines (79 loc) · 4.51 KB
/
api.js
File metadata and controls
99 lines (79 loc) · 4.51 KB
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
exports.install = function() {
ROUTE('GET /api/ping', ping);
// Users
ROUTE('+API /api/ +users --> Users/list');
ROUTE('+API /api/ +users_read/{id} --> Users/read');
ROUTE('+API /api/ +users_create --> Users/create');
ROUTE('+API /api/ +users_update/{id} --> Users/update');
ROUTE('+API /api/ -users_remove/{id} --> Users/remove');
ROUTE('-API /api/ +login --> Users/login');
ROUTE('+API /api/ -profile_read --> Users/profile_read');
ROUTE('+API /api/ +profile_update --> Users/profile_update');
ROUTE('+API /api/ +password --> Users/password_update');
ROUTE('+GET /logout/ --> Users/logout');
// Misc
ROUTE('-API /api/ +account_create --> Account/create');
ROUTE('+API /api/ -version --> Common/version');
ROUTE('+API /api/ +search --> Spotlight/search');
ROUTE('+API /api/ +catalogs --> Catalogs/list');
ROUTE('+API /api/ +catalogs_read/{id} --> Catalogs/read');
ROUTE('+API /api/ +catalogs_create --> Catalogs/create');
ROUTE('+API /api/ +catalogs_update/{id} --> Catalogs/update');
ROUTE('+API /api/ +catalogs_fork_create --> Catalogs/fork_create');
ROUTE('+API /api/ +catalogs_fork_update/{id} --> Catalogs/fork_update');
ROUTE('+API /api/ +catalogs_fork_remove --> Catalogs/fork_remove');
ROUTE('+API /api/ +catalogs_remove/{id} --> Catalogs/remove');
ROUTE('+API /api/ +catalogs_execute/{id} --> Catalogs/execute');
// infrastructures
ROUTE('+API /api/ -infrastructures --> Infrastructures/list');
ROUTE('+API /api/ +infrastructures_read/{id} --> Infrastructures/read');
ROUTE('+API /api/ +infrastructures_create --> Infrastructures/create');
ROUTE('+API /api/ +infrastructures_update/{id} --> Infrastructures/update');
ROUTE('+API /api/ +infrastructures_remove/{id} --> Infrastructures/remove');
ROUTE('+POST /api/tfstates/{id}/ --> Infrastructures/tfstates_update');
ROUTE('+GET /api/tfstates/{id}/ --> Infrastructures/tfstates_read');
// Inventory
ROUTE('+GET /api/inventory --> Inventory/read');
// Software
ROUTE('+API /api/ -softwares --> Softwares/list');
ROUTE('+API /api/ +softwares_new --> Softwares/new');
ROUTE('+API /api/ +softwares_read/{id} --> Softwares/read');
ROUTE('+API /api/ +softwares_create --> Softwares/create');
ROUTE('+API /api/ +softwares_update/{id} --> Softwares/update');
ROUTE('+API /api/ +softwares_update_version/{id} --> Softwares/update_version');
ROUTE('+API /api/ +softwares_remove/{id} --> Softwares/remove');
ROUTE('+API /api/ +softwares_execute/{id} --> Softwares/execute');
// Variables
ROUTE('+API /api/ +variables --> Variables/list');
ROUTE('+API /api/ +variables_read/{id} --> Variables/read');
ROUTE('+API /api/ +variables_create --> Variables/create');
ROUTE('+API /api/ +variables_update/{id} --> Variables/update');
ROUTE('+API /api/ +variables_remove/{id} --> Variables/remove');
ROUTE('+POST /api/secret --> Variables/secret');
// 3dForceGraph
ROUTE('+API /api/ -graphs --> Graphs/list');
ROUTE('+SOCKET /api/', socket);
};
function ping($) {
$.success();
}
function socket($) {
var clients = {};
MAIN.ws = $;
$.autodestroy(() => MAIN.ws = null);
$.on('open', function(client) {
var msg = { TYPE: 'sync', data: clients };
client.send(msg);
});
$.on('close', function(client) {
$.send({ TYPE: 'close', data: clients[client.query.id], clientid: client.query.id });
delete clients[client.query.id];
});
$.on('message', function(client, msg) {
if (msg.TYPE === 'ticket') {
client.ticketid = msg.id;
clients[client.query.id] = { clientid: client.query.id, userid: client.user.id, ticketid: msg.id };
$.send({ TYPE: 'ticket', data: clients[client.query.id], clientid: client.query.id });
}
});
}