AMBARI-20243 - Include option to filter out properties from APi that returns 
ambari.properties file (Anita Jebaraj via jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0471b0c3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0471b0c3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0471b0c3

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 0471b0c373dbc7757115cccc20e20ff260b690c0
Parents: e6fc6f4
Author: Jonathan Hurley <jhur...@hortonworks.com>
Authored: Fri Mar 10 16:08:14 2017 -0500
Committer: Jonathan Hurley <jhur...@hortonworks.com>
Committed: Fri Mar 10 16:08:20 2017 -0500

----------------------------------------------------------------------
 ambari-server/docs/configuration/index.md       |  1 +
 .../server/configuration/Configuration.java     | 42 ++++++++++++++++++++
 .../controller/RootServiceResponseFactory.java  |  5 +++
 .../server/configuration/ConfigurationTest.java | 11 +++++
 4 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0471b0c3/ambari-server/docs/configuration/index.md
----------------------------------------------------------------------
diff --git a/ambari-server/docs/configuration/index.md 
b/ambari-server/docs/configuration/index.md
index af962e1..7a7f3b9 100644
--- a/ambari-server/docs/configuration/index.md
+++ b/ambari-server/docs/configuration/index.md
@@ -162,6 +162,7 @@ The following are the properties which can be used to 
configure Ambari.
 | mpacks.staging.path | The Ambari Management Pack staging directory on the 
Ambari Server.<br/><br/>The following are examples of valid 
values:<ul><li>`/var/lib/ambari-server/resources/mpacks`</ul> | | 
 | packages.pre.installed | Determines whether Ambari Agent instances have 
already have the necessary stack software installed |`false` | 
 | pam.configuration | The PAM configuration file. | | 
+| property.mask.file | The path of the file which lists the properties that 
should be masked from the api that returns ambari.properties | | 
 | proxy.allowed.hostports | A comma-separated whitelist of host and port 
values which Ambari Server can use to determine if a proxy value is valid. 
|`*:*` | 
 | recommendations.artifacts.lifetime | The amount of time that Recommendation 
API data is kept on the Ambari Server file system. This is specified using a 
`hdwmy` syntax for pairing the value with a time unit (hours, days, weeks, 
months, years)<br/><br/>The following are examples of valid 
values:<ul><li>`8h`<li>`2w`<li>`1m`</ul> |`1w` | 
 | recommendations.artifacts.rollover.max | Maximum number of recommendations 
artifacts at a given time<br/><br/>The following are examples of valid 
values:<ul><li>`50`<li>`10`<li>`100`</ul> |`100` | 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0471b0c3/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index df334c5..20431f6 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -35,6 +35,7 @@ import java.security.interfaces.RSAPublicKey;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -866,6 +867,12 @@ public class Configuration {
   @Markdown(description = "The timeout, used by the `timeout` command in 
linux, when checking mounts for free capacity.")
   public static final ConfigurationProperty<String> CHECK_MOUNTS_TIMEOUT = new 
ConfigurationProperty<>(
       "agent.check.mounts.timeout", "0");
+  /**
+   * The path of the file which lists the properties that should be masked 
from the api that returns ambari.properties
+   */
+  @Markdown(description = "The path of the file which lists the properties 
that should be masked from the api that returns ambari.properties")
+  public static final ConfigurationProperty<String> PROPERTY_MASK_FILE = new 
ConfigurationProperty<>(
+      "property.mask.file", null);
 
   /**
    * The name of the database.
@@ -2685,6 +2692,7 @@ public class Configuration {
 
   private Properties properties;
   private Properties log4jProperties = new Properties();
+  private Set<String> propertiesToMask = null;
   private String ambariUpgradeConfigUpdatesFilePath;
   private JsonObject hostChangesJson;
   private Map<String, String> configsMap;
@@ -4067,6 +4075,9 @@ public class Configuration {
   public String getJCEName() {
     return getProperty(JCE_NAME);
   }
+  public String getAmbariBlacklistFile() {
+    return getProperty(PROPERTY_MASK_FILE);
+  }
 
   public String getServerDBName() {
     return getProperty(SERVER_DB_NAME);
@@ -4330,6 +4341,37 @@ public class Configuration {
     return Integer.parseInt(getProperty(SERVER_HTTP_RESPONSE_HEADER_SIZE));
   }
 
+  /**
+   * @return the set of properties to mask in the api that
+   * returns ambari.properties
+   */
+  public Set<String> getPropertiesToBlackList()
+  {
+    if (propertiesToMask != null) {
+      return propertiesToMask;
+    }
+    Properties blacklistProperties = new Properties();
+    String blacklistFile = getAmbariBlacklistFile();
+    propertiesToMask = new HashSet<String>();
+    if(blacklistFile != null) {
+      File propertiesMaskFile = new File(blacklistFile);
+      InputStream inputStream = null;
+      if(propertiesMaskFile.exists()) {
+        try {
+          inputStream = new FileInputStream(propertiesMaskFile);
+         blacklistProperties.load(inputStream);
+         propertiesToMask = blacklistProperties.stringPropertyNames();
+        } catch (Exception e) {
+         String message = String.format("Blacklist properties file %s cannot 
be read", blacklistFile);
+          LOG.error(message);
+        } finally {
+         IOUtils.closeQuietly(inputStream);
+        }
+      }
+    }
+    return propertiesToMask;
+  }
+
   public Map<String, String> getAmbariProperties() {
 
     Properties properties = readConfigFile();

http://git-wip-us.apache.org/repos/asf/ambari/blob/0471b0c3/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java
index dadcf09..11bc730 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/RootServiceResponseFactory.java
@@ -149,6 +149,7 @@ public class RootServiceResponseFactory extends
   private Map<String, String> getComponentProperties(String componentName){
     
     Map<String, String> response;
+    Set<String> propertiesToHideInResponse;
     Components component = null;
 
     if (componentName != null) {
@@ -159,6 +160,10 @@ public class RootServiceResponseFactory extends
         response = configs.getAmbariProperties();
         response.put(JDK_LOCATION, managementController.getJdkResourceUrl());
         response.put("java.version", 
System.getProperty("java.specification.version"));
+        propertiesToHideInResponse = configs.getPropertiesToBlackList();
+        for(String key : propertiesToHideInResponse) {
+         response.remove(key);
+       }
         break;
 
       default:

http://git-wip-us.apache.org/repos/asf/ambari/blob/0471b0c3/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
index 8111a39..7d2ebb5 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
@@ -299,6 +299,17 @@ public class ConfigurationTest {
     Assert.assertEquals("value", props.get("name"));
   }
 
+  @Test
+  public void testGetAmbariBlacklistFile() {
+    Properties ambariProperties = new Properties();
+    Configuration conf = new Configuration(ambariProperties);
+    Assert.assertEquals(null, conf.getAmbariBlacklistFile());
+    ambariProperties = new Properties();
+    ambariProperties.setProperty(Configuration.PROPERTY_MASK_FILE.getKey(), 
"ambari-blacklist.properties");
+    conf = new Configuration(ambariProperties);
+    Assert.assertEquals("ambari-blacklist.properties", 
conf.getAmbariBlacklistFile());
+  }
+
   @Rule
   public ExpectedException exception = ExpectedException.none();
 

Reply via email to