mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Release 6.1.17 (#6538)
* Release 6.1.17 Signed-off-by: Sebastian Malton <sebastian@malton.name> * Improve unix shell env sync error logging (#6531) Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix computeUnixShellEnv tests (#6532) Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix jsonPath functions (#6530) * Fix jsonPath functions - Add handling of / shorthand - Update tests to show new behaviour of safeJSONPathValue so that it is more usable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Defend CRDResourceDetails against bad jsonPaths Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update CRDResources for new behaviour of helper function Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix installing extension dependencies (#6537) - The --only option was removed in v7 and the --omit option was introduced then too. Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ce38d7025e
commit
f87a29052c
@ -3,7 +3,7 @@
|
|||||||
"productName": "OpenLens",
|
"productName": "OpenLens",
|
||||||
"description": "OpenLens - Open Source IDE for Kubernetes",
|
"description": "OpenLens - Open Source IDE for Kubernetes",
|
||||||
"homepage": "https://github.com/lensapp/lens",
|
"homepage": "https://github.com/lensapp/lens",
|
||||||
"version": "6.1.16",
|
"version": "6.1.17",
|
||||||
"main": "static/build/main.js",
|
"main": "static/build/main.js",
|
||||||
"copyright": "© 2022 OpenLens Authors",
|
"copyright": "© 2022 OpenLens Authors",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@ -16,6 +16,16 @@ interface Dependencies {
|
|||||||
extensionPackageRootDirectory: string;
|
extensionPackageRootDirectory: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseNpmInstallArgs = [
|
||||||
|
"install",
|
||||||
|
"--audit=false",
|
||||||
|
"--fund=false",
|
||||||
|
"--omit=dev",
|
||||||
|
"--omit=optional",
|
||||||
|
"--omit=peer",
|
||||||
|
"--prefer-offline",
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs dependencies for extensions
|
* Installs dependencies for extensions
|
||||||
*/
|
*/
|
||||||
@ -42,7 +52,7 @@ export class ExtensionInstaller {
|
|||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`${logModule} installing dependencies at ${this.dependencies.extensionPackageRootDirectory}`);
|
logger.info(`${logModule} installing dependencies at ${this.dependencies.extensionPackageRootDirectory}`);
|
||||||
await this.npm(["install", "--audit=false", "--fund=false", "--only=prod", "--prefer-offline"]);
|
await this.npm(...baseNpmInstallArgs);
|
||||||
logger.info(`${logModule} dependencies installed at ${this.dependencies.extensionPackageRootDirectory}`);
|
logger.info(`${logModule} dependencies installed at ${this.dependencies.extensionPackageRootDirectory}`);
|
||||||
} finally {
|
} finally {
|
||||||
this.installLock.release();
|
this.installLock.release();
|
||||||
@ -58,14 +68,14 @@ export class ExtensionInstaller {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info(`${logModule} installing package from ${name} to ${this.dependencies.extensionPackageRootDirectory}`);
|
logger.info(`${logModule} installing package from ${name} to ${this.dependencies.extensionPackageRootDirectory}`);
|
||||||
await this.npm(["install", "--audit=false", "--fund=false", "--only=prod", "--prefer-offline", name]);
|
await this.npm(...baseNpmInstallArgs, name);
|
||||||
logger.info(`${logModule} package ${name} installed to ${this.dependencies.extensionPackageRootDirectory}`);
|
logger.info(`${logModule} package ${name} installed to ${this.dependencies.extensionPackageRootDirectory}`);
|
||||||
} finally {
|
} finally {
|
||||||
this.installLock.release();
|
this.installLock.release();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private npm(args: string[]): Promise<void> {
|
private npm(...args: string[]): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = child_process.fork(this.npmPath, args, {
|
const child = child_process.fork(this.npmPath, args, {
|
||||||
cwd: this.dependencies.extensionPackageRootDirectory,
|
cwd: this.dependencies.extensionPackageRootDirectory,
|
||||||
|
|||||||
@ -110,25 +110,37 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
|
|||||||
const stdout: Buffer[] = [];
|
const stdout: Buffer[] = [];
|
||||||
const stderr: Buffer[] = [];
|
const stderr: Buffer[] = [];
|
||||||
|
|
||||||
shellProcess.stdout.on("data", b => stdout.push(b));
|
const getErrorContext = (other: object = {}) => {
|
||||||
shellProcess.stderr.on("data", b => stderr.push(b));
|
|
||||||
|
|
||||||
shellProcess.on("error", (err) => resolve({
|
|
||||||
callWasSuccessful: false,
|
|
||||||
error: `Failed to spawn ${shellPath}: ${err}`,
|
|
||||||
}));
|
|
||||||
shellProcess.on("close", (code, signal) => {
|
|
||||||
if (code || signal) {
|
|
||||||
const context = {
|
const context = {
|
||||||
code,
|
...other,
|
||||||
signal,
|
|
||||||
stdout: Buffer.concat(stdout).toString("utf-8"),
|
stdout: Buffer.concat(stdout).toString("utf-8"),
|
||||||
stderr: Buffer.concat(stderr).toString("utf-8"),
|
stderr: Buffer.concat(stderr).toString("utf-8"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return JSON.stringify(context, null, 4);
|
||||||
|
};
|
||||||
|
|
||||||
|
shellProcess.stdout.on("data", b => stdout.push(b));
|
||||||
|
shellProcess.stderr.on("data", b => stderr.push(b));
|
||||||
|
|
||||||
|
shellProcess.on("error", (error) => {
|
||||||
|
if (opts.signal.aborted) {
|
||||||
|
resolve({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: `timeout: ${getErrorContext()}`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: `Failed to spawn ${shellPath}: ${getErrorContext({ error: String(error) })}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
shellProcess.on("close", (code, signal) => {
|
||||||
|
if (code || signal) {
|
||||||
return resolve({
|
return resolve({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: `Shell did not exit sucessfully: ${JSON.stringify(context, null, 4)}`,
|
error: `Shell did not exit sucessfully: ${getErrorContext({ code, signal })}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -127,7 +127,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
it("should resolve with a failed call", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).resolves.toEqual({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
error: `Failed to spawn ${shellPath}: ${JSON.stringify({
|
||||||
|
error: "Error: some-error",
|
||||||
|
stdout: "",
|
||||||
|
stderr: "",
|
||||||
|
}, null, 4)}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -229,7 +233,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
it("should resolve with a failed call", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).resolves.toEqual({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
error: `Failed to spawn ${shellPath}: ${JSON.stringify({
|
||||||
|
error: "Error: some-error",
|
||||||
|
stdout: "",
|
||||||
|
stderr: "",
|
||||||
|
}, null, 4)}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -330,7 +338,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
it("should resolve with a failed call", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).resolves.toEqual({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
error: `Failed to spawn ${shellPath}: ${JSON.stringify({
|
||||||
|
error: "Error: some-error",
|
||||||
|
stdout: "",
|
||||||
|
stderr: "",
|
||||||
|
}, null, 4)}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -430,7 +442,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
it("should resolve with a failed call", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).resolves.toEqual({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
error: `Failed to spawn ${shellPath}: ${JSON.stringify({
|
||||||
|
error: "Error: some-error",
|
||||||
|
stdout: "",
|
||||||
|
stderr: "",
|
||||||
|
}, null, 4)}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -45,11 +45,7 @@ exports[`<CustomResourceDetails /> with a CRD with a boolean field should displa
|
|||||||
<span
|
<span
|
||||||
class="value"
|
class="value"
|
||||||
>
|
>
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
false
|
false
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -101,11 +97,7 @@ exports[`<CustomResourceDetails /> with a CRD with a boolean field should displa
|
|||||||
<span
|
<span
|
||||||
class="value"
|
class="value"
|
||||||
>
|
>
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
true
|
true
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -157,11 +149,7 @@ exports[`<CustomResourceDetails /> with a CRD with a number field should display
|
|||||||
<span
|
<span
|
||||||
class="value"
|
class="value"
|
||||||
>
|
>
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
0
|
0
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -213,11 +201,7 @@ exports[`<CustomResourceDetails /> with a CRD with a number field should display
|
|||||||
<span
|
<span
|
||||||
class="value"
|
class="value"
|
||||||
>
|
>
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
1234
|
1234
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -15,11 +15,10 @@ import { KubeObjectMeta } from "../kube-object-meta";
|
|||||||
import { Input } from "../input";
|
import { Input } from "../input";
|
||||||
import type { AdditionalPrinterColumnsV1 } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
|
import type { AdditionalPrinterColumnsV1 } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
|
||||||
import { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
|
import { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
|
||||||
import { convertKubectlJsonPathToNodeJsonPath } from "../../utils/jsonPath";
|
import { safeJSONPathValue } from "../../utils/jsonPath";
|
||||||
import type { KubeObjectMetadata, KubeObjectStatus } from "../../../common/k8s-api/kube-object";
|
import type { KubeObjectMetadata, KubeObjectStatus } from "../../../common/k8s-api/kube-object";
|
||||||
import { KubeObject } from "../../../common/k8s-api/kube-object";
|
import { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||||
import logger from "../../../common/logger";
|
import logger from "../../../common/logger";
|
||||||
import { JSONPath } from "@astronautlabs/jsonpath";
|
|
||||||
|
|
||||||
export interface CustomResourceDetailsProps extends KubeObjectDetailsProps<KubeObject> {
|
export interface CustomResourceDetailsProps extends KubeObjectDetailsProps<KubeObject> {
|
||||||
crd: CustomResourceDefinition;
|
crd: CustomResourceDefinition;
|
||||||
@ -66,7 +65,7 @@ export class CustomResourceDetails extends React.Component<CustomResourceDetails
|
|||||||
renderAdditionalColumns(resource: KubeObject, columns: AdditionalPrinterColumnsV1[]) {
|
renderAdditionalColumns(resource: KubeObject, columns: AdditionalPrinterColumnsV1[]) {
|
||||||
return columns.map(({ name, jsonPath }) => (
|
return columns.map(({ name, jsonPath }) => (
|
||||||
<DrawerItem key={name} name={name}>
|
<DrawerItem key={name} name={name}>
|
||||||
{convertSpecValue(JSONPath.query(resource, convertKubectlJsonPathToNodeJsonPath(jsonPath)))}
|
{convertSpecValue(safeJSONPathValue(resource, jsonPath))}
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { KubeObjectListLayout } from "../kube-object-list-layout";
|
|||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
import { computed, makeObservable } from "mobx";
|
import { computed, makeObservable } from "mobx";
|
||||||
import type { ApiManager } from "../../../common/k8s-api/api-manager";
|
import type { ApiManager } from "../../../common/k8s-api/api-manager";
|
||||||
import { safeJSONPathValue } from "../../utils/jsonPath";
|
import { formatJSONValue, safeJSONPathValue } from "../../utils/jsonPath";
|
||||||
import { TabLayout } from "../layout/tab-layout-2";
|
import { TabLayout } from "../layout/tab-layout-2";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import customResourcesRouteParametersInjectable from "./custom-resources-route-parameters.injectable";
|
import customResourcesRouteParametersInjectable from "./custom-resources-route-parameters.injectable";
|
||||||
@ -73,7 +73,7 @@ class NonInjectedCustomResources extends React.Component<Dependencies> {
|
|||||||
[columnId.age]: customResource => -customResource.getCreationTimestamp(),
|
[columnId.age]: customResource => -customResource.getCreationTimestamp(),
|
||||||
...Object.fromEntries(extraColumns.map(({ name, jsonPath }) => [
|
...Object.fromEntries(extraColumns.map(({ name, jsonPath }) => [
|
||||||
name,
|
name,
|
||||||
customResource => safeJSONPathValue(customResource, jsonPath),
|
customResource => formatJSONValue(safeJSONPathValue(customResource, jsonPath)),
|
||||||
])),
|
])),
|
||||||
}}
|
}}
|
||||||
searchFilters={[
|
searchFilters={[
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { convertKubectlJsonPathToNodeJsonPath, safeJSONPathValue } from "../jsonPath";
|
import { convertKubectlJsonPathToNodeJsonPath, safeJSONPathValue } from "../jsonPath";
|
||||||
|
|
||||||
describe("parseJsonPath", () => {
|
describe("convertKubectlJsonPathToNodeJsonPath", () => {
|
||||||
it("should convert \\. to use indexed notation", () => {
|
it("should convert \\. to use indexed notation", () => {
|
||||||
const res = convertKubectlJsonPathToNodeJsonPath(".metadata.labels.kubesphere\\.io/alias-name");
|
const res = convertKubectlJsonPathToNodeJsonPath(".metadata.labels.kubesphere\\.io/alias-name");
|
||||||
|
|
||||||
@ -82,13 +82,13 @@ describe("safeJSONPathValue", () => {
|
|||||||
it("should convert boolean values to strings", () => {
|
it("should convert boolean values to strings", () => {
|
||||||
const res = safeJSONPathValue({ bar: false }, ".bar");
|
const res = safeJSONPathValue({ bar: false }, ".bar");
|
||||||
|
|
||||||
expect(res).toBe("false");
|
expect(res).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert number values to strings", () => {
|
it("should convert number values to strings", () => {
|
||||||
const res = safeJSONPathValue({ bar: 0 }, ".bar");
|
const res = safeJSONPathValue({ bar: 0 }, ".bar");
|
||||||
|
|
||||||
expect(res).toBe("0");
|
expect(res).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should join sliced entries with commas only", () => {
|
it("should join sliced entries with commas only", () => {
|
||||||
@ -103,7 +103,7 @@ describe("safeJSONPathValue", () => {
|
|||||||
],
|
],
|
||||||
}, ".bar[].foo");
|
}, ".bar[].foo");
|
||||||
|
|
||||||
expect(res).toBe("1");
|
expect(res).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should join an array of values using JSON.stringify", () => {
|
it("should join an array of values using JSON.stringify", () => {
|
||||||
@ -114,7 +114,7 @@ describe("safeJSONPathValue", () => {
|
|||||||
],
|
],
|
||||||
}, ".bar");
|
}, ".bar");
|
||||||
|
|
||||||
expect(res).toBe(`["world","hello"]`);
|
expect(res).toEqual(["world", "hello"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should stringify an object value", () => {
|
it("should stringify an object value", () => {
|
||||||
@ -122,7 +122,7 @@ describe("safeJSONPathValue", () => {
|
|||||||
foo: { bar: "bat" },
|
foo: { bar: "bat" },
|
||||||
}, ".foo");
|
}, ".foo");
|
||||||
|
|
||||||
expect(res).toBe(`{"bar":"bat"}`);
|
expect(res).toEqual({ "bar":"bat" });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use convertKubectlJsonPathToNodeJsonPath", () => {
|
it("should use convertKubectlJsonPathToNodeJsonPath", () => {
|
||||||
@ -155,7 +155,7 @@ describe("safeJSONPathValue", () => {
|
|||||||
|
|
||||||
const res = safeJSONPathValue(obj, ".spec.metrics[*].external.highWatermark..");
|
const res = safeJSONPathValue(obj, ".spec.metrics[*].external.highWatermark..");
|
||||||
|
|
||||||
expect(res).toBe("100, 100");
|
expect(res).toEqual(["100", "100"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not throw if path is invalid jsonpath", () => {
|
it("should not throw if path is invalid jsonpath", () => {
|
||||||
@ -163,6 +163,16 @@ describe("safeJSONPathValue", () => {
|
|||||||
foo: { "hello.world": "bat" },
|
foo: { "hello.world": "bat" },
|
||||||
}, "asd[");
|
}, "asd[");
|
||||||
|
|
||||||
expect(res).toBe("<unknown>");
|
expect(res).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should retrive value with '/' in jsonpath", () => {
|
||||||
|
const res = safeJSONPathValue({
|
||||||
|
foo: {
|
||||||
|
"hello/world": "bat",
|
||||||
|
},
|
||||||
|
}, ".foo.hello/world");
|
||||||
|
|
||||||
|
expect(res).toBe("bat");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -6,7 +6,7 @@
|
|||||||
import { JSONPath } from "@astronautlabs/jsonpath";
|
import { JSONPath } from "@astronautlabs/jsonpath";
|
||||||
import { TypedRegEx } from "typed-regex";
|
import { TypedRegEx } from "typed-regex";
|
||||||
|
|
||||||
const slashDashSearch = /[\\-]/g;
|
const slashDashSearch = /[/\\-]/g;
|
||||||
const pathByBareDots = /(?<=\w)\./;
|
const pathByBareDots = /(?<=\w)\./;
|
||||||
const textBeforeFirstSquare = /^.*(?=\[)/g;
|
const textBeforeFirstSquare = /^.*(?=\[)/g;
|
||||||
const backSlash = /\\/g;
|
const backSlash = /\\/g;
|
||||||
@ -22,6 +22,7 @@ const trailingDotDot = /\.\.$/;
|
|||||||
*
|
*
|
||||||
* Known shorthands:
|
* Known shorthands:
|
||||||
* - Leading `$` is optional (but implied)
|
* - Leading `$` is optional (but implied)
|
||||||
|
* - The string `/` can be used without a leading `\` escapement
|
||||||
* - The string `\.` is used to denote the "value of '.'" and not "next key"
|
* - The string `\.` is used to denote the "value of '.'" and not "next key"
|
||||||
* - The string `-` can be used while not in quotes
|
* - The string `-` can be used while not in quotes
|
||||||
* - `[]` as shorthand for `[0]`
|
* - `[]` as shorthand for `[0]`
|
||||||
@ -75,7 +76,15 @@ function convertToIndexNotation(key: string, firstItem = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatJSONValue(value: unknown) {
|
export function formatJSONValue(value: unknown): string {
|
||||||
|
if (value == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.map(formatJSONValue).join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof value === "object") {
|
if (typeof value === "object") {
|
||||||
return JSON.stringify(value);
|
return JSON.stringify(value);
|
||||||
}
|
}
|
||||||
@ -88,21 +97,21 @@ function formatJSONValue(value: unknown) {
|
|||||||
*
|
*
|
||||||
* This function will also stringify the value retreived from the object
|
* This function will also stringify the value retreived from the object
|
||||||
*/
|
*/
|
||||||
export function safeJSONPathValue(obj: object, path: string): string {
|
export function safeJSONPathValue(obj: object, path: string): unknown {
|
||||||
try {
|
try {
|
||||||
const parsedPath = JSONPath.parse(convertKubectlJsonPathToNodeJsonPath(path));
|
const parsedPath = JSONPath.parse(convertKubectlJsonPathToNodeJsonPath(path));
|
||||||
const isSlice = parsedPath.some((exp: any) => exp.expression.type === "slice" || "wildcard");
|
const isSlice = parsedPath.some((exp: any) => exp.expression.type === "slice" || exp.expression.type === "wildcard");
|
||||||
const value = JSONPath.query(obj, JSONPath.stringify(parsedPath), isSlice ? Infinity : 1);
|
const value = JSONPath.query(obj, JSONPath.stringify(parsedPath), isSlice ? Infinity : 1);
|
||||||
|
|
||||||
if (isSlice) {
|
if (isSlice) {
|
||||||
return value.map(formatJSONValue).join(", ");
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatJSONValue(value[0]);
|
return value[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// something failed
|
// something failed
|
||||||
console.warn("[JSON-PATH]: failed to parse jsonpath", error);
|
console.warn("[JSON-PATH]: failed to parse jsonpath", error);
|
||||||
|
|
||||||
return "<unknown>";
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user