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

ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new 714c5bb  Add method to load client properties from URL (#2075)
714c5bb is described below

commit 714c5bbacb4f703a70b95c4304aff86815adf52e
Author: slackwinner <50567198+slackwin...@users.noreply.github.com>
AuthorDate: Tue May 11 17:57:51 2021 -0400

    Add method to load client properties from URL (#2075)
    
    This commit contains changes that accepts
    URL paths to accumulo-client.properties
---
 .../org/apache/accumulo/core/client/AccumuloClient.java | 13 +++++++++++++
 .../apache/accumulo/core/clientImpl/ClientContext.java  |  8 +++++++-
 .../org/apache/accumulo/core/clientImpl/ClientInfo.java |  8 ++++++++
 .../apache/accumulo/core/clientImpl/ClientInfoImpl.java | 17 +++++++++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java 
b/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java
index 1180ad1..ffc213a 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/AccumuloClient.java
@@ -18,6 +18,7 @@
  */
 package org.apache.accumulo.core.client;
 
+import java.net.URL;
 import java.nio.file.Path;
 import java.util.Properties;
 
@@ -382,6 +383,18 @@ public interface AccumuloClient extends AutoCloseable {
      * Build using Java properties object. An example properties file can be 
found at
      * conf/accumulo-client.properties in the Accumulo tarball distribution.
      *
+     * @param propertiesURL
+     *          URL path to properties file
+     * @return this builder
+     * @see <a 
href="https://accumulo.apache.org/docs/2.x/configuration/client-properties";>Client
+     *      properties documentation</a>
+     */
+    FromOptions<T> from(URL propertiesURL);
+
+    /**
+     * Build using Java properties object. An example properties file can be 
found at
+     * conf/accumulo-client.properties in the Accumulo tarball distribution.
+     *
      * @param properties
      *          Properties object
      * @return this builder
diff --git 
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java 
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
index 9af9a10..0c0ea45 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
@@ -23,6 +23,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.Objects.requireNonNull;
 import static 
org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOCATION;
 
+import java.net.URL;
 import java.nio.file.Path;
 import java.util.Collections;
 import java.util.List;
@@ -798,8 +799,13 @@ public class ClientContext implements AccumuloClient {
     }
 
     @Override
+    public FromOptions<T> from(URL propertiesURL) {
+      return from(ClientInfoImpl.toProperties(propertiesURL));
+    }
+
+    @Override
     public FromOptions<T> from(Properties properties) {
-      // make a copy, so that this builder's subsequent methods don't mutate 
the
+      // Make a copy, so that this builder's subsequent methods don't mutate 
the
       // properties object provided by the caller
       this.properties = new Properties();
       this.properties.putAll(properties);
diff --git 
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfo.java 
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfo.java
index 2531a3e..fdb8097 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfo.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfo.java
@@ -18,6 +18,7 @@
  */
 package org.apache.accumulo.core.clientImpl;
 
+import java.net.URL;
 import java.nio.file.Path;
 import java.util.Properties;
 
@@ -80,6 +81,13 @@ public interface ClientInfo {
   }
 
   /**
+   * @return ClientInfo given URL path to client config file
+   */
+  static ClientInfo from(URL propertiesURL) {
+    return new ClientInfoImpl(propertiesURL);
+  }
+
+  /**
    * @return ClientInfo given properties and token
    */
   static ClientInfo from(Properties properties, AuthenticationToken token) {
diff --git 
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfoImpl.java 
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfoImpl.java
index 6d56b21..816604c 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfoImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientInfoImpl.java
@@ -21,6 +21,7 @@ package org.apache.accumulo.core.clientImpl;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Properties;
@@ -42,6 +43,10 @@ public class ClientInfoImpl implements ClientInfo {
     this(ClientInfoImpl.toProperties(propertiesFile));
   }
 
+  public ClientInfoImpl(URL propertiesURL) {
+    this(ClientInfoImpl.toProperties(propertiesURL));
+  }
+
   public ClientInfoImpl(Properties properties) {
     this(properties, null);
   }
@@ -115,6 +120,18 @@ public class ClientInfoImpl implements ClientInfo {
     return properties;
   }
 
+  @SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD",
+      justification = "code runs in same security context as user who provided 
propertiesURL")
+  public static Properties toProperties(URL propertiesURL) {
+    Properties properties = new Properties();
+    try (InputStream is = propertiesURL.openStream()) {
+      properties.load(is);
+    } catch (IOException e) {
+      throw new IllegalArgumentException("Failed to load properties from " + 
propertiesURL, e);
+    }
+    return properties;
+  }
+
   @Override
   public Configuration getHadoopConf() {
     return this.hadoopConf;

Reply via email to