You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "huangzhir (via GitHub)" <gi...@apache.org> on 2023/04/04 07:48:45 UTC

[GitHub] [kyuubi] huangzhir commented on a diff in pull request #4643: [KYUUBI #4530] [AUTHZ] fixbug support MASK_SHOW_FIRST_4 和 MASK_SHOW_FIRST_4 chinese data mask

huangzhir commented on code in PR #4643:
URL: https://github.com/apache/kyuubi/pull/4643#discussion_r1156862619


##########
extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/SparkRangerAdminPlugin.scala:
##########
@@ -131,12 +125,28 @@ object SparkRangerAdminPlugin extends RangerBasePlugin("spark", "sparkSql")
     }
   }
 
-  private def regexp_replace(expr: String, hasLen: Boolean = false): String = {
+  // public for test

Review Comment:
   Thank you for your feedback. I have made the changes you suggested. Please let me know if there is anything else I can do to improve this PR.



##########
extensions/spark/kyuubi-spark-authz/src/main/scala/org/apache/kyuubi/plugin/spark/authz/ranger/SparkRangerAdminPlugin.scala:
##########
@@ -131,12 +125,28 @@ object SparkRangerAdminPlugin extends RangerBasePlugin("spark", "sparkSql")
     }
   }
 
-  private def regexp_replace(expr: String, hasLen: Boolean = false): String = {
+  // public for test
+  def regexp_replace(expr: String, hasLen: Boolean = false): String = {
     val pos = if (hasLen) ", 5" else ""
     val upper = s"regexp_replace($expr, '[A-Z]', 'X'$pos)"
     val lower = s"regexp_replace($upper, '[a-z]', 'x'$pos)"
     val digits = s"regexp_replace($lower, '[0-9]', 'n'$pos)"
-    digits
+    val other = s"regexp_replace($digits, '[^A-Za-z0-9 ]', 'U'$pos)"
+    other
+  }
+
+  def maskShowFirst4(col: String, isSparkV31OrGreater: Boolean): String = {
+    if (isSparkV31OrGreater) {
+      regexp_replace(col, hasLen = true)
+    } else {
+      val right = regexp_replace(s"substr($col, 5)")
+      s"concat(substr($col, 0, 4), $right)"
+    }
+  }
+
+  def maskShowLast4(col: String): String = {
+    val left = regexp_replace(s"left($col, length($col) - 4)")
+    s"concat($left, right($col, 4))"

Review Comment:
   Thank you for your feedback. I have made the changes you suggested. Please let me know if there is anything else I can do to improve this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org