Revert "Fix check for user exec command (#3664)" (#3827)

This reverts commit 056b818ceb.

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala authored and GitHub committed 2021-09-17 11:13:04 +03:00
1 parent e5c9c9a4b5
commit 53ce818589
6 files changed
+23 -62

No files matched your search

+4 -7
View File
@@ -19,18 +19,15 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import path from "path";
export class ExecValidationNotFoundError extends Error {
constructor(execPath: string) {
constructor(execPath: string, isAbsolute: boolean) {
super(`User Exec command "${execPath}" not found on host.`);
let message = `User Exec command "${execPath}" not found on host.`;
if (!path.isAbsolute(execPath)) {
if (!isAbsolute) {
message += ` Please ensure binary is found in PATH or use absolute path to binary in Kubeconfig`;
}
super(message);
this.message = message;
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
+7 -11
View File
@@ -25,11 +25,11 @@ import path from "path";
import os from "os";
import yaml from "js-yaml";
import logger from "../main/logger";
import commandExists from "command-exists";
import { ExecValidationNotFoundError } from "./custom-errors";
import { Cluster, Context, newClusters, newContexts, newUsers, User } from "@kubernetes/client-node/dist/config_types";
import { resolvePath } from "./utils";
import Joi from "joi";
import which from "which";
export type KubeConfigValidationOpts = {
validateCluster?: boolean;
@@ -295,17 +295,13 @@ export function validateKubeConfig(config: KubeConfig, contextName: string, vali
// Validate exec command if present
if (validateExec && user?.exec) {
try {
which.sync(user.exec.command);
const execCommand = user.exec["command"];
// check if the command is absolute or not
const isAbsolute = path.isAbsolute(execCommand);
// If this doesn't throw an error it also means that it has found the executable.
} catch (error) {
switch (error?.code) {
case "ENOENT":
return new ExecValidationNotFoundError(user.exec.command);
default:
return error;
}
// validate the exec struct in the user object, start with the command field
if (!commandExists.sync(execCommand)) {
return new ExecValidationNotFoundError(execCommand, isAbsolute);
}
}
@@ -50,11 +50,4 @@
display: block;
padding-top: 6px;
}
.actions-panel {
.Spinner {
vertical-align: middle;
margin-left: $spacing;
}
}
}
@@ -24,7 +24,7 @@ import "./add-cluster.scss";
import type { KubeConfig } from "@kubernetes/client-node";
import fse from "fs-extra";
import { debounce } from "lodash";
import { action, computed, observable, makeObservable, runInAction } from "mobx";
import { action, computed, observable, makeObservable } from "mobx";
import { observer } from "mobx-react";
import path from "path";
import React from "react";
@@ -41,7 +41,6 @@ import { SettingLayout } from "../layout/setting-layout";
import MonacoEditor from "react-monaco-editor";
import { ThemeStore } from "../../theme.store";
import { UserStore } from "../../../common/user-store";
import { Spinner } from "../spinner";
interface Option {
config: KubeConfig;
@@ -63,7 +62,6 @@ export class AddCluster extends React.Component {
@observable kubeContexts = observable.map<string, Option>();
@observable customConfig = "";
@observable isWaiting = false;
@observable isCheckingInput = false;
@observable errorText: string;
constructor(props: {}) {
@@ -82,35 +80,14 @@ export class AddCluster extends React.Component {
].filter(Boolean);
}
_refreshContexts = debounce(() => {
runInAction(() => {
try {
const text = this.customConfig.trim();
@action
refreshContexts = debounce(() => {
const { config, error } = loadConfigFromString(this.customConfig.trim() || "{}");
if (!text) {
return this.kubeContexts.clear();
}
const { config, error } = loadConfigFromString(text);
this.kubeContexts.replace(getContexts(config));
this.errorText = error?.toString();
} catch (error) {
this.kubeContexts.clear();
this.errorText = error?.toString() || "An error occured";
} finally {
this.isCheckingInput = false;
}
});
this.kubeContexts.replace(getContexts(config));
this.errorText = error?.toString();
}, 500);
refreshContexts = () => {
// Clear the kubeContexts immediately
this.isCheckingInput = true;
this.kubeContexts.clear();
this._refreshContexts();
};
@action
addClusters = async () => {
this.isWaiting = true;
@@ -168,7 +145,6 @@ export class AddCluster extends React.Component {
tooltip={this.kubeContexts.size === 0 || "Paste in at least one cluster to add."}
tooltipOverrideDisabled
/>
{this.isCheckingInput && <Spinner />}
</div>
</SettingLayout>
);