suneet-s commented on a change in pull request #11711:
URL: https://github.com/apache/druid/pull/11711#discussion_r713585330



##########
File path: 
core/src/main/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategy.java
##########
@@ -0,0 +1,54 @@
+/*
+ * 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 org.apache.druid.common.exception;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+import java.util.function.Function;
+import java.util.regex.Pattern;
+
+public class AllowedRegexErrorResponseTransformStrategy implements 
ErrorResponseTransformStrategy
+{
+  @JsonProperty
+  private final List<Pattern> allowedRegex;
+
+  @JsonCreator
+  public AllowedRegexErrorResponseTransformStrategy(
+      @JsonProperty("allowedRegex") List<Pattern> allowedRegex
+  )
+  {
+    this.allowedRegex = allowedRegex == null ? ImmutableList.of() : 
allowedRegex;
+  }
+
+  @Override
+  public Function<String, String> getErrorMessageTransformFunction()
+  {
+    return (String errorMessage) -> {
+      if (allowedRegex.stream().noneMatch(pattern -> 
pattern.matcher(errorMessage).matches())) {

Review comment:
       nit: Is it better to use `anyMatch` to return the errorMessage so the 
stream can short circuit and exit early?

##########
File path: 
core/src/main/java/org/apache/druid/common/exception/SanitizableException.java
##########
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.druid.common.exception;
+
+import java.util.function.Function;
+
+public interface SanitizableException
+{
+  /**
+   * Apply the function for transforming the error message then
+   * return new Exception with sanitized fields and transformed message.
+   */
+  Exception transform(

Review comment:
       nit: rename to `sanitize` to be inline with `SanitizableException`

##########
File path: 
core/src/main/java/org/apache/druid/common/exception/SanitizableException.java
##########
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.druid.common.exception;
+
+import java.util.function.Function;
+
+public interface SanitizableException

Review comment:
       javadocs please. Explanation about how this is expected to be used and 
why this class exists will be helpful.

##########
File path: 
core/src/main/java/org/apache/druid/common/exception/SanitizableException.java
##########
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.druid.common.exception;
+
+import java.util.function.Function;
+
+public interface SanitizableException
+{
+  /**
+   * Apply the function for transforming the error message then
+   * return new Exception with sanitized fields and transformed message.
+   */
+  Exception transform(
+      Function<String, String> errorMessageTransformFunction

Review comment:
       Can you add details on why only the errorMessage is expected to be 
transformed in this interface to the javadoc please

##########
File path: 
server/src/main/java/org/apache/druid/server/security/ForbiddenException.java
##########
@@ -44,4 +48,14 @@ public String getErrorMessage()
   {
     return super.getMessage();
   }
+
+  @Override
+  public ForbiddenException transform(Function<String, String> 
errorMessageTransformFunction)
+  {
+    if 
(Strings.isNullOrEmpty(errorMessageTransformFunction.apply(getMessage()))) {
+      return new ForbiddenException();
+    } else {
+      return this;

Review comment:
       appears to be a logic bug here
   
   unit tests please

##########
File path: core/src/main/java/org/apache/druid/query/QueryException.java
##########
@@ -96,4 +98,10 @@ protected static String resolveHostname()
       return null;
     }
   }
+
+  @Override
+  public QueryException transform(Function<String, String> 
errorMessageTransformFunction)
+  {
+    return new QueryException(errorCode, 
errorMessageTransformFunction.apply(getMessage()), null, null);

Review comment:
       can we add unit tests for this please




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to