Skip to content

Commit

Permalink
fix: unable to login on cluster with private certificate (#866)
Browse files Browse the repository at this point in the history
* fix: unable to login on cluster with private certificate

Signed-off-by: Stephane Bouchet <[email protected]>

* fix: unable to login on cluster with private certificate

Signed-off-by: Stephane Bouchet <[email protected]>

---------

Signed-off-by: Stephane Bouchet <[email protected]>
  • Loading branch information
sbouchet authored Jul 11, 2024
1 parent 4e36c83 commit c9829a6
Show file tree
Hide file tree
Showing 26 changed files with 626 additions and 320 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
echo PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state open --search "fix: update helm ${{env.LATEST_TOOL_RELEASE}} in:title" --json url | jq length) >> $GITHUB_ENV
- name: Update tools.json with latest helm version
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_HELM_VERSION) && (env.PR_EXISTS == 0) && (env.LATEST_TOOL_RELEASE != '') }}
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_HELM_VERSION) && (env.PR_EXISTS == 0) }}
run: |
jq --indent 4 '.tools.helm.version = "${{ env.LATEST_TOOL_RELEASE }}"' src/main/resources/tools.json | jq --indent 4 '.tools.helm.versionMatchRegExpr = "${{ env.LATEST_TOOL_RELEASE }}"' > src/main/resources/tools.json.new
mv src/main/resources/tools.json.new src/main/resources/tools.json
Expand All @@ -37,7 +37,7 @@ jobs:
mv src/main/resources/tools.json.new src/main/resources/tools.json
done
- name: Create pull request
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_HELM_VERSION) && (env.PR_EXISTS == 0) && (env.LATEST_TOOL_RELEASE != '') }}
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_HELM_VERSION) && (env.PR_EXISTS == 0) }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/check-oc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: check-oc

on:
schedule:
- cron: "0 10 * * *"
workflow_dispatch:
jobs:
check-oc-repo:
runs-on: ubuntu-latest
env:
TOOL_REPO: openshift/oc
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Check Out Code
uses: actions/checkout@v4
- name: Get latest OC version
run: |
echo "REPO_OC_VERSION=$(cat src/main/resources/tools.json | jq -r .tools.oc.version)" >> $GITHUB_ENV
baseUrl="'https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/release.txt"
echo "LATEST_TOOL_URL=$(echo ${baseUrl})" >> $GITHUB_ENV
echo "LATEST_TOOL_RELEASE=$(curl -s -L ${baseUrl} | grep "Name:" | head -n 1 | sed 's|Name:||' | sed 's| ||g')" >> $GITHUB_ENV
- name: Find existing PR for OC version
run: |
echo PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state open --search "fix: update oc ${{env.LATEST_TOOL_RELEASE}} in:title" --json url | jq length) >> $GITHUB_ENV
- name: Update tools.json with latest oc version
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_OC_VERSION) && (env.PR_EXISTS == 0) }}
run: |
jq --indent 4 '.tools.oc.version = "${{ env.LATEST_TOOL_RELEASE }}"' src/main/resources/tools.json | jq --indent 4 '.tools.oc.versionMatchRegExpr = "${{ env.LATEST_TOOL_RELEASE }}"' > src/main/resources/tools.json.new
mv src/main/resources/tools.json.new src/main/resources/tools.json
for platform in win osx \"osx-aarch64\" lnx \"lnx-arm64\"; do
old_url=`jq -r .tools.oc.platforms.${platform}.url src/main/resources/tools.json`
new_url=`echo ${old_url} | sed "s|${{ env.REPO_OC_VERSION }}|${{ env.LATEST_TOOL_RELEASE }}|"`
checksum_url=`echo "${new_url}.sha256"`
checksum=`curl -s -L ${checksum_url} | sed "s| ||g"`
jq --indent 4 ".tools.oc.platforms.${platform}.url = \"${new_url}\"" src/main/resources/tools.json \
| jq --indent 4 ".tools.oc.platforms.${platform}.sha256sum = \"${checksum}\"" > src/main/resources/tools.json.new
mv src/main/resources/tools.json.new src/main/resources/tools.json
done
- name: Create pull request
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_OC_VERSION) && (env.PR_EXISTS == 0) }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git checkout -b "oc-${{ env.LATEST_TOOL_RELEASE }}"
git commit -am "fix: Update oc to ${{ env.LATEST_TOOL_RELEASE }}"
git push origin "oc-${{ env.LATEST_TOOL_RELEASE }}"
gh pr create --title "fix: Update oc to ${{ env.LATEST_TOOL_RELEASE }}" --body "See ${{ env.LATEST_TOOL_URL }}"
4 changes: 2 additions & 2 deletions .github/workflows/check-odo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
echo PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state open --search "fix: update odo ${{env.LATEST_TOOL_RELEASE}} in:title" --json url | jq length) >> $GITHUB_ENV
- name: Update tools.json with latest odo version
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_ODO_VERSION) && (env.PR_EXISTS == 0) }}
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_ODO_VERSION) && (env.PR_EXISTS == 0) }}
run: |
jq --indent 4 '.tools.odo.version = "${{ env.LATEST_TOOL_RELEASE }}"' src/main/resources/tools.json | jq --indent 4 '.tools.odo.versionMatchRegExpr = "${{ env.LATEST_TOOL_RELEASE }}"' > src/main/resources/tools.json.new
mv src/main/resources/tools.json.new src/main/resources/tools.json
Expand All @@ -34,7 +34,7 @@ jobs:
mv src/main/resources/tools.json.new src/main/resources/tools.json
done
- name: Create pull request
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_ODO_VERSION) && (env.PR_EXISTS == 0) }}
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_ODO_VERSION) && (env.PR_EXISTS == 0) }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
******************************************************************************/
package org.jboss.tools.intellij.openshift.utils;

