You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/06/14 22:47:56 UTC

[06/10] incubator-brooklyn git commit: Sanitize: don’t use anonymous inner class

Sanitize: don’t use anonymous inner class


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/475c482f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/475c482f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/475c482f

Branch: refs/heads/master
Commit: 475c482fba2459dbf8d7a565f324163743978580
Parents: 521a3a0
Author: Aled Sage <al...@gmail.com>
Authored: Sat Jun 13 17:26:37 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Sat Jun 13 23:11:10 2015 +0100

----------------------------------------------------------------------
 .../java/brooklyn/entity/basic/Sanitizer.java   | 24 +++++++++++--
 .../brooklyn/entity/basic/SanitizerTest.java    | 38 ++++++++++++++++++++
 2 files changed, 60 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/475c482f/core/src/main/java/brooklyn/entity/basic/Sanitizer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/Sanitizer.java b/core/src/main/java/brooklyn/entity/basic/Sanitizer.java
index 6e07071..88ca756 100644
--- a/core/src/main/java/brooklyn/entity/basic/Sanitizer.java
+++ b/core/src/main/java/brooklyn/entity/basic/Sanitizer.java
@@ -44,9 +44,29 @@ public final class Sanitizer {
             "private",
             "access.cert", 
             "access.key");
-    
-    public static final Predicate<Object> IS_SECRET_PREDICATE = new Predicate<Object>() {
 
+    public static final Predicate<Object> IS_SECRET_PREDICATE = new IsSecretPredicate();
+
+    private static class IsSecretPredicate implements Predicate<Object> {
+        @Override
+        public boolean apply(Object name) {
+            String lowerName = name.toString().toLowerCase();
+            for (String secretName : SECRET_NAMES) {
+                if (lowerName.contains(secretName))
+                    return true;
+            }
+            return false;
+        }
+    };
+
+    /**
+     * Kept only in case this anonymous inner class has made it into any persisted state.
+     * 
+     * @deprecated since 0.7.0
+     */
+    @Deprecated
+    @SuppressWarnings("unused")
+    private static final Predicate<Object> IS_SECRET_PREDICATE_DEPRECATED = new Predicate<Object>() {
         @Override
         public boolean apply(Object name) {
             String lowerName = name.toString().toLowerCase();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/475c482f/core/src/test/java/brooklyn/entity/basic/SanitizerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/SanitizerTest.java b/core/src/test/java/brooklyn/entity/basic/SanitizerTest.java
new file mode 100644
index 0000000..c9d40a5
--- /dev/null
+++ b/core/src/test/java/brooklyn/entity/basic/SanitizerTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.entity.basic;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+
+import org.testng.annotations.Test;
+
+import brooklyn.util.config.ConfigBag;
+
+import com.google.common.collect.ImmutableMap;
+
+public class SanitizerTest {
+
+    @Test
+    public void testSanitize() throws Exception {
+        Map<String, Object> sanitized = Sanitizer.sanitize(ConfigBag.newInstance(ImmutableMap.of("password", "pa55w0rd", "mykey", "myval")));
+        assertEquals(sanitized, ImmutableMap.of("password", "xxxxxxxx", "mykey", "myval"));
+    }
+}