File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 66
77#include < algorithm>
88#include < map>
9+ #include < regex>
910#include < string>
1011
1112
@@ -71,10 +72,17 @@ class Properties
7172
7273 std::string toString () const
7374 {
75+
7476 std::string ret;
7577 std::for_each (_kvMap.cbegin (), _kvMap.cend (),
7678 [&ret](const auto & kv) {
77- ret.append (ret.empty () ? " " : " |" ).append (kv.first ).append (" =" ).append (kv.second );
79+ const std::string& key = kv.first ;
80+ const std::string& value = kv.second ;
81+
82+ static const std::regex reSensitiveKey (R"( .+\.password)" );
83+ bool isSensitive = std::regex_match (key, reSensitiveKey);
84+
85+ ret.append (ret.empty () ? " " : " |" ).append (key).append (" =" ).append (isSensitive ? " *" : value);
7886 });
7987 return ret;
8088 }
Original file line number Diff line number Diff line change @@ -83,3 +83,15 @@ TEST(Properties, AdminClientConfig)
8383
8484 EXPECT_EQ (" bootstrap.servers=127.0.0.1:9000,127.0.0.1:9001|security.protocol=SASL_PLAINTEXT" , props.toString ());
8585}
86+
87+ TEST (Properties, SensitiveProperties)
88+ {
89+ kafka::Properties props
90+ {{
91+ { " ssl.key.password" , " passwordA" },
92+ { " ssl.keystore.password" , " passwordB" },
93+ { " sasl.password" , " passwordC" },
94+ }};
95+
96+ EXPECT_EQ (" sasl.password=*|ssl.key.password=*|ssl.keystore.password=*" , props.toString ());
97+ }
You can’t perform that action at this time.
0 commit comments