@celljs/ta-gateway 4.16.0 → 4.17.0
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/README.en.md +5 -2
- package/README.md +5 -2
- package/esm/node/docker-engine.d.ts +5 -1
- package/esm/node/docker-engine.js +7 -1
- package/esm/node/docker-sandbox.d.ts +10 -1
- package/esm/node/docker-sandbox.js +24 -5
- package/esm/node/egress-proxy.d.ts +98 -0
- package/esm/node/egress-proxy.js +428 -0
- package/esm/node/environments.d.ts +5 -2
- package/esm/node/environments.js +4 -2
- package/esm/node/gateway-cli.js +12 -5
- package/esm/node/gateway-policy.d.ts +6 -1
- package/esm/node/gateway-policy.js +10 -1
- package/esm/node/gateway-quotas.d.ts +6 -1
- package/esm/node/gateway-quotas.js +17 -0
- package/esm/node/gateway-server.d.ts +31 -0
- package/esm/node/gateway-server.js +131 -13
- package/esm/node/gateway-service-util.d.ts +41 -0
- package/esm/node/gateway-service-util.js +178 -0
- package/esm/node/gateway-service.d.ts +5 -41
- package/esm/node/gateway-service.js +19 -173
- package/esm/node/gateway-socket.d.ts +1 -1
- package/esm/node/gateway-socket.js +1 -1
- package/esm/node/index.d.ts +4 -0
- package/esm/node/index.js +4 -0
- package/esm/node/kubernetes-api.d.ts +35 -0
- package/esm/node/kubernetes-api.js +115 -0
- package/esm/node/kubernetes-sandbox.d.ts +198 -0
- package/esm/node/kubernetes-sandbox.js +279 -0
- package/esm/node/sandbox-provider.d.ts +11 -1
- package/esm/node/sandbox-provider.js +2 -1
- package/esm/node/tenant-store.d.ts +15 -0
- package/esm/node/tenant-store.js +15 -0
- package/lib/node/docker-engine.d.ts +5 -1
- package/lib/node/docker-engine.js +7 -1
- package/lib/node/docker-sandbox.d.ts +10 -1
- package/lib/node/docker-sandbox.js +24 -5
- package/lib/node/egress-proxy.d.ts +99 -0
- package/lib/node/egress-proxy.js +433 -0
- package/lib/node/environments.d.ts +5 -2
- package/lib/node/environments.js +4 -2
- package/lib/node/gateway-cli.js +12 -5
- package/lib/node/gateway-policy.d.ts +6 -1
- package/lib/node/gateway-policy.js +10 -1
- package/lib/node/gateway-quotas.d.ts +6 -1
- package/lib/node/gateway-quotas.js +17 -0
- package/lib/node/gateway-server.d.ts +31 -0
- package/lib/node/gateway-server.js +129 -11
- package/lib/node/gateway-service-util.d.ts +42 -0
- package/lib/node/gateway-service-util.js +182 -0
- package/lib/node/gateway-service.d.ts +5 -41
- package/lib/node/gateway-service.js +41 -196
- package/lib/node/gateway-socket.d.ts +1 -1
- package/lib/node/gateway-socket.js +10 -10
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.js +4 -0
- package/lib/node/kubernetes-api.d.ts +36 -0
- package/lib/node/kubernetes-api.js +120 -0
- package/lib/node/kubernetes-sandbox.d.ts +199 -0
- package/lib/node/kubernetes-sandbox.js +283 -0
- package/lib/node/sandbox-provider.d.ts +11 -1
- package/lib/node/sandbox-provider.js +2 -1
- package/lib/node/tenant-store.d.ts +15 -0
- package/lib/node/tenant-store.js +15 -0
- package/package.json +4 -4
|
@@ -1,185 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GatewayService =
|
|
3
|
+
exports.GatewayService = void 0;
|
|
4
4
|
const access_store_1 = require("@celljs/ta-host/lib/node/sign-in/access-store");
|
|
5
5
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
6
6
|
const redactor_1 = require("@celljs/ta-protocol/lib/common/redactor");
|
|
7
|
+
const egress_proxy_1 = require("./egress-proxy");
|
|
7
8
|
const gateway_policy_1 = require("./gateway-policy");
|
|
9
|
+
const gateway_service_util_1 = require("./gateway-service-util");
|
|
8
10
|
const gateway_usage_1 = require("./gateway-usage");
|
|
9
11
|
const model_proxy_1 = require("./model-proxy");
|
|
10
|
-
const ta_sandbox_1 = require("./ta-sandbox");
|
|
11
|
-
class GatewayCallError extends Error {
|
|
12
|
-
constructor(message, code, hint) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.code = code;
|
|
15
|
-
this.hint = hint;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.GatewayCallError = GatewayCallError;
|
|
19
12
|
const DAY = 24 * 3600000;
|
|
20
|
-
var GatewayServiceUtil;
|
|
21
|
-
(function (GatewayServiceUtil) {
|
|
22
|
-
GatewayServiceUtil.DEFAULT_LOG_LINES = 200;
|
|
23
|
-
GatewayServiceUtil.MAX_LOG_LINES = 2000;
|
|
24
|
-
/**
|
|
25
|
-
* Who may call each method: `anyone` signed in (about their own Ta, their own sign-ins), `admin` (owners too),
|
|
26
|
-
* `owner`. A method not here is no method. What an admin may do to another account is checked again by its role
|
|
27
|
-
* (GatewayService.manage).
|
|
28
|
-
*/
|
|
29
|
-
GatewayServiceUtil.RULES = {
|
|
30
|
-
TaGatewayServer: {
|
|
31
|
-
getGateway: 'anyone',
|
|
32
|
-
setEnvironment: 'anyone',
|
|
33
|
-
restartEnvironment: 'anyone',
|
|
34
|
-
listTenants: 'admin',
|
|
35
|
-
getConsole: 'admin',
|
|
36
|
-
getTenantAgents: 'admin',
|
|
37
|
-
getAgentActivity: 'admin',
|
|
38
|
-
getTenantLogs: 'admin',
|
|
39
|
-
getUsageTrend: 'admin',
|
|
40
|
-
getPolicy: 'admin',
|
|
41
|
-
getAudit: 'admin',
|
|
42
|
-
startTenant: 'admin',
|
|
43
|
-
stopTenant: 'admin',
|
|
44
|
-
restartTenant: 'admin',
|
|
45
|
-
createSignInLink: 'admin',
|
|
46
|
-
setTenantLimits: 'admin',
|
|
47
|
-
grantMinutes: 'admin',
|
|
48
|
-
setSuspended: 'admin',
|
|
49
|
-
setDefaultLimits: 'owner',
|
|
50
|
-
setRole: 'owner',
|
|
51
|
-
createAccessToken: 'anyone',
|
|
52
|
-
},
|
|
53
|
-
TaAccessServer: {
|
|
54
|
-
getAccess: 'anyone',
|
|
55
|
-
signOut: 'anyone',
|
|
56
|
-
bindUrl: 'admin',
|
|
57
|
-
allow: 'admin',
|
|
58
|
-
dismiss: 'admin',
|
|
59
|
-
disallow: 'admin',
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
/** What an administrator did or looked at of others: kept in the audit. */
|
|
63
|
-
GatewayServiceUtil.AUDITED = new Set([
|
|
64
|
-
'startTenant',
|
|
65
|
-
'stopTenant',
|
|
66
|
-
'restartTenant',
|
|
67
|
-
'getTenantLogs',
|
|
68
|
-
'getAgentActivity',
|
|
69
|
-
'createSignInLink',
|
|
70
|
-
'setTenantLimits',
|
|
71
|
-
'grantMinutes',
|
|
72
|
-
'setSuspended',
|
|
73
|
-
'setDefaultLimits',
|
|
74
|
-
'setRole',
|
|
75
|
-
'allow',
|
|
76
|
-
'dismiss',
|
|
77
|
-
'disallow',
|
|
78
|
-
]);
|
|
79
|
-
/** By name, own keys only: a method such as `toString` is no rule. */
|
|
80
|
-
const BY_SERVICE = new Map(Object.entries(GatewayServiceUtil.RULES).map(([service, rules]) => [service, new Map(Object.entries(rules))]));
|
|
81
|
-
function need(service, name) {
|
|
82
|
-
var _a;
|
|
83
|
-
return (_a = BY_SERVICE.get(service)) === null || _a === void 0 ? void 0 : _a.get(name);
|
|
84
|
-
}
|
|
85
|
-
GatewayServiceUtil.need = need;
|
|
86
|
-
function allowed(role, need) {
|
|
87
|
-
return need === 'anyone' || gateway_policy_1.GatewayPolicyUtil.rank(role) >= gateway_policy_1.GatewayPolicyUtil.rank(need);
|
|
88
|
-
}
|
|
89
|
-
GatewayServiceUtil.allowed = allowed;
|
|
90
|
-
/** As many lines as asked, within bounds. */
|
|
91
|
-
function lines(value) {
|
|
92
|
-
const count = Math.floor(Number(value !== null && value !== void 0 ? value : GatewayServiceUtil.DEFAULT_LOG_LINES));
|
|
93
|
-
return Number.isFinite(count) && count > 0 ? Math.min(count, GatewayServiceUtil.MAX_LOG_LINES) : GatewayServiceUtil.DEFAULT_LOG_LINES;
|
|
94
|
-
}
|
|
95
|
-
GatewayServiceUtil.lines = lines;
|
|
96
|
-
/** Days of a trend, 1 to 31. */
|
|
97
|
-
function days(value) {
|
|
98
|
-
const count = Math.floor(Number(value !== null && value !== void 0 ? value : 7));
|
|
99
|
-
return Number.isFinite(count) ? Math.min(31, Math.max(1, count)) : 7;
|
|
100
|
-
}
|
|
101
|
-
GatewayServiceUtil.days = days;
|
|
102
|
-
/** The services the gateway answers itself, not the Ta of the tenant. */
|
|
103
|
-
GatewayServiceUtil.SERVICES = Object.keys(GatewayServiceUtil.RULES);
|
|
104
|
-
function owns(method) {
|
|
105
|
-
return typeof method === 'string' && GatewayServiceUtil.SERVICES.includes(method.split('/')[0]);
|
|
106
|
-
}
|
|
107
|
-
GatewayServiceUtil.owns = owns;
|
|
108
|
-
/** Whether the text of a message may be a call of {@link SERVICES}: those that are not are not parsed. */
|
|
109
|
-
function mayOwn(text) {
|
|
110
|
-
return GatewayServiceUtil.SERVICES.some(service => text.includes(`"${service}/`));
|
|
111
|
-
}
|
|
112
|
-
GatewayServiceUtil.mayOwn = mayOwn;
|
|
113
|
-
/** The calls that send the agents a message, which the limit of messages a minute counts. */
|
|
114
|
-
GatewayServiceUtil.PROMPTS = ['TaServer/prompt', 'TaServer/steer', 'TaServer/followUp'];
|
|
115
|
-
function mayPrompt(text) {
|
|
116
|
-
return GatewayServiceUtil.PROMPTS.some(method => text.includes(`"${method}"`));
|
|
117
|
-
}
|
|
118
|
-
GatewayServiceUtil.mayPrompt = mayPrompt;
|
|
119
|
-
/** The error of a JSON-RPC answer, as ta serve sends an ApplicationError: the client reads its code and hint. */
|
|
120
|
-
function error(id, message, code, hint) {
|
|
121
|
-
return JSON.stringify({ jsonrpc: '2.0', id, error: { code: ta_protocol_1.TA_RPC_ERROR_CODE, message, data: { kind: 'application', data: { code, hint } } } });
|
|
122
|
-
}
|
|
123
|
-
GatewayServiceUtil.error = error;
|
|
124
|
-
function result(id, result) {
|
|
125
|
-
return JSON.stringify({ jsonrpc: '2.0', id, result: result !== null && result !== void 0 ? result : null });
|
|
126
|
-
}
|
|
127
|
-
GatewayServiceUtil.result = result;
|
|
128
|
-
function invalid(message, hint) {
|
|
129
|
-
return new GatewayCallError(message, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, hint);
|
|
130
|
-
}
|
|
131
|
-
function forbidden(message, hint) {
|
|
132
|
-
return new GatewayCallError(message, ta_protocol_1.TaErrorCode.FORBIDDEN, hint);
|
|
133
|
-
}
|
|
134
|
-
GatewayServiceUtil.forbidden = forbidden;
|
|
135
|
-
function choice(value, own, providers) {
|
|
136
|
-
var _a;
|
|
137
|
-
const given = (value !== null && value !== void 0 ? value : {});
|
|
138
|
-
if (typeof given.provider === 'string') {
|
|
139
|
-
if (!providers.includes(given.provider)) {
|
|
140
|
-
throw invalid(`The gateway has no provider ${given.provider} for you.`, 'Pick one of the options of getGateway.');
|
|
141
|
-
}
|
|
142
|
-
return { provider: given.provider };
|
|
143
|
-
}
|
|
144
|
-
if (given.type === 'ta') {
|
|
145
|
-
if (!own) {
|
|
146
|
-
throw invalid('This gateway runs your Ta in its own sandboxes only.', 'Pick one of the options of getGateway.');
|
|
147
|
-
}
|
|
148
|
-
let url;
|
|
149
|
-
try {
|
|
150
|
-
url = ta_sandbox_1.TaSandboxUtil.url(String((_a = given.url) !== null && _a !== void 0 ? _a : ''));
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
throw invalid(error.message, 'Write the address its Ta service is reached at, such as https://ta.example.com.');
|
|
154
|
-
}
|
|
155
|
-
if (typeof given.token !== 'string' || !given.token.trim()) {
|
|
156
|
-
throw invalid('A Ta service of your own is reached with its access token.', 'Copy it from ~/.ta/agent/serve.json there, or the link ta serve printed.');
|
|
157
|
-
}
|
|
158
|
-
return { type: 'ta', url, token: given.token.trim(), name: typeof given.name === 'string' && given.name.trim() ? given.name.trim() : undefined };
|
|
159
|
-
}
|
|
160
|
-
throw invalid('No environment was named.', 'Pass { provider } or { type: "ta", url, token }.');
|
|
161
|
-
}
|
|
162
|
-
GatewayServiceUtil.choice = choice;
|
|
163
|
-
/** What the audit says of the arguments of a call: its numbers, flags and roles, never more. */
|
|
164
|
-
function detail(method, params) {
|
|
165
|
-
const [, second] = params;
|
|
166
|
-
switch (method) {
|
|
167
|
-
case 'setTenantLimits':
|
|
168
|
-
case 'setDefaultLimits':
|
|
169
|
-
return JSON.stringify(method === 'setDefaultLimits' ? params[0] : second);
|
|
170
|
-
case 'grantMinutes':
|
|
171
|
-
case 'getTenantLogs':
|
|
172
|
-
return String(second !== null && second !== void 0 ? second : '');
|
|
173
|
-
case 'setSuspended':
|
|
174
|
-
return second ? 'suspended' : 'let go';
|
|
175
|
-
case 'setRole':
|
|
176
|
-
return String(second);
|
|
177
|
-
default:
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
GatewayServiceUtil.detail = detail;
|
|
182
|
-
})(GatewayServiceUtil || (exports.GatewayServiceUtil = GatewayServiceUtil = {}));
|
|
183
13
|
/**
|
|
184
14
|
* The calls the gateway answers on the WebSocket of a browser: TaGatewayServer, and TaAccessServer, whose
|
|
185
15
|
* accounts are those that may have a tenant here. Each method needs a role (GatewayServiceUtil.RULES); what an
|
|
@@ -188,6 +18,7 @@ var GatewayServiceUtil;
|
|
|
188
18
|
class GatewayService {
|
|
189
19
|
constructor(parts) {
|
|
190
20
|
this.models = parts.models;
|
|
21
|
+
this.egress = parts.egress;
|
|
191
22
|
this.flow = parts.flow;
|
|
192
23
|
this.tenants = parts.tenants;
|
|
193
24
|
this.environments = parts.environments;
|
|
@@ -200,17 +31,17 @@ class GatewayService {
|
|
|
200
31
|
}
|
|
201
32
|
async call(caller, method, params) {
|
|
202
33
|
const [service, name] = method.split('/');
|
|
203
|
-
const need = GatewayServiceUtil.need(service, name);
|
|
34
|
+
const need = gateway_service_util_1.GatewayServiceUtil.need(service, name);
|
|
204
35
|
if (!need) {
|
|
205
|
-
throw new GatewayCallError(`${method} is not a method of the gateway.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Call a method of TaGatewayServer or TaAccessServer.');
|
|
36
|
+
throw new gateway_service_util_1.GatewayCallError(`${method} is not a method of the gateway.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Call a method of TaGatewayServer or TaAccessServer.');
|
|
206
37
|
}
|
|
207
|
-
if (!GatewayServiceUtil.allowed(caller.role, need)) {
|
|
38
|
+
if (!gateway_service_util_1.GatewayServiceUtil.allowed(caller.role, need)) {
|
|
208
39
|
throw need === 'owner'
|
|
209
|
-
? GatewayServiceUtil.forbidden('Only owners of the gateway may do that.', 'Ask one of those of TA_GATEWAY_ADMINS.')
|
|
210
|
-
: GatewayServiceUtil.forbidden('Only administrators of the gateway may do that.', 'Ask one of its administrators.');
|
|
40
|
+
? gateway_service_util_1.GatewayServiceUtil.forbidden('Only owners of the gateway may do that.', 'Ask one of those of TA_GATEWAY_ADMINS.')
|
|
41
|
+
: gateway_service_util_1.GatewayServiceUtil.forbidden('Only administrators of the gateway may do that.', 'Ask one of its administrators.');
|
|
211
42
|
}
|
|
212
43
|
const result = await this.handle(caller, service, name, params);
|
|
213
|
-
if (GatewayServiceUtil.AUDITED.has(name)) {
|
|
44
|
+
if (gateway_service_util_1.GatewayServiceUtil.AUDITED.has(name)) {
|
|
214
45
|
this.record(caller, name, params);
|
|
215
46
|
}
|
|
216
47
|
return result;
|
|
@@ -239,6 +70,7 @@ class GatewayService {
|
|
|
239
70
|
setSuspended: () => this.setSuspended(caller, first, second),
|
|
240
71
|
setDefaultLimits: () => this.setDefaultLimits(first),
|
|
241
72
|
setRole: () => this.setRole(caller, first, second),
|
|
73
|
+
setEgressHosts: () => this.setEgressHosts(first),
|
|
242
74
|
createAccessToken: () => this.accessToken(caller, first),
|
|
243
75
|
}
|
|
244
76
|
: {
|
|
@@ -257,7 +89,7 @@ class GatewayService {
|
|
|
257
89
|
const [first] = params;
|
|
258
90
|
const target = typeof first === 'string' ? ((_b = (_a = this.tenants.get(first)) === null || _a === void 0 ? void 0 : _a.account) !== null && _b !== void 0 ? _b : (/^[a-z][a-z0-9-]*:\S+$/.test(first) ? first : undefined)) : undefined;
|
|
259
91
|
try {
|
|
260
|
-
this.audit.add({ actor: caller.account, action, target, detail: GatewayServiceUtil.detail(action, params) });
|
|
92
|
+
this.audit.add({ actor: caller.account, action, target, detail: gateway_service_util_1.GatewayServiceUtil.detail(action, params) });
|
|
261
93
|
}
|
|
262
94
|
catch (error) {
|
|
263
95
|
console.warn(`ta gateway: the audit could not be written: ${error.message}`);
|
|
@@ -284,7 +116,7 @@ class GatewayService {
|
|
|
284
116
|
var _a;
|
|
285
117
|
const tenant = (_a = this.tenants.get(caller.tenant.id)) !== null && _a !== void 0 ? _a : caller.tenant;
|
|
286
118
|
const limits = this.quotas.limits(tenant);
|
|
287
|
-
const choice = GatewayServiceUtil.choice(value, this.environments.settings.own && limits.own, this.environments.providers.map(provider => provider.id).filter(id => !limits.providers || limits.providers.includes(id)));
|
|
119
|
+
const choice = gateway_service_util_1.GatewayServiceUtil.choice(value, this.environments.settings.own && limits.own, this.environments.providers.map(provider => provider.id).filter(id => !limits.providers || limits.providers.includes(id)));
|
|
288
120
|
const next = await this.environments.change(tenant, choice);
|
|
289
121
|
caller.tenant = next;
|
|
290
122
|
// Everyone of the tenant connects again, once the browser that asked has its answer.
|
|
@@ -356,12 +188,25 @@ class GatewayService {
|
|
|
356
188
|
};
|
|
357
189
|
}
|
|
358
190
|
policyView() {
|
|
359
|
-
|
|
191
|
+
var _a;
|
|
192
|
+
return this.policy.view(this.environments.settings.idleMinutes, (_a = this.egress) === null || _a === void 0 ? void 0 : _a.settings);
|
|
193
|
+
}
|
|
194
|
+
setEgressHosts(value) {
|
|
195
|
+
try {
|
|
196
|
+
this.policy.setEgressHosts(egress_proxy_1.EgressProxyUtil.hosts(value));
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
if (error instanceof egress_proxy_1.EgressConfigError) {
|
|
200
|
+
throw new gateway_service_util_1.GatewayCallError(error.message, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Send hosts such as registry.npmjs.org, *.github.com or example.com:8443.');
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
return this.policyView();
|
|
360
205
|
}
|
|
361
206
|
tenant(id) {
|
|
362
207
|
const tenant = typeof id === 'string' ? this.tenants.get(id) : undefined;
|
|
363
208
|
if (!tenant) {
|
|
364
|
-
throw new GatewayCallError(`The gateway has no tenant ${id}.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Pick one of the tenants of getConsole.');
|
|
209
|
+
throw new gateway_service_util_1.GatewayCallError(`The gateway has no tenant ${id}.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Pick one of the tenants of getConsole.');
|
|
365
210
|
}
|
|
366
211
|
return tenant;
|
|
367
212
|
}
|
|
@@ -369,7 +214,7 @@ class GatewayService {
|
|
|
369
214
|
manage(caller, id) {
|
|
370
215
|
const tenant = this.tenant(id);
|
|
371
216
|
if (caller.role !== 'owner' && (this.quotas.role(tenant) !== 'member' || tenant.account === caller.account)) {
|
|
372
|
-
throw GatewayServiceUtil.forbidden('Admins manage members only, not themselves, other admins or owners.', 'Ask an owner of the gateway (TA_GATEWAY_ADMINS).');
|
|
217
|
+
throw gateway_service_util_1.GatewayServiceUtil.forbidden('Admins manage members only, not themselves, other admins or owners.', 'Ask an owner of the gateway (TA_GATEWAY_ADMINS).');
|
|
373
218
|
}
|
|
374
219
|
return tenant;
|
|
375
220
|
}
|
|
@@ -389,14 +234,14 @@ class GatewayService {
|
|
|
389
234
|
}
|
|
390
235
|
/** What its sandbox wrote, its secrets hidden: tokens and keys printed by what ran there do not reach the page. */
|
|
391
236
|
async logs(id, lines) {
|
|
392
|
-
return new redactor_1.Redactor().text(await this.environments.logs(this.tenant(id), GatewayServiceUtil.lines(lines)));
|
|
237
|
+
return new redactor_1.Redactor().text(await this.environments.logs(this.tenant(id), gateway_service_util_1.GatewayServiceUtil.lines(lines)));
|
|
393
238
|
}
|
|
394
239
|
activity(id, sessionId) {
|
|
395
240
|
return this.environments.activity(this.tenant(id), String(sessionId));
|
|
396
241
|
}
|
|
397
242
|
async trend(daysValue, id) {
|
|
398
243
|
const now = Date.now();
|
|
399
|
-
const days = GatewayServiceUtil.days(daysValue);
|
|
244
|
+
const days = gateway_service_util_1.GatewayServiceUtil.days(daysValue);
|
|
400
245
|
const tenants = id === undefined || id === null ? this.tenants.list() : [this.tenant(id)];
|
|
401
246
|
const fresh = await Promise.all(tenants.map(tenant => this.usage.refresh(tenant.id, this.environments.usageReader(tenant), now, 0).catch(() => false)));
|
|
402
247
|
const byTenant = new Map();
|
|
@@ -420,7 +265,7 @@ class GatewayService {
|
|
|
420
265
|
}
|
|
421
266
|
catch (error) {
|
|
422
267
|
if (error instanceof gateway_policy_1.PolicyError) {
|
|
423
|
-
throw new GatewayCallError(error.message, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Send the limits again, written well.');
|
|
268
|
+
throw new gateway_service_util_1.GatewayCallError(error.message, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Send the limits again, written well.');
|
|
424
269
|
}
|
|
425
270
|
throw error;
|
|
426
271
|
}
|
|
@@ -432,7 +277,7 @@ class GatewayService {
|
|
|
432
277
|
grantMinutes(caller, id, minutes) {
|
|
433
278
|
const tenant = this.manage(caller, id);
|
|
434
279
|
if (typeof minutes !== 'number' || !Number.isInteger(minutes) || Math.abs(minutes) > 1000000) {
|
|
435
|
-
throw new GatewayCallError('Minutes are a whole number.', ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Give, say, 60; a negative number takes some back.');
|
|
280
|
+
throw new gateway_service_util_1.GatewayCallError('Minutes are a whole number.', ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Give, say, 60; a negative number takes some back.');
|
|
436
281
|
}
|
|
437
282
|
this.quotas.grant(tenant, minutes);
|
|
438
283
|
}
|
|
@@ -451,13 +296,13 @@ class GatewayService {
|
|
|
451
296
|
setRole(caller, account, role) {
|
|
452
297
|
const id = typeof account === 'string' ? account.trim() : '';
|
|
453
298
|
if (role !== 'admin' && role !== 'member') {
|
|
454
|
-
throw new GatewayCallError('A role is admin or member.', ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Owners are those of TA_GATEWAY_ADMINS.');
|
|
299
|
+
throw new gateway_service_util_1.GatewayCallError('A role is admin or member.', ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Owners are those of TA_GATEWAY_ADMINS.');
|
|
455
300
|
}
|
|
456
301
|
if (this.policy.role(id) === 'owner') {
|
|
457
|
-
throw GatewayServiceUtil.forbidden('An owner stays one: they are of TA_GATEWAY_ADMINS.', 'Change TA_GATEWAY_ADMINS where the gateway runs.');
|
|
302
|
+
throw gateway_service_util_1.GatewayServiceUtil.forbidden('An owner stays one: they are of TA_GATEWAY_ADMINS.', 'Change TA_GATEWAY_ADMINS where the gateway runs.');
|
|
458
303
|
}
|
|
459
304
|
if (id === caller.account || !this.tenants.list().some(tenant => tenant.account === id)) {
|
|
460
|
-
throw new GatewayCallError(`${id} has not signed in to the gateway.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Make an account that signed in an admin.');
|
|
305
|
+
throw new gateway_service_util_1.GatewayCallError(`${id} has not signed in to the gateway.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Make an account that signed in an admin.');
|
|
461
306
|
}
|
|
462
307
|
this.policy.setRole(id, role);
|
|
463
308
|
return this.policyView();
|
|
@@ -481,7 +326,7 @@ class GatewayService {
|
|
|
481
326
|
}
|
|
482
327
|
allow(account, name) {
|
|
483
328
|
if (typeof account !== 'string' || !/^[a-z][a-z0-9-]*:\S+$/.test(account.trim())) {
|
|
484
|
-
throw new GatewayCallError(`${account} is not an account.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Write it <provider>:<login or address>, such as github:octocat.');
|
|
329
|
+
throw new gateway_service_util_1.GatewayCallError(`${account} is not an account.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Write it <provider>:<login or address>, such as github:octocat.');
|
|
485
330
|
}
|
|
486
331
|
this.flow.store.allow(account.trim(), typeof name === 'string' ? name : undefined);
|
|
487
332
|
}
|
|
@@ -490,7 +335,7 @@ class GatewayService {
|
|
|
490
335
|
const normalized = access_store_1.AccessUtil.normalize(account);
|
|
491
336
|
const role = this.policy.role(normalized);
|
|
492
337
|
if (role === 'owner' || (role === 'admin' && caller.role !== 'owner')) {
|
|
493
|
-
throw GatewayServiceUtil.forbidden(role === 'owner' ? 'Owners are let in where the gateway runs (TA_GATEWAY_ADMINS).' : 'Only owners remove an admin.', 'Ask an owner of the gateway.');
|
|
338
|
+
throw gateway_service_util_1.GatewayServiceUtil.forbidden(role === 'owner' ? 'Owners are let in where the gateway runs (TA_GATEWAY_ADMINS).' : 'Only owners remove an admin.', 'Ask an owner of the gateway.');
|
|
494
339
|
}
|
|
495
340
|
if (role === 'admin') {
|
|
496
341
|
this.policy.setRole(normalized, 'member');
|
|
@@ -508,7 +353,7 @@ class GatewayService {
|
|
|
508
353
|
async signOut(caller, id) {
|
|
509
354
|
const own = this.flow.store.info(caller.token).signIns.find(signIn => signIn.id === id);
|
|
510
355
|
if (!caller.admin && (own === null || own === void 0 ? void 0 : own.account) !== caller.account) {
|
|
511
|
-
throw GatewayServiceUtil.forbidden('That sign-in is not yours.', 'Sign out of the browsers of your own account.');
|
|
356
|
+
throw gateway_service_util_1.GatewayServiceUtil.forbidden('That sign-in is not yours.', 'Sign out of the browsers of your own account.');
|
|
512
357
|
}
|
|
513
358
|
this.flow.store.signOut(id);
|
|
514
359
|
this.hooks.cutOff();
|
|
@@ -520,10 +365,10 @@ class GatewayService {
|
|
|
520
365
|
signInLink(account, name) {
|
|
521
366
|
const id = typeof account === 'string' ? account.trim() : '';
|
|
522
367
|
if (!/^[a-z][a-z0-9-]*:\S+$/.test(id)) {
|
|
523
|
-
throw new GatewayCallError(`${account} is not an account.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Write it <kind>:<name>, such as github:octocat or user:alice.');
|
|
368
|
+
throw new gateway_service_util_1.GatewayCallError(`${account} is not an account.`, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, 'Write it <kind>:<name>, such as github:octocat or user:alice.');
|
|
524
369
|
}
|
|
525
370
|
if (this.tenants.list().some(tenant => tenant.account === id) || this.policy.role(id) !== 'member') {
|
|
526
|
-
throw GatewayServiceUtil.forbidden(`${id} has been here already: a link would sign whoever opens it in as them.`, 'Invite accounts that are new; one that has been here signs in its own way.');
|
|
371
|
+
throw gateway_service_util_1.GatewayServiceUtil.forbidden(`${id} has been here already: a link would sign whoever opens it in as them.`, 'Invite accounts that are new; one that has been here signs in its own way.');
|
|
527
372
|
}
|
|
528
373
|
return this.meta.links.create(id, typeof name === 'string' && name.trim() ? name.trim() : undefined);
|
|
529
374
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
|
|
2
2
|
import type { Environments } from './environments';
|
|
3
3
|
import type { GatewayQuotas } from './gateway-quotas';
|
|
4
|
-
import {
|
|
4
|
+
import type { GatewayCaller, GatewayService } from './gateway-service';
|
|
5
5
|
/**
|
|
6
6
|
* One browser's WebSocket: the calls of the gateway's services answered here, everything else forwarded to
|
|
7
7
|
* the Ta of its tenant, whose token only the gateway has, and back. Until that Ta answers, what the browser
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GatewaySocket = void 0;
|
|
4
4
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
5
|
-
const
|
|
5
|
+
const gateway_service_util_1 = require("./gateway-service-util");
|
|
6
6
|
/** What a browser sends before the Ta of its tenant answers, at most: then it is cut off, to connect again. */
|
|
7
7
|
const MAX_QUEUED = 256;
|
|
8
8
|
/** And as many bytes at most: a message may be 32 MB, and 256 of them would hold the gateway's memory for one browser. */
|
|
@@ -90,11 +90,11 @@ class GatewaySocket {
|
|
|
90
90
|
this.close(1008, 'Too many messages.');
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
if (this.failure === undefined &&
|
|
93
|
+
if (this.failure === undefined && gateway_service_util_1.GatewayServiceUtil.mayPrompt(text) && !this.admitPrompt(text)) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
// Most messages are the Ta's, some large (pictures): forwarded without being read.
|
|
97
|
-
if (this.failure === undefined && !
|
|
97
|
+
if (this.failure === undefined && !gateway_service_util_1.GatewayServiceUtil.mayOwn(text)) {
|
|
98
98
|
this.forward(text);
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
@@ -106,13 +106,13 @@ class GatewaySocket {
|
|
|
106
106
|
this.close(1007, 'Not JSON.');
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
|
-
if (
|
|
109
|
+
if (gateway_service_util_1.GatewayServiceUtil.owns(message.method)) {
|
|
110
110
|
void this.answer(message.id, message.method, Array.isArray(message.params) ? message.params : []);
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
113
|
if (this.failure !== undefined) {
|
|
114
114
|
if (message.method !== undefined && message.id !== undefined) {
|
|
115
|
-
this.browser.send(
|
|
115
|
+
this.browser.send(gateway_service_util_1.GatewayServiceUtil.error(message.id, `Your environment did not start: ${this.failure}`, ta_protocol_1.TaErrorCode.ENVIRONMENT_FAILED, 'Restart it, or pick another (TaGatewayServer).'));
|
|
116
116
|
}
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
@@ -127,7 +127,7 @@ class GatewaySocket {
|
|
|
127
127
|
catch (_a) {
|
|
128
128
|
return true;
|
|
129
129
|
}
|
|
130
|
-
if (typeof message.method !== 'string' || !
|
|
130
|
+
if (typeof message.method !== 'string' || !gateway_service_util_1.GatewayServiceUtil.PROMPTS.includes(message.method) || !this.quotas) {
|
|
131
131
|
return true;
|
|
132
132
|
}
|
|
133
133
|
if (this.quotas.takePrompt(this.caller.tenant)) {
|
|
@@ -135,7 +135,7 @@ class GatewaySocket {
|
|
|
135
135
|
}
|
|
136
136
|
const seconds = Math.ceil(this.quotas.retryAfter(this.caller.tenant) / 1000);
|
|
137
137
|
if (message.id !== undefined) {
|
|
138
|
-
this.browser.send(
|
|
138
|
+
this.browser.send(gateway_service_util_1.GatewayServiceUtil.error(message.id, `You sent as many messages this minute as your account may (${this.quotas.limits(this.caller.tenant).promptsPerMinute}).`, ta_protocol_1.TaErrorCode.RATE_LIMITED, `Send it again in ${seconds} s.`));
|
|
139
139
|
}
|
|
140
140
|
return false;
|
|
141
141
|
}
|
|
@@ -156,11 +156,11 @@ class GatewaySocket {
|
|
|
156
156
|
let reply;
|
|
157
157
|
this.answering++;
|
|
158
158
|
try {
|
|
159
|
-
reply =
|
|
159
|
+
reply = gateway_service_util_1.GatewayServiceUtil.result(id, await this.service.call(this.caller, method, params));
|
|
160
160
|
}
|
|
161
161
|
catch (error) {
|
|
162
|
-
const known = error instanceof
|
|
163
|
-
reply =
|
|
162
|
+
const known = error instanceof gateway_service_util_1.GatewayCallError;
|
|
163
|
+
reply = gateway_service_util_1.GatewayServiceUtil.error(id, error.message, known ? error.code : ta_protocol_1.TaErrorCode.COMMAND_FAILED, known ? error.hint : 'The gateway could not do it; try again.');
|
|
164
164
|
}
|
|
165
165
|
this.answering--;
|
|
166
166
|
if (id !== undefined && this.browser.open) {
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export * from './command-sandbox';
|
|
2
2
|
export * from './docker-engine';
|
|
3
3
|
export * from './docker-sandbox';
|
|
4
|
+
export * from './egress-proxy';
|
|
4
5
|
export * from './environments';
|
|
5
6
|
export * from './gateway-cli';
|
|
6
7
|
export * from './gateway-server';
|
|
7
8
|
export * from './gateway-service';
|
|
9
|
+
export * from './gateway-service-util';
|
|
8
10
|
export * from './gateway-socket';
|
|
11
|
+
export * from './kubernetes-api';
|
|
12
|
+
export * from './kubernetes-sandbox';
|
|
9
13
|
export * from './local-sandbox';
|
|
10
14
|
export * from './sandbox-provider';
|
|
11
15
|
export * from './sign-in-links';
|
package/lib/node/index.js
CHANGED
|
@@ -17,11 +17,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./command-sandbox"), exports);
|
|
18
18
|
__exportStar(require("./docker-engine"), exports);
|
|
19
19
|
__exportStar(require("./docker-sandbox"), exports);
|
|
20
|
+
__exportStar(require("./egress-proxy"), exports);
|
|
20
21
|
__exportStar(require("./environments"), exports);
|
|
21
22
|
__exportStar(require("./gateway-cli"), exports);
|
|
22
23
|
__exportStar(require("./gateway-server"), exports);
|
|
23
24
|
__exportStar(require("./gateway-service"), exports);
|
|
25
|
+
__exportStar(require("./gateway-service-util"), exports);
|
|
24
26
|
__exportStar(require("./gateway-socket"), exports);
|
|
27
|
+
__exportStar(require("./kubernetes-api"), exports);
|
|
28
|
+
__exportStar(require("./kubernetes-sandbox"), exports);
|
|
25
29
|
__exportStar(require("./local-sandbox"), exports);
|
|
26
30
|
__exportStar(require("./sandbox-provider"), exports);
|
|
27
31
|
__exportStar(require("./sign-in-links"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare class KubernetesError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
constructor(status: number, message: string);
|
|
4
|
+
}
|
|
5
|
+
/** The calls a provider makes: a JSON body or text back; KubernetesError for an answer not 2xx. */
|
|
6
|
+
export interface KubernetesCalls {
|
|
7
|
+
call<T = unknown>(method: string, path: string, body?: unknown, type?: string): Promise<T>;
|
|
8
|
+
text(path: string): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
export interface KubernetesApiOptions {
|
|
11
|
+
/** https://<host>:<port> of the API server. */
|
|
12
|
+
server: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
/** The CA of the server, PEM. */
|
|
15
|
+
ca?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The API of a cluster over HTTPS, without a client library: what a provider of sandboxes needs is a few
|
|
19
|
+
* resources by their paths.
|
|
20
|
+
*/
|
|
21
|
+
export declare class KubernetesApi implements KubernetesCalls {
|
|
22
|
+
protected readonly options: KubernetesApiOptions;
|
|
23
|
+
/** In a pod of the cluster: its service account, and the namespace it runs in. */
|
|
24
|
+
static inCluster(env?: Record<string, string | undefined>, read?: (path: string) => string): KubernetesApiOptions & {
|
|
25
|
+
namespace: string;
|
|
26
|
+
};
|
|
27
|
+
constructor(options: KubernetesApiOptions);
|
|
28
|
+
call<T = unknown>(method: string, path: string, body?: unknown, type?: string): Promise<T>;
|
|
29
|
+
text(path: string): Promise<string>;
|
|
30
|
+
protected send(method: string, path: string, body?: string, type?: string): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
export declare namespace KubernetesUtil {
|
|
33
|
+
/** A quantity of Kubernetes (`4Gi`, `500M`, `250m`, `123456n`) as a number of its unit (bytes, CPUs). */
|
|
34
|
+
function quantity(value: string | number | undefined): number | undefined;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=kubernetes-api.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KubernetesUtil = exports.KubernetesApi = exports.KubernetesError = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_http_1 = require("node:http");
|
|
6
|
+
const node_https_1 = require("node:https");
|
|
7
|
+
/** Where a pod finds the API of its cluster: its service account's token, CA and namespace. */
|
|
8
|
+
const ACCOUNT = '/var/run/secrets/kubernetes.io/serviceaccount';
|
|
9
|
+
class KubernetesError extends Error {
|
|
10
|
+
constructor(status, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.KubernetesError = KubernetesError;
|
|
16
|
+
/**
|
|
17
|
+
* The API of a cluster over HTTPS, without a client library: what a provider of sandboxes needs is a few
|
|
18
|
+
* resources by their paths.
|
|
19
|
+
*/
|
|
20
|
+
class KubernetesApi {
|
|
21
|
+
/** In a pod of the cluster: its service account, and the namespace it runs in. */
|
|
22
|
+
static inCluster(env = process.env, read = (path) => (0, node_fs_1.readFileSync)(path, 'utf8')) {
|
|
23
|
+
var _a;
|
|
24
|
+
const host = env.KUBERNETES_SERVICE_HOST;
|
|
25
|
+
if (!host) {
|
|
26
|
+
throw new Error('Not in a pod of Kubernetes (no KUBERNETES_SERVICE_HOST): give "server" and "token" of the cluster.');
|
|
27
|
+
}
|
|
28
|
+
const port = (_a = env.KUBERNETES_SERVICE_PORT) !== null && _a !== void 0 ? _a : '443';
|
|
29
|
+
return {
|
|
30
|
+
server: `https://${host.includes(':') ? `[${host}]` : host}:${port}`,
|
|
31
|
+
token: read(`${ACCOUNT}/token`).trim(),
|
|
32
|
+
ca: read(`${ACCOUNT}/ca.crt`),
|
|
33
|
+
namespace: read(`${ACCOUNT}/namespace`).trim(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
}
|
|
39
|
+
async call(method, path, body, type = 'application/json') {
|
|
40
|
+
const text = await this.send(method, path, body === undefined ? undefined : JSON.stringify(body), type);
|
|
41
|
+
return (text ? JSON.parse(text) : undefined);
|
|
42
|
+
}
|
|
43
|
+
text(path) {
|
|
44
|
+
return this.send('GET', path);
|
|
45
|
+
}
|
|
46
|
+
send(method, path, body, type) {
|
|
47
|
+
const url = new URL(path, this.options.server);
|
|
48
|
+
const options = {
|
|
49
|
+
method,
|
|
50
|
+
headers: {
|
|
51
|
+
accept: 'application/json, */*',
|
|
52
|
+
...(this.options.token ? { authorization: `Bearer ${this.options.token}` } : {}),
|
|
53
|
+
...(body !== undefined ? { 'content-type': type !== null && type !== void 0 ? type : 'application/json', 'content-length': Buffer.byteLength(body) } : {}),
|
|
54
|
+
},
|
|
55
|
+
...(this.options.ca ? { ca: this.options.ca } : {}),
|
|
56
|
+
timeout: 30000,
|
|
57
|
+
};
|
|
58
|
+
const send = url.protocol === 'https:' ? node_https_1.request : node_http_1.request;
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const request = send(url, options, response => {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
response.on('data', chunk => chunks.push(chunk));
|
|
63
|
+
response.on('end', () => {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
66
|
+
const status = (_a = response.statusCode) !== null && _a !== void 0 ? _a : 0;
|
|
67
|
+
if (status >= 200 && status < 300) {
|
|
68
|
+
resolve(text);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let message = text.slice(0, 300);
|
|
72
|
+
try {
|
|
73
|
+
message = (_b = JSON.parse(text).message) !== null && _b !== void 0 ? _b : message;
|
|
74
|
+
}
|
|
75
|
+
catch (_c) {
|
|
76
|
+
// Not JSON.
|
|
77
|
+
}
|
|
78
|
+
reject(new KubernetesError(status, `${method} ${url.pathname}: ${status} ${message}`));
|
|
79
|
+
});
|
|
80
|
+
response.on('error', reject);
|
|
81
|
+
});
|
|
82
|
+
request.on('timeout', () => request.destroy(new Error(`${method} ${url.pathname}: no answer in time`)));
|
|
83
|
+
request.on('error', reject);
|
|
84
|
+
request.end(body);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.KubernetesApi = KubernetesApi;
|
|
89
|
+
var KubernetesUtil;
|
|
90
|
+
(function (KubernetesUtil) {
|
|
91
|
+
/** A quantity of Kubernetes (`4Gi`, `500M`, `250m`, `123456n`) as a number of its unit (bytes, CPUs). */
|
|
92
|
+
function quantity(value) {
|
|
93
|
+
if (typeof value === 'number') {
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
const match = /^([0-9.]+)([a-zA-Z]*)$/.exec(String(value !== null && value !== void 0 ? value : '').trim());
|
|
97
|
+
if (!match) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const scale = {
|
|
101
|
+
'': 1,
|
|
102
|
+
n: 1e-9,
|
|
103
|
+
u: 1e-6,
|
|
104
|
+
m: 1e-3,
|
|
105
|
+
k: 1e3,
|
|
106
|
+
K: 1e3,
|
|
107
|
+
M: 1e6,
|
|
108
|
+
G: 1e9,
|
|
109
|
+
T: 1e12,
|
|
110
|
+
Ki: 2 ** 10,
|
|
111
|
+
Mi: 2 ** 20,
|
|
112
|
+
Gi: 2 ** 30,
|
|
113
|
+
Ti: 2 ** 40,
|
|
114
|
+
};
|
|
115
|
+
const factor = scale[match[2]];
|
|
116
|
+
return factor === undefined ? undefined : Number(match[1]) * factor;
|
|
117
|
+
}
|
|
118
|
+
KubernetesUtil.quantity = quantity;
|
|
119
|
+
})(KubernetesUtil || (exports.KubernetesUtil = KubernetesUtil = {}));
|
|
120
|
+
//# sourceMappingURL=kubernetes-api.js.map
|