thorin-plugin-cluster-kube 2.0.1 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -0
- package/lib/clusterClient.js +19 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -17,6 +17,8 @@ module.exports = function init(thorin, opt, pluginName) {
|
|
|
17
17
|
token: process.env.CLUSTER_TOKEN || null, // A shared verification token used for auth
|
|
18
18
|
namespace: 'svc.cluster.local', // The kube namespace name
|
|
19
19
|
protocol: 'http', // The default protocol for all communication
|
|
20
|
+
alias: { // aliases for services.
|
|
21
|
+
},
|
|
20
22
|
port: {
|
|
21
23
|
_all: 8080 // A map with {serviceName:port} for any registered services.
|
|
22
24
|
}, // The default microservice port
|
package/lib/clusterClient.js
CHANGED
|
@@ -70,14 +70,22 @@ module.exports = function init(thorin, opt) {
|
|
|
70
70
|
if (this.#token) {
|
|
71
71
|
fetchOpt.headers['x-cluster-token'] = this.sign(reqPayload, opt.service.id);
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let port = (typeof opt.port === 'number') ? opt.port : null;
|
|
76
|
-
if (!port && typeof opt.port === 'object' && opt.port) {
|
|
77
|
-
port = opt.port[service] || opt.port['_all'];
|
|
73
|
+
if (_opt && _opt.headers) {
|
|
74
|
+
Object.keys(_opt.headers || {}).forEach(k => fetchOpt.headers[k] = _opt.headers[k]);
|
|
78
75
|
}
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
let url;
|
|
77
|
+
if (opt.alias && opt.alias[service]) {
|
|
78
|
+
url = opt.alias[service];
|
|
79
|
+
} else {
|
|
80
|
+
url = `${opt.protocol}://${service}`;
|
|
81
|
+
if (opt.namespace) url += `.${opt.namespace}`;
|
|
82
|
+
let port = (typeof opt.port === 'number') ? opt.port : null;
|
|
83
|
+
if (!port && typeof opt.port === 'object' && opt.port) {
|
|
84
|
+
port = opt.port[service] || opt.port['_all'];
|
|
85
|
+
}
|
|
86
|
+
if (port) {
|
|
87
|
+
url += `:${port}`;
|
|
88
|
+
}
|
|
81
89
|
}
|
|
82
90
|
url += `${opt.path}`;
|
|
83
91
|
try {
|
|
@@ -90,7 +98,9 @@ module.exports = function init(thorin, opt) {
|
|
|
90
98
|
try {
|
|
91
99
|
let r = await fetch(url, fetchOpt);
|
|
92
100
|
if (r.type) delete r.type;
|
|
93
|
-
|
|
101
|
+
if (opt.debug) {
|
|
102
|
+
logger.trace(`dispatch <- [${service}#${action}]`, r);
|
|
103
|
+
}
|
|
94
104
|
return r;
|
|
95
105
|
} catch (e) {
|
|
96
106
|
if (opt.debug) {
|
|
@@ -98,6 +108,7 @@ module.exports = function init(thorin, opt) {
|
|
|
98
108
|
}
|
|
99
109
|
if (opt.required === false) return null;
|
|
100
110
|
if (e.ns === 'FETCH') e.ns = 'CLUSTER';
|
|
111
|
+
if (e.data && e.data.url) delete e.data.url;
|
|
101
112
|
e.action = action;
|
|
102
113
|
e.service = service;
|
|
103
114
|
throw e;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thorin-plugin-cluster-kube",
|
|
3
3
|
"author": "UNLOQ Systems",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.5",
|
|
5
5
|
"dependencies": {},
|
|
6
6
|
"description": "Thorin.js cluster plugin for microservice communication within a kubernetes environment",
|
|
7
7
|
"main": "index.js",
|