You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by da...@apache.org on 2017/04/07 19:58:51 UTC

kudu git commit: Add --redact=none flag option for specifying no redaction

Repository: kudu
Updated Branches:
  refs/heads/master b95d3a4fa -> f304dd32f


Add --redact=none flag option for specifying no redaction

It's still possible to specify no redaction via --redact='', but I was
only able to determine how to do that by reading the code.  I think this
makes it a bit easier to use.

Change-Id: I06f9d1ab08baaac02359e3ab29f8741bd1f4ff7d
Reviewed-on: http://gerrit.cloudera.org:8080/6590
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Reviewed-by: Hao Hao <ha...@cloudera.com>
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: f304dd32f74d03e4b8d8d88b8cd56e2089c84879
Parents: b95d3a4
Author: Dan Burkert <da...@apache.org>
Authored: Fri Apr 7 10:10:14 2017 -0700
Committer: Dan Burkert <da...@apache.org>
Committed: Fri Apr 7 19:58:36 2017 +0000

----------------------------------------------------------------------
 src/kudu/util/flags.cc | 64 ++++++++++++++++++---------------------------
 1 file changed, 26 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/f304dd32/src/kudu/util/flags.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/flags.cc b/src/kudu/util/flags.cc
index c410c19..4394979 100644
--- a/src/kudu/util/flags.cc
+++ b/src/kudu/util/flags.cc
@@ -114,61 +114,49 @@ TAG_FLAG(unlock_unsafe_flags, advanced);
 TAG_FLAG(unlock_unsafe_flags, stable);
 
 DEFINE_string(redact, "all",
-              "Comma-separated list of redactions. Supported redactions are 'flag', "
-              "'log' and 'all'. If 'flag' is specified, configuration flags which may "
+              "Comma-separated list of redactions. Supported options are 'flag', "
+              "'log', 'all', and 'none'. If 'flag' is specified, configuration flags which may "
               "include sensitive data will be redacted whenever server configuration "
               "is emitted. If 'log' is specified, row data will be redacted from log "
-              "and error messages. If 'all' is specified, all of above will be redacted.");
+              "and error messages. If 'all' is specified, all of above will be redacted. "
+              "If 'none' is specified, no redaction will occur.");
 TAG_FLAG(redact, advanced);
 TAG_FLAG(redact, evolving);
 
 static bool ValidateRedact(const char* /*flagname*/, const string& value) {
-  // Empty value is valid.
-  if (value.empty()) {
-    kudu::g_should_redact_log = false;
-    kudu::g_should_redact_flag = false;
-    return true;
-  }
+  kudu::g_should_redact_log = false;
+  kudu::g_should_redact_flag = false;
 
-  // Flag value is case insensitive
+  // Flag value is case insensitive.
   string redact_flags;
   kudu::ToUpperCase(value, &redact_flags);
-  // "ALL" is valid, "ALL, LOG" is not valid
-  if (redact_flags.compare("ALL") == 0) {
+
+  // 'all', 'none', and '' must be specified without any other option.
+  if (redact_flags == "ALL") {
     kudu::g_should_redact_log = true;
     kudu::g_should_redact_flag = true;
     return true;
   }
+  if (redact_flags == "NONE" || redact_flags.empty()) {
+    return true;
+  }
 
-  // If use specific flag value, it can only be "FLAG"
-  // or "LOG".
-  vector<string> enabled_redact_types = strings::Split(redact_flags, ",",
-                                                       strings::SkipEmpty());
-  vector<string>::const_iterator iter;
-  bool is_valid = true;
-  bool enabled_redact_log = false;
-  bool enabled_redact_flag = false;
-  for (const auto& t : enabled_redact_types) {
-    if (t.compare("LOG") == 0) {
-      enabled_redact_log = true;
+  for (const auto& t : strings::Split(redact_flags, ",", strings::SkipEmpty())) {
+    if (t == "LOG") {
+      kudu::g_should_redact_log = true;
+    } else if (t == "FLAG") {
+      kudu::g_should_redact_flag = true;
+    } else if (t == "ALL" || t == "NONE") {
+      LOG(ERROR) << "Invalid redaction options: "
+                 << value << ", '" << t << "' must be specified by itself.";
+      return false;
     } else {
-      if (t.compare("FLAG") == 0) {
-        enabled_redact_flag = true;
-      } else {
-        is_valid = false;
-      }
+      LOG(ERROR) << "Invalid redaction type: " << t <<
+                    ". Available types are 'flag', 'log', 'all', and 'none'.";
+      return false;
     }
   }
-  if (!is_valid) {
-    LOG(ERROR) << Substitute("Invalid redaction type: $0. Available types are 'flag', "
-                             "'log', 'all'.", value);
-  } else {
-    // If the value of --redact flag is valid, set
-    // g_should_redact_log and g_should_redact_flag accordingly.
-    kudu::g_should_redact_log = enabled_redact_log;
-    kudu::g_should_redact_flag = enabled_redact_flag;
-  }
-  return is_valid;
+  return true;
 }
 
 DEFINE_validator(redact, &ValidateRedact);