public void checkValidShellCommand(final SingularityShellCommand shellCommand) { Optional<ShellCommandDescriptor> commandDescriptor = Iterables.tryFind(uiConfiguration.getShellCommands(), new Predicate<ShellCommandDescriptor>() { @Override public boolean apply(ShellCommandDescriptor input) { return input.getName().equals(shellCommand.getName()); } }); if (!commandDescriptor.isPresent()) { throw WebExceptions.badRequest("Shell command %s not in %s", shellCommand.getName(), uiConfiguration.getShellCommands()); } Set<String> options = Sets.newHashSetWithExpectedSize(commandDescriptor.get().getOptions().size()); for (ShellCommandOptionDescriptor option : commandDescriptor.get().getOptions()) { options.add(option.getName()); } if (shellCommand.getOptions().isPresent()) { for (String option : shellCommand.getOptions().get()) { if (!options.contains(option)) { throw WebExceptions.badRequest("Shell command %s does not have option %s (%s)", shellCommand.getName(), option, options); } } } } }
if (shellRequest.getShellCommand().getOptions().isPresent()) { for (SingularityExecutorShellCommandOptionDescriptor option : shellCommandDescriptor.getOptions()) { if (shellRequest.getShellCommand().getOptions().get().contains(option.getName())) { command.add(option.getFlag());
public void checkValidShellCommand(final SingularityShellCommand shellCommand) { Optional<ShellCommandDescriptor> commandDescriptor = Iterables.tryFind(uiConfiguration.getShellCommands(), new Predicate<ShellCommandDescriptor>() { @Override public boolean apply(ShellCommandDescriptor input) { return input.getName().equals(shellCommand.getName()); } }); if (!commandDescriptor.isPresent()) { throw WebExceptions.badRequest("Shell command %s not in %s", shellCommand.getName(), uiConfiguration.getShellCommands()); } Set<String> options = Sets.newHashSetWithExpectedSize(commandDescriptor.get().getOptions().size()); for (ShellCommandOptionDescriptor option : commandDescriptor.get().getOptions()) { options.add(option.getName()); } if (shellCommand.getOptions().isPresent()) { for (String option : shellCommand.getOptions().get()) { if (!options.contains(option)) { throw WebExceptions.badRequest("Shell command %s does not have option %s (%s)", shellCommand.getName(), option, options); } } } } }