@compforge/harness-toolbox 0.3.10 → 0.4.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.md +76 -0
- package/dist/{chunk-p6k59m3q.js → chunk-0s27bgga.js} +9 -4
- package/dist/{chunk-zhkrydeg.js → chunk-20kv4wc3.js} +4 -1
- package/dist/chunk-4ms037k2.js +210 -0
- package/dist/{chunk-b7f39m4v.js → chunk-8mb6natq.js} +1 -1
- package/dist/chunk-ba883sdp.js +60 -0
- package/dist/chunk-ftkrjqkc.js +15 -0
- package/dist/{chunk-ahc00qs5.js → chunk-h73h2b7y.js} +5 -5
- package/dist/chunk-mxyvpy79.js +62 -0
- package/dist/chunk-mzdz6wwc.js +91 -0
- package/dist/{chunk-y94xq8b4.js → chunk-y529s0mz.js} +26 -11
- package/dist/datasource.js +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +4 -2
- package/dist/file/client.d.ts +17 -0
- package/dist/file/client.js +10 -0
- package/dist/file/index.d.ts +5 -0
- package/dist/file/index.js +24 -0
- package/dist/file/local.d.ts +13 -0
- package/dist/file/local.js +11 -0
- package/dist/file/pod.d.ts +31 -0
- package/dist/file/pod.js +11 -0
- package/dist/kubernetes/client.d.ts +12 -4
- package/dist/kubernetes/client.js +6 -4
- package/dist/kubernetes/environment.d.ts +2 -2
- package/dist/kubernetes/environment.js +5 -4
- package/dist/kubernetes/pod-log-datasource.js +1 -1
- package/dist/kubernetes/resource-transport.d.ts +19 -0
- package/dist/kubernetes/resource-transport.js +10 -0
- package/dist/kubernetes/resources.d.ts +45 -5
- package/dist/kubernetes/resources.js +4 -5
- package/dist/kubernetes/workload.js +2 -2
- package/dist/mysql/client.js +3 -3
- package/dist/mysql/index.js +12 -12
- package/dist/opensearch/client.js +2 -2
- package/dist/opensearch/index.js +7 -7
- package/dist/s3/datasource.js +1 -1
- package/dist/s3/index.js +1 -1
- package/package.json +6 -2
- package/dist/chunk-fhtbvj0s.js +0 -89
package/dist/chunk-fhtbvj0s.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
KubernetesError,
|
|
3
|
-
ToolboxError,
|
|
4
|
-
kubernetesHttpError
|
|
5
|
-
} from "./chunk-zhkrydeg.js";
|
|
6
|
-
import {
|
|
7
|
-
ConcurrencyPool
|
|
8
|
-
} from "./chunk-v3hxvnrc.js";
|
|
9
|
-
|
|
10
|
-
// src/kubernetes/resources.ts
|
|
11
|
-
import { KubeConfig } from "@kubernetes/client-node";
|
|
12
|
-
import fetch from "node-fetch/lib/index.js";
|
|
13
|
-
function resourceAccess(options, signal, limits) {
|
|
14
|
-
if (![limits.timeoutMs, limits.concurrency, limits.maxBytes].every((value) => Number.isSafeInteger(value) && value > 0)) {
|
|
15
|
-
throw new KubernetesError("Resource limits must be positive integers", { kind: "invalid_argument" });
|
|
16
|
-
}
|
|
17
|
-
const config = new KubeConfig;
|
|
18
|
-
try {
|
|
19
|
-
if (options.kubeconfig)
|
|
20
|
-
config.loadFromFile(options.kubeconfig);
|
|
21
|
-
else
|
|
22
|
-
config.loadFromDefault();
|
|
23
|
-
if (options.context)
|
|
24
|
-
config.setCurrentContext(options.context);
|
|
25
|
-
} catch (cause) {
|
|
26
|
-
throw new KubernetesError("Cannot load Kubernetes access configuration", { kind: "connection_failed", cause });
|
|
27
|
-
}
|
|
28
|
-
const cluster = config.getCurrentCluster();
|
|
29
|
-
if (!cluster)
|
|
30
|
-
throw new KubernetesError("Kubernetes context has no cluster", { kind: "invalid_argument" });
|
|
31
|
-
if (new URL(cluster.server).protocol === "http:") {
|
|
32
|
-
config.clusters = config.clusters.map((item) => item === cluster ? { ...item, skipTLSVerify: true } : item);
|
|
33
|
-
}
|
|
34
|
-
const pool = new ConcurrencyPool(limits.concurrency);
|
|
35
|
-
return {
|
|
36
|
-
get: (namespace, resource, name, selector) => pool.run(async () => {
|
|
37
|
-
const group = ["pods", "services"].includes(resource) ? "/api/v1" : "/apis/apps/v1";
|
|
38
|
-
const path = group + "/namespaces/" + encodeURIComponent(namespace) + "/" + resource + (name ? "/" + encodeURIComponent(name) : "");
|
|
39
|
-
const url = new URL(cluster.server.replace(/\/$/, "") + path);
|
|
40
|
-
if (selector)
|
|
41
|
-
url.searchParams.set("labelSelector", selector);
|
|
42
|
-
const controller = new AbortController;
|
|
43
|
-
const abort = () => controller.abort(signal.reason);
|
|
44
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
45
|
-
let timedOut = false;
|
|
46
|
-
const timer = setTimeout(() => {
|
|
47
|
-
timedOut = true;
|
|
48
|
-
controller.abort();
|
|
49
|
-
}, limits.timeoutMs);
|
|
50
|
-
try {
|
|
51
|
-
signal.throwIfAborted();
|
|
52
|
-
const init = await config.applyToFetchOptions({});
|
|
53
|
-
controller.signal.throwIfAborted();
|
|
54
|
-
const response = await fetch(url.href, { ...init, signal: controller.signal, size: limits.maxBytes });
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
controller.abort();
|
|
57
|
-
const error = kubernetesHttpError(response.status);
|
|
58
|
-
throw new KubernetesError("Read " + resource + " in namespace " + namespace + " failed", { kind: error.kind, code: error.code });
|
|
59
|
-
}
|
|
60
|
-
return await response.json();
|
|
61
|
-
} catch (cause) {
|
|
62
|
-
if (signal.aborted)
|
|
63
|
-
throw signal.reason;
|
|
64
|
-
if (cause instanceof ToolboxError)
|
|
65
|
-
throw cause;
|
|
66
|
-
const type = cause && typeof cause === "object" && "type" in cause ? cause.type : undefined;
|
|
67
|
-
const code = cause && typeof cause === "object" && "code" in cause && typeof cause.code === "string" ? cause.code : undefined;
|
|
68
|
-
const tls = code !== undefined && [
|
|
69
|
-
"CERT_HAS_EXPIRED",
|
|
70
|
-
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
71
|
-
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
72
|
-
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
73
|
-
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
74
|
-
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
75
|
-
].includes(code);
|
|
76
|
-
throw new KubernetesError("Read " + resource + " in namespace " + namespace + " failed", {
|
|
77
|
-
kind: timedOut ? "timeout" : type === "max-size" ? "limit_exceeded" : type === "invalid-json" ? "invalid_response" : tls ? "tls_verification_failed" : code === "ECONNRESET" ? "connection_lost" : "connection_failed",
|
|
78
|
-
cause,
|
|
79
|
-
code
|
|
80
|
-
});
|
|
81
|
-
} finally {
|
|
82
|
-
clearTimeout(timer);
|
|
83
|
-
signal.removeEventListener("abort", abort);
|
|
84
|
-
}
|
|
85
|
-
}, signal)
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { resourceAccess };
|