[ 
https://issues.apache.org/jira/browse/GEODE-8583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17210971#comment-17210971
 ] 

ASF GitHub Bot commented on GEODE-8583:
---------------------------------------

jhutchison commented on a change in pull request #5604:
URL: https://github.com/apache/geode/pull/5604#discussion_r501859545



##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/ParameterRequirements/RestrictedInputValuesParameterRequirements.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.geode.redis.internal.ParameterRequirements;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class RestrictedInputValuesParameterRequirements implements 
ParameterRequirements {
+
+  List<String> allowedValues = null;
+
+  public RestrictedInputValuesParameterRequirements(List<String> 
allowedValues) {
+    this.allowedValues = allowedValues;
+  }
+
+  @Override
+  public void checkParameters(Command command,
+      ExecutionHandlerContext executionHandlerContext) {
+    List<byte[]> parameters = command.getProcessedCommand();
+    String commandType = command.getCommandType().name();
+
+    parameters.forEach(parameter -> {
+      String parameterString = parameter.toString();
+      if (isNotAllowed(parameterString) &&
+          !parameterString.equalsIgnoreCase(commandType)) {

Review comment:
       > This PR changes way too many files. I didn't look at all of them. But 
it should have only changed 2 or 3.
   > I'm not sure I like this change because now we have the parameters in two 
places. We still have the switch statement in InfoExecutor that checks for each 
one, but now we also have a list of them in another place 
(ALLOWED_INFO_COMMANDS). The other confusing thing is that the INFO command 
does allow other keywords it just ignores them. In native redis "INFO foobar" 
does not give an error but just returns nothing. But by adding a 
RestrictedInputValuesParameterRequirements to INFO it makes me think that any 
other params would cause an error.
   
   I'll double check, but the large number of files changed should be the 
result of my moving the RedisConstants class into a new subdirectory (because 
there is now another constants files to hold specifically allowed parameters , 
and it seemed to  make sense to group them together).    To be addressed below, 
 I did forget to make the change to allow an error mesg for the class to be 
passed in as a parameter.  As you say, for info, the error mesg will just be an 
empty string, but other commands can pass in other other err msgs as is 
appropriate to match native  redis behavior.    
   
   I still like having the logic for the commands in the executor for now.  I 
see your point about the list of allowable commands being in 2 places.  
Ultimately I would like to use a singleton  enum, but wasn't able to figure out 
how to make that work without some more playing around (let me know if you have 
thoughts) 

##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisServer.java
##########
@@ -93,13 +86,21 @@ public GeodeRedisServer(String bindAddress, int port, 
InternalCache cache) {
     CommandFunction.register(regionProvider.getDataRegion(), stripedExecutor, 
redisStats);
     RenameFunction.register(regionProvider.getDataRegion(), stripedExecutor, 
redisStats);
     RedisCommandFunction.register();
+
     passiveExpirationManager =
         new PassiveExpirationManager(regionProvider.getDataRegion(), 
redisStats);
-    redisCommandExecutor = 
LoggingExecutors.newCachedThreadPool("GeodeRedisServer-Command-", true);
-    nettyRedisServer = new NettyRedisServer(() -> 
cache.getInternalDistributedSystem().getConfig(),
-        regionProvider, pubSub,
-        this::allowUnsupportedCommands, this::shutdown, port, bindAddress, 
redisStats,
-        redisCommandExecutor);
+    redisCommandExecutor =
+        LoggingExecutors.newCachedThreadPool("Redis Command", true);

Review comment:
       makes sense.  I think I'm going to slowly lobby to see if I can get some 
things updated in Spotless...   

##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/ParameterRequirements/RestrictedInputValuesParameterRequirements.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.geode.redis.internal.ParameterRequirements;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class RestrictedInputValuesParameterRequirements implements 
ParameterRequirements {
+
+  List<String> allowedValues = null;
+
+  public RestrictedInputValuesParameterRequirements(List<String> 
allowedValues) {
+    this.allowedValues = allowedValues;
+  }
+
+  @Override
+  public void checkParameters(Command command,
+      ExecutionHandlerContext executionHandlerContext) {
+    List<byte[]> parameters = command.getProcessedCommand();
+    String commandType = command.getCommandType().name();
+
+    parameters.forEach(parameter -> {
+      String parameterString = parameter.toString();
+      if (isNotAllowed(parameterString) &&
+          !parameterString.equalsIgnoreCase(commandType)) {
+        throw new RedisParametersMismatchException("");

Review comment:
       the idea is to allow a mesg to be passed as a parameter.  I'm only using 
it for info command now, and forgot to make that change.  Thanks for the catch

##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/ParameterRequirements/RestrictedInputValuesParameterRequirements.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.geode.redis.internal.ParameterRequirements;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class RestrictedInputValuesParameterRequirements implements 
ParameterRequirements {
+
+  List<String> allowedValues = null;
+
+  public RestrictedInputValuesParameterRequirements(List<String> 
allowedValues) {
+    this.allowedValues = allowedValues;
+  }
+
+  @Override
+  public void checkParameters(Command command,
+      ExecutionHandlerContext executionHandlerContext) {
+    List<byte[]> parameters = command.getProcessedCommand();
+    String commandType = command.getCommandType().name();
+
+    parameters.forEach(parameter -> {
+      String parameterString = parameter.toString();
+      if (isNotAllowed(parameterString) &&
+          !parameterString.equalsIgnoreCase(commandType)) {

Review comment:
       Also, I left the commit history, in an attempt to make it easy to see 
that a lot of files were changed when I moved the redisConstants class.  Is 
there a better way to communicate/show that in PRs?  just a separate PR? 

##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/ParameterRequirements/RestrictedInputValuesParameterRequirements.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.geode.redis.internal.ParameterRequirements;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class RestrictedInputValuesParameterRequirements implements 
ParameterRequirements {
+
+  List<String> allowedValues = null;

Review comment:
       will do, thx

##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/ParameterRequirements/RestrictedInputValuesParameterRequirements.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.geode.redis.internal.ParameterRequirements;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class RestrictedInputValuesParameterRequirements implements 
ParameterRequirements {
+
+  List<String> allowedValues = null;
+
+  public RestrictedInputValuesParameterRequirements(List<String> 
allowedValues) {

Review comment:
       So the reason I did this, was to allow the list of a parameters to exist 
as a constant, and allow that constant to be passed in when the command type is 
declared.  Didn't seem to work with the variable arg option (but that is how I 
had it before introducing the constant list of params)

##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/ParameterRequirements/RestrictedInputValuesParameterRequirements.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.geode.redis.internal.ParameterRequirements;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class RestrictedInputValuesParameterRequirements implements 
ParameterRequirements {
+
+  List<String> allowedValues = null;
+
+  public RestrictedInputValuesParameterRequirements(List<String> 
allowedValues) {
+    this.allowedValues = allowedValues;
+  }
+
+  @Override
+  public void checkParameters(Command command,
+      ExecutionHandlerContext executionHandlerContext) {
+    List<byte[]> parameters = command.getProcessedCommand();
+    String commandType = command.getCommandType().name();
+
+    parameters.forEach(parameter -> {
+      String parameterString = parameter.toString();
+      if (isNotAllowed(parameterString) &&
+          !parameterString.equalsIgnoreCase(commandType)) {
+        throw new RedisParametersMismatchException("");
+      }
+    });
+  }
+
+  private boolean isNotAllowed(String parameterString) {
+    return (allowedValues.contains(parameterString));

Review comment:
       probably.  Thanks

##########
File path: 
geode-redis/src/main/java/org/apache/geode/redis/internal/ParameterRequirements/RestrictedInputValuesParameterRequirements.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.geode.redis.internal.ParameterRequirements;
+
+import java.util.List;
+
+import org.apache.geode.redis.internal.netty.Command;
+import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;
+
+public class RestrictedInputValuesParameterRequirements implements 
ParameterRequirements {
+
+  List<String> allowedValues = null;
+
+  public RestrictedInputValuesParameterRequirements(List<String> 
allowedValues) {
+    this.allowedValues = allowedValues;
+  }
+
+  @Override
+  public void checkParameters(Command command,
+      ExecutionHandlerContext executionHandlerContext) {
+    List<byte[]> parameters = command.getProcessedCommand();
+    String commandType = command.getCommandType().name();
+
+    parameters.forEach(parameter -> {
+      String parameterString = parameter.toString();
+      if (isNotAllowed(parameterString) &&
+          !parameterString.equalsIgnoreCase(commandType)) {

Review comment:
       looks like I also included some left over gemfire servers in one of the 
commits too :).  




----------------------------------------------------------------
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.

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


> create RestrictedInputValuesParameterRequirements in Redis Module
> -----------------------------------------------------------------
>
>                 Key: GEODE-8583
>                 URL: https://issues.apache.org/jira/browse/GEODE-8583
>             Project: Geode
>          Issue Type: Improvement
>            Reporter: John Hutchison
>            Priority: Minor
>              Labels: pull-request-available, redis
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to