|
13 | 13 | import com.intellij.openapi.application.ApplicationManager;
|
14 | 14 | import com.intellij.util.messages.MessageBus;
|
15 | 15 | import com.redhat.devtools.intellij.common.utils.ExecHelper;
|
| 16 | +import io.fabric8.kubernetes.client.Config; |
16 | 17 | import io.fabric8.kubernetes.client.KubernetesClient;
|
17 | 18 | import java.io.File;
|
18 | 19 | import java.io.IOException;
|
19 | 20 | import java.net.URL;
|
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
20 | 23 | import java.util.Map;
|
21 | 24 | import java.util.function.Function;
|
22 | 25 | import org.jboss.tools.intellij.openshift.utils.Cli;
|
@@ -60,10 +63,30 @@ private static void execute(@NotNull File workingDirectory, String command, Map<
|
60 | 63 |
|
61 | 64 | @Override
|
62 | 65 | public void login(String url, String userName, char[] password, char[] token) throws IOException {
|
| 66 | + var args = new ArrayList<String>(); |
| 67 | + args.add("login"); |
| 68 | + args.add(url); |
| 69 | + args.add("--insecure-skip-tls-verify"); |
| 70 | + addKubeconfigParameter(args); |
| 71 | + addLoginParameter(userName, password, token, args); |
| 72 | + execute(new File(HOME_FOLDER), command, envVars, args.toArray(new String[0])); |
| 73 | + } |
| 74 | + |
| 75 | + private void addKubeconfigParameter(ArrayList<String> args) { |
| 76 | + String kubeconfig = Config.getKubeconfigFilenames().stream() |
| 77 | + .findFirst() |
| 78 | + .orElse(null); |
| 79 | + if (kubeconfig != null) { |
| 80 | + args.add("--kubeconfig"); |
| 81 | + args.add(kubeconfig); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + private static void addLoginParameter(String userName, char[] password, char[] token, ArrayList<String> args) { |
63 | 86 | if (userName != null && !userName.isEmpty()) {
|
64 |
| - execute(new File(HOME_FOLDER), command, envVars, "login", url, "-u", userName, "-p", String.valueOf(password), "--insecure-skip-tls-verify"); |
| 87 | + args.addAll(Arrays.asList("-u", userName, "-p", String.valueOf(password))); |
65 | 88 | } else {
|
66 |
| - execute(new File(HOME_FOLDER), command, envVars, "login", url, "--token", String.valueOf(token), "--insecure-skip-tls-verify"); |
| 89 | + args.addAll(Arrays.asList("--token", String.valueOf(token))); |
67 | 90 | }
|
68 | 91 | }
|
69 | 92 |
|
|
0 commit comments