import org.jboss.tools.intellij.openshift.utils.odo.Odo;
import org.jboss.tools.intellij.openshift.utils.oc.Oc;

import java.io.IOException;

Expand All @@ -24,12 +24,9 @@ public class OdoCluster {

private static final String CLUSTER_PASSWORD = System.getenv("CLUSTER_PASSWORD");

public boolean login(Odo odo) throws IOException {
if (CLUSTER_URL != null && !odo.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
odo.login(CLUSTER_URL, CLUSTER_USER, CLUSTER_PASSWORD.toCharArray(), null);
return true;
} else {
return false;
public void login(Oc oc) throws IOException {
if (CLUSTER_URL != null && !oc.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
oc.login(CLUSTER_URL, CLUSTER_USER, CLUSTER_PASSWORD.toCharArray(), null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import org.jboss.tools.intellij.openshift.utils.ToolFactory.Tool;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.oc.Oc;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
import org.jboss.tools.intellij.openshift.utils.odo.OdoDelegate;

Expand All @@ -32,4 +33,10 @@ public void testGetHelm() throws ExecutionException, InterruptedException {
assertNotNull(helm);
}

public void testGetOc() throws ExecutionException, InterruptedException {
Tool<Oc> tool = ToolFactory.getInstance().createOc(getProject()).get();
Oc oc = tool.get();
assertNotNull(oc);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jboss.tools.intellij.openshift.utils.OdoCluster;
import org.jboss.tools.intellij.openshift.utils.ToolFactory;
import org.jboss.tools.intellij.openshift.utils.ToolFactory.Tool;
import org.jboss.tools.intellij.openshift.utils.oc.Oc;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
import org.jboss.tools.intellij.openshift.utils.odo.OdoDelegate;

Expand All @@ -29,8 +30,9 @@ public abstract class HelmCliTest extends BasePlatformTestCase {
protected void setUp() throws Exception {
super.setUp();
Tool<OdoDelegate> odoTool = ToolFactory.getInstance().createOdo(getProject()).get();
Tool<Oc> ocTool = ToolFactory.getInstance().createOc(getProject()).get();
Odo odo = odoTool.get();
OdoCluster.INSTANCE.login(odo);
OdoCluster.INSTANCE.login(ocTool.get());
odo.createProject(projectName);
Tool<Helm> helmTool = ToolFactory.getInstance().createHelm(getProject()).get();
this.helm = helmTool.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.commons.io.FileUtils;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationRootNodeOdo;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.utils.OdoCluster;
import org.jboss.tools.intellij.openshift.utils.ToolFactory;

import java.io.File;
Expand Down Expand Up @@ -56,25 +57,22 @@ public abstract class OdoCliTest extends BasePlatformTestCase {

protected static final String REGISTRY_PREFIX = "reg";

protected static final String CLUSTER_URL = System.getenv("CLUSTER_URL");

protected static final String CLUSTER_USER = System.getenv("CLUSTER_USER");

protected static final String CLUSTER_PASSWORD = System.getenv("CLUSTER_PASSWORD");

private TestDialog previousTestDialog;

@Override
protected void setUp() throws Exception {
super.setUp();
previousTestDialog = MessagesHelper.setTestDialog(TestDialog.OK);
ToolFactory.getInstance().createOc(getProject()).whenComplete((ocTool, throwable) -> {
try {
OdoCluster.INSTANCE.login(ocTool.get());
} catch (IOException e) {
throw new RuntimeException(e);
}
});
odo = getOdo().get();
if (odo.listDevfileRegistries().stream().noneMatch(c -> c.getName().equals(REGISTRY_NAME)))
odo.createDevfileRegistry(REGISTRY_NAME, REGISTRY_URL, null);
if (CLUSTER_URL != null && !odo.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
odo.login(CLUSTER_URL, CLUSTER_USER, CLUSTER_PASSWORD.toCharArray(), null);
odo = getOdo().get();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.fabric8.openshift.api.model.ProjectList;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.dsl.ProjectOperation;
import org.jboss.tools.intellij.openshift.utils.odo.OdoCli.TelemetryReport;
import org.jboss.tools.intellij.openshift.utils.Cli;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -245,7 +245,7 @@ public void isAuthorized_should_throw_if_listing_secrets_throws_other_Kubernetes
.when(authorization).getApiGroups();
Odo odo = createOdo(kubernetesClient, openShiftClient);
// when
boolean found = odo.isAuthorized();
odo.isAuthorized();
// then
}

Expand All @@ -259,7 +259,7 @@ private OdoCli createOdo(KubernetesClient kubernetesClient, OpenShiftClient open
Supplier<KubernetesClient> kubernetesClientFactory = () -> kubernetesClient;
Function<KubernetesClient, OpenShiftClient> openShiftClientFactory = client -> openShiftClient;
Function<String, Map<String, String>> envVarFactory = url -> new HashMap<>();
TelemetryReport telemetryReport = mock(TelemetryReport.class);
Cli.TelemetryReport telemetryReport = mock(Cli.TelemetryReport.class);
return new OdoCli(project, command, bus, kubernetesClientFactory, openShiftClientFactory, envVarFactory, telemetryReport);
}

Expand Down Expand Up @@ -313,7 +313,7 @@ private static V1AuthorizationAPIGroupDSL v1AuthorizationAPIGroup(APIGroupList a
var v1 = mock(V1AuthorizationAPIGroupDSL.class);
doReturn(apiGroupList)
.when(v1).getApiGroups();
var authorization = mock(AuthorizationAPIGroupDSL.class);
var authorization = mock(AuthorizationAPIGroupDSL.class);
doReturn(v1)
.when(authorization).v1();
doReturn(authorization)
Expand Down
3 changes: 2 additions & 1 deletion src/it/projects/go/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.odo/
.odo/env
.odo/odo-file-index.json
main
main.exe
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
Expand All @@ -32,6 +31,7 @@
import java.awt.event.MouseEvent;
import java.util.function.Consumer;

import static com.intellij.openapi.actionSystem.PlatformCoreDataKeys.CONTEXT_COMPONENT;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.PREFIX_ACTION;

public class ActionUtils {
Expand All @@ -55,7 +55,7 @@ public static ApplicationsTreeStructure getApplicationTreeStructure(AnActionEven
}

private static JTree getTree(AnActionEvent e) {
Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
Component component = e.getData(CONTEXT_COMPONENT);
if (!(component instanceof Tree)) {
throw new IllegalArgumentException("invalid context: not a com.intellij.ui.treeStructure.Tree");
}
Expand Down Expand Up @@ -89,8 +89,7 @@ public static Point getLocation(AnActionEvent actionEvent) {

public static <T extends StructureTreeAction> T createAction(String id) {
T action = (T) ActionManager.getInstance().getAction(id);
if (action instanceof TelemetrySenderAware) {
TelemetrySenderAware sender = (TelemetrySenderAware) action;
if (action instanceof TelemetrySenderAware sender) {
sender.setTelemetrySender(new TelemetrySender(PREFIX_ACTION + sender.getTelemetryActionName()));
}
return action;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jboss.tools.intellij.openshift.telemetry.TelemetrySender;
import org.jboss.tools.intellij.openshift.utils.oc.Oc;
import org.jetbrains.annotations.NotNull;

import javax.swing.tree.TreePath;

import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.PREFIX_ACTION;

public abstract class OcAction extends TelemetryAction {

protected OcAction(Class... filters) {
super(filters);
}

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected) {
setTelemetrySender(new TelemetrySender(PREFIX_ACTION + getTelemetryActionName()));
ActionUtils.getApplicationRootNode(anActionEvent).getOcTool().whenComplete(
(ocTool, throwable) -> {
if (ocTool != null) {
Oc oc = ocTool.get();
if (oc != null) {
this.actionPerformedOnSelectedObject(anActionEvent, getElement(selected), oc);
}
}
}
);
}

public abstract void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Oc oc);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
package org.jboss.tools.intellij.openshift.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.redhat.devtools.intellij.common.actions.StructureTreeAction;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryHandler;
import org.jboss.tools.intellij.openshift.telemetry.TelemetrySender;
import org.jboss.tools.intellij.openshift.telemetry.TelemetrySenderAware;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.utils.odo.OdoFacade;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand All @@ -25,19 +21,17 @@

import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.PREFIX_ACTION;

public abstract class OdoAction extends StructureTreeAction implements TelemetryHandler, TelemetrySenderAware {
public abstract class OdoAction extends TelemetryAction {

private static final Logger LOGGER = LoggerFactory.getLogger(OdoAction.class);

protected TelemetrySender telemetrySender;

protected OdoAction(Class... filters) {
super(filters);
}

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected) {
this.telemetrySender = new TelemetrySender(PREFIX_ACTION + getTelemetryActionName());
setTelemetrySender(new TelemetrySender(PREFIX_ACTION + getTelemetryActionName()));
OdoFacade odo = getOdo(anActionEvent);
if (odo == null) {
return;
Expand All @@ -49,29 +43,10 @@ protected OdoFacade getOdo(AnActionEvent anActionEvent) {
try {
return ActionUtils.getApplicationRootNode(anActionEvent).getOdo().getNow(null);
} catch (Exception e) {
LOGGER.warn("Could not get odo: " + e.getMessage(), e);
LOGGER.warn("Could not get odo: {}", e.getMessage(), e);
return null;
}
}

public abstract void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull OdoFacade odo);

@Override
public void setTelemetrySender(TelemetrySender telemetrySender) {
this.telemetrySender = telemetrySender;
}

public void sendTelemetryResults(TelemetryService.TelemetryResult result) {
telemetrySender.sendTelemetryResults(result);
}

@Override
public void sendTelemetryError(String message) {
telemetrySender.sendTelemetryError(message);
}

@Override
public void sendTelemetryError(Exception exception) {
telemetrySender.sendTelemetryError(exception);
}
}
Loading

0 comments on commit c9829a6

Please sign in to comment.