[
https://issues.apache.org/jira/browse/GEODE-8583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17209893#comment-17209893
]
ASF GitHub Bot commented on GEODE-8583:
---------------------------------------
dschneider-pivotal commented on a change in pull request #5604:
URL: https://github.com/apache/geode/pull/5604#discussion_r501326934
##########
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:
It seems like it would be better to only iterate over a sublist that
excludes that first item (which is the commandType). Saying a parameter is
okay if it is equal "commandType" would allow someone to do this following
command: "INFO INFO INFO" and it would not care about the extra INFO parameters
because they match the commandType.
##########
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:
make this private final and initialize it only in the constructor
##########
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:
Do you want to ignore case hear also? You could store all the values
given to the constructor in lower case and then here convert parameterString to
lower case and then contains would work.
##########
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:
Instead of a List<String> have the method take varargs (i.e. "(String...
allowedValues)"). Then callers can just say new
RestrictedInputValuesParameterRequirements("SERVER", "PERSISTENCE") instead of
having to create its own collection
##########
File path:
geode-redis/src/main/java/org/apache/geode/redis/internal/executor/server/InfoExecutor.java
##########
@@ -46,8 +47,10 @@ private boolean
containsSectionParameter(List<ByteArrayWrapper> commands) {
private String getSpecifiedSection(ExecutionHandlerContext context,
List<ByteArrayWrapper> commands) {
- String result;
- String section = commands.get(1).toString().toLowerCase();
+ String result = "";
Review comment:
I think the old code (using default on the switch) is better.
----------------------------------------------------------------
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:
[email protected]
> 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)