Commit 7254798d authored by amir.yosef's avatar amir.yosef

Adding validation to INFO command

parent f74874d4
......@@ -10,7 +10,6 @@ import java.util.stream.IntStream;
public class CommandValidator {
private CommandValidator() {
}
private static final class InstanceHolder {
......@@ -49,8 +48,11 @@ public class CommandValidator {
}
public boolean validateGetCommand(List<String> args) {
return args != null && args.size() == 1;
}
public boolean validateInfoCommand(List<String> args) {
return args != null && args.size() == 1 && "replication".equalsIgnoreCase(args.getFirst());
}
}
package command;
import model.Command;
import util.Response;
import server.ServerInfo;
import util.Response;
import java.util.List;
import java.util.Map;
......@@ -10,6 +10,7 @@ import java.util.stream.Collectors;
public class InfoCommand implements CommandExecutable<byte[]> {
private final ServerInfo configuration = ServerInfo.getInstance();
private final CommandValidator validator = CommandValidator.getInstance();
List<String> args;
public InfoCommand(List<String> args) {
......@@ -18,6 +19,9 @@ public class InfoCommand implements CommandExecutable<byte[]> {
@Override
public byte[] execute() {
if (!validator.validateInfoCommand(args)) {
return "unsupported args".getBytes();
}
String command = args.getFirst();
if (command.equalsIgnoreCase(Command.REPLICATION.getValue())) {
Map<String, String> info = configuration.getInfo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment