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

+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);
}
}