-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEndpointManager.js
More file actions
122 lines (97 loc) · 3.38 KB
/
EndpointManager.js
File metadata and controls
122 lines (97 loc) · 3.38 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
CloudGenix Controller SDK
(c) 2017 CloudGenix, Inc.
All Rights Reserved
https://www.cloudgenix.com
This SDK is released under the MIT license.
For support, please contact us on:
NetworkToCode Slack channel #cloudgenix: http://slack.networktocode.com
Email: developers@cloudgenix.com
*/
'use strict';
class EndpointManager {
// <editor-fold desc="Constructors and Factories">
constructor(debug) {
this._versions = {};
this._endpoints = {};
this._debug = debug;
// static versions
this.addVersion("login", "v2.0");
this.addVersion("logout", "v2.0");
this.addVersion("permissions", "v2.0");
this.addVersion("profile", "v2.0");
this.addVersion("flows_monitor", "v3.0");
this.addVersion("events", "v3.1");
this.addVersion("query_events", "v3.1");
// static endpoints
this.addEndpoint("login", "/%s/api/login");
this.addEndpoint("logout", "/%s/api/logout");
this.addEndpoint("permissions", "/%s/api/permissions");
this.addEndpoint("profile", "/%s/api/profile");
this.addEndpoint("flows_monitor", "/%s/api/tenants/%s/monitor/flows");
this.addEndpoint("events", "/%s/api/tenants/%s/events");
this.addEndpoint("query_events", "/%s/api/tenants/%s/events/query");
}
// </editor-fold>
// <editor-fold desc="Public Methods">
addVersion(api, version) {
if (api in this._versions) {
// do not override static mappings
this._log("addVersion skipping add version for api " + api + ": static mapping exists");
return;
}
this._log("addVersion added version for api: " + api + " " + version);
this._versions[api] = version;
}
getVersion(api) {
if (api in this._versions) {
this._log("addVersion returning version for api " + api + ": " + this._versions[api]);
return this._versions[api];
}
return null;
}
getAllVersions() {
return this._versions;
}
addEndpoint(api, url) {
if (api in this._endpoints) {
// do not override static mappings
this._log("addEndpoint skipping add endpoint for endpoint " + api + ": static mapping exists");
return;
}
// get the version
if (api in this._versions) {
var version = this._versions[api];
var amendedUrl = url.replace("%s", version);
this._log("addEndpoint added endpoint for api " + api + ": " + amendedUrl);
this._endpoints[api] = amendedUrl;
return;
}
else {
this._log("addEndpoint unable to find version for api: " + api);
return;
}
}
getEndpoint(api) {
if (api in this._endpoints) {
this._log("getEndpoint returning endpoint for api " + api + ": " + this._endpoints[api]);
return this._endpoints[api];
}
else {
this._log("getEndpoint unable to find endpoint for api " + api);
return null;
}
}
getAllEndpoints() {
return this._endpoints;
}
// </editor-fold>
// <editor-fold desc="Internal Methods">
_log(msg) {
if (this._debug) {
console.log(msg);
}
}
// </editor-fold>
};
module.exports = EndpointManager;