From a8a7bf8c4f41506afde53331be0f9ab820132bba Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 19 Aug 2020 20:39:29 +0530 Subject: [PATCH] Fix #339: Https should be considered default while converting tcp urls --- CHANGELOG.md | 1 + .../org/eclipse/jkube/kit/common/util/EnvUtil.java | 9 ++++----- .../org/eclipse/jkube/kit/common/util/EnvUtilTest.java | 10 ++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28ca0093fb..2d237bb953 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Usage: * Fix #341: JKube doesn't add ImageChange triggers in DC when merging from a deployment fragment * Fix #326: Add default `/metrics` path for `prometheus.io/path` annotation (Sort of [redundant](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config), this makes it explicit) +* Fix #339: Https should be considered default while converting tcp urls ### 1.0.0-rc-1 (2020-07-23) * Fix #252: Replace Quarkus Native Base image with ubi-minimal (same as in `Dockerfile.native`) diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/EnvUtil.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/EnvUtil.java index 7668935a5a..00d8f43e19 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/EnvUtil.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/EnvUtil.java @@ -52,18 +52,17 @@ public class EnvUtil { public static final String MAVEN_PROPERTY_REGEXP = "\\s*\\$\\{\\s*([^}]+)\\s*}\\s*$"; - // Standard HTTPS port (IANA registered). The other 2375 with plain HTTP is used only in older - // docker installations. - public static final String DOCKER_HTTPS_PORT = "2376"; + // Standard HTTP port (IANA registered). It is used only in older docker installations. + public static final String DOCKER_HTTP_PORT = "2375"; public static final String PROPERTY_COMBINE_POLICY_SUFFIX = "_combine"; private EnvUtil() { } - // Convert docker host URL to an http URL + // Convert docker host URL to an HTTP(s) URL public static String convertTcpToHttpUrl(String connect) { - String protocol = connect.contains(":" + DOCKER_HTTPS_PORT) ? "https:" : "http:"; + String protocol = connect.contains(":" + DOCKER_HTTP_PORT) ? "http:" : "https:"; return connect.replaceFirst("^tcp:", protocol); } diff --git a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/EnvUtilTest.java b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/EnvUtilTest.java index c380b1dd6e..bd66381e69 100644 --- a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/EnvUtilTest.java +++ b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/EnvUtilTest.java @@ -72,6 +72,16 @@ public void testConvertTcpToHttpUrl() { assertEquals("http://0.0.0.0:2375", result2); } + @Test + public void testConvertTcpToHttpUrlShouldDefaultToHttps() { + // Given + String url = "tcp://127.0.0.1:32770"; + // When + String result = EnvUtil.convertTcpToHttpUrl(url); + // Then + assertEquals("https://127.0.0.1:32770", result); + } + @Test public void testExtractLargerVersionWhenBothNull(){ assertNull(EnvUtil.extractLargerVersion(null,null));