You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by iu...@apache.org on 2021/09/09 15:34:46 UTC

[brooklyn-server] branch master updated: Added method to use curl with a minimum TLS version specified as argument

This is an automated email from the ASF dual-hosted git repository.

iuliana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new cb731cd  Added method to use curl with a minimum TLS version specified as argument
     new c11b7d3  Merge pull request #1256 from iuliana/fix/curl-cutoms-tls
cb731cd is described below

commit cb731cdf7f089b62e158731950136f65407fb7d8
Author: iuliana <iu...@cloudsoft.io>
AuthorDate: Thu Sep 9 16:10:25 2021 +0100

    Added method to use curl with a minimum TLS version specified as
    argument
---
 .../org/apache/brooklyn/util/ssh/BashCommands.java | 29 +++++++++++++++++++---
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java b/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java
index fe7c939..d60c9a9 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java
@@ -570,6 +570,17 @@ public class BashCommands {
         return Arrays.asList(INSTALL_CURL, 
                 require(simpleDownloadUrlAs(urls, saveAs), "Could not retrieve "+saveAs+". Tried: " + Joiner.on(", ").join(urls), 9));
     }
+
+    /**
+     * Returns commands to download the URL, saving as the given file. Will try each URL in turn until one is successful.
+     * It allows setting a minimum TLS version to avoid this error: <code> <curl: (35) Peer reports incompatible or unsupported protocol version./code>
+     * (see `curl -f` documentation).
+     */
+    public static List<String> commandsToDownloadUrlsAsWithMinimumTlsVersion(List<String> urls, String saveAs, String tlsVersion) {
+        return Arrays.asList(INSTALL_CURL,
+                require(simpleDownloadUrlAs(urls, saveAs, tlsVersion), "Could not retrieve "+saveAs+". Tried: " + Joiner.on(", ").join(urls), 9));
+    }
+
     public static String commandToDownloadUrlsAs(List<String> urls, String saveAs) {
         return chain(INSTALL_CURL, 
                 require(simpleDownloadUrlAs(urls, saveAs), "Could not retrieve "+saveAs+". Tried: " + Joiner.on(", ").join(urls), 9));
@@ -597,19 +608,29 @@ public class BashCommands {
     }
 
     /**
-     * Same as {@link downloadUrlAs(List, String)}, except does not install curl, and does not exit on failure,
+     * Same as {@link simpleDownloadUrlAs(List, String)}, except does not install curl, and does not exit on failure,
      * and if saveAs is null it downloads it so stdout.
      */
     public static String simpleDownloadUrlAs(List<String> urls, String saveAs) {
-        return simpleDownloadUrlAs(urls, null, null, saveAs);
+        return simpleDownloadUrlAs(urls, null, null, saveAs, null);
+    }
+
+    /**
+     * Same as {@link simpleDownloadUrlAs(List, String, String)}, except does not install curl, and does not exit on failure,
+     * and if saveAs is null it downloads it so stdout.
+     */
+    public static String simpleDownloadUrlAs(List<String> urls, String saveAs, String tlsVersion) {
+        return simpleDownloadUrlAs(urls, null, null, saveAs, tlsVersion);
     }
 
-    public static String simpleDownloadUrlAs(List<String> urls, String user, String password, String saveAs) {
+    public static String simpleDownloadUrlAs(List<String> urls, String user, String password, String saveAs, String tlsVersion) {
         if (urls.isEmpty()) throw new IllegalArgumentException("No URLs supplied to download "+saveAs);
         
         List<String> commands = new ArrayList<String>();
         for (String url : urls) {
-            String command = "curl -f -L -k --retry 10 --keepalive-time 30 --speed-time 30 ";
+            String command = tlsVersion == null ?
+                    "curl -f -L -k --retry 10 --keepalive-time 30 --speed-time 30 " :
+                    "curl --tlsv" + tlsVersion + " -f -L -k --retry 10 --keepalive-time 30 --speed-time 30 " ;
             if (user!=null && password!=null) {
                command = command + format("-u %s:%s ", user, password);
             }