Skip to content

Commit

Permalink
Update to Seed 3.4.0-S
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Nov 16, 2017
1 parent c821180 commit ef76fdd
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 71 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 1.0.1 (2017-11-31)

* [chg] Update to Seed 3.4.0.

# Version 1.0.0 (2016-12-15)

* [new] Extracted as an add-on from `seed-shell` module.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

<groupId>org.seedstack.addons.shell</groupId>
<artifactId>shell</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>

<properties>
<seed.version>3.0.0</seed.version>
<seed.version>3.4.0-SNAPSHOT</seed.version>

<compatibility.skip>true</compatibility.skip>

Expand Down
40 changes: 19 additions & 21 deletions src/main/java/org/seedstack/shell/internal/AbstractShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.seedstack.shell.internal;

import com.google.common.base.Strings;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import javax.inject.Inject;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand All @@ -19,27 +29,15 @@
import org.seedstack.seed.command.Command;
import org.seedstack.seed.command.CommandRegistry;

import javax.inject.Inject;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

abstract class AbstractShell implements org.apache.sshd.server.Command, Runnable {
public static final String COMMAND_PATTERN = "([a-zA-Z][a-zA-Z0-9\\-]+:)?[a-zA-Z][a-zA-Z0-9\\-]+";
private static final String COMMAND_PATTERN = "([a-zA-Z][a-zA-Z0-9\\-]+:)?[a-zA-Z][a-zA-Z0-9\\-]+";
private final CommandLineParser commandLineParser = new DefaultParser();

protected InputStream inputStream;
protected OutputStream outputStream;
protected OutputStream errorStream;
protected ExitCallback exitCallback;

InputStream inputStream;
OutputStream outputStream;
OutputStream errorStream;
ExitCallback exitCallback;
@Inject
protected CommandRegistry commandRegistry;
CommandRegistry commandRegistry;

@Override
public void setInputStream(InputStream inputStream) {
Expand All @@ -61,7 +59,7 @@ public void setExitCallback(ExitCallback exitCallback) {
this.exitCallback = exitCallback;
}

protected List<Command> createCommandActions(String line) {
List<Command> createCommandActions(String line) {
if (Strings.isNullOrEmpty(line)) {
return new ArrayList<>();
}
Expand Down Expand Up @@ -114,7 +112,7 @@ protected List<Command> createCommandActions(String line) {
}

@SuppressWarnings("unchecked")
protected Command createCommandAction(String qualifiedName, List<String> args) {
Command createCommandAction(String qualifiedName, List<String> args) {
if (Strings.isNullOrEmpty(qualifiedName)) {
throw SeedException.createNew(ShellErrorCode.MISSING_COMMAND);
}
Expand Down Expand Up @@ -153,7 +151,7 @@ protected Command createCommandAction(String qualifiedName, List<String> args) {
return commandRegistry.createCommand(commandScope, commandName, cmd.getArgList(), optionValues);
}

protected String stripAnsiCharacters(String value) {
String stripAnsiCharacters(String value) {
return value.replaceAll("\\e\\[[\\d;]*[^\\d;]", "");
}
}
24 changes: 13 additions & 11 deletions src/main/java/org/seedstack/shell/internal/InteractiveShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.seedstack.shell.internal;

import com.google.common.base.Strings;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import javax.inject.Inject;
import jline.Terminal;
import jline.UnsupportedTerminal;
import jline.console.ConsoleReader;
Expand All @@ -24,17 +31,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;

class InteractiveShell extends AbstractShell {
private static final Logger LOGGER = LoggerFactory.getLogger(InteractiveShell.class);
public static final String DETAILS_MESSAGE = "Details of the previous error below";
public static final String WELCOME_MESSAGE = " _______________ ______ ________ __ \n" +
private static final String DETAILS_MESSAGE = "Details of the previous error below";
private static final String WELCOME_MESSAGE = " _______________ ______ ________ __ \n" +
" / __/ __/ __/ _ \\ / __/ // / __/ / / / \n" +
" _\\ \\/ _// _// // / _\\ \\/ _ / _// /__/ /__\n" +
" /___/___/___/____/ /___/_//_/___/____/____/\n";
Expand Down Expand Up @@ -196,7 +196,8 @@ private void alterMode(String modeName, String modeValue) {
try {
defaultOutputMode = OutputMode.valueOf(modeValue.toUpperCase());
} catch (IllegalArgumentException e) {
throw SeedException.wrap(e, ShellErrorCode.ILLEGAL_MODE_OPTION).put("supportedOptions", Arrays.toString(OutputMode.values()));
throw SeedException.wrap(e, ShellErrorCode.ILLEGAL_MODE_OPTION)
.put("supportedOptions", Arrays.toString(OutputMode.values()));
}
} else if ("pretty".equals(modeName)) {
if ("on".equalsIgnoreCase(modeValue)) {
Expand All @@ -215,7 +216,8 @@ private void alterMode(String modeName, String modeValue) {
throw SeedException.createNew(ShellErrorCode.ILLEGAL_MODE_OPTION).put("supportedOptions", "on|off");
}
} else {
throw SeedException.createNew(ShellErrorCode.ILLEGAL_MODE).put("supportedModes", "output|pretty|stacktraces");
throw SeedException.createNew(ShellErrorCode.ILLEGAL_MODE)
.put("supportedModes", "output|pretty|stacktraces");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.shell.internal;

package org.seedstack.shell.internal;

import com.google.common.collect.Lists;
import com.google.inject.assistedinject.Assisted;
import org.apache.shiro.concurrent.SubjectAwareExecutorService;
import org.apache.shiro.util.ThreadContext;
import org.apache.sshd.server.Environment;
import org.seedstack.seed.command.Command;
import org.seedstack.seed.command.StreamCommand;
import org.seedstack.shell.internal.commands.JsonCommand;

import javax.inject.Inject;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import javax.inject.Inject;
import org.apache.shiro.concurrent.SubjectAwareExecutorService;
import org.apache.shiro.util.ThreadContext;
import org.apache.sshd.server.Environment;
import org.seedstack.seed.command.Command;
import org.seedstack.seed.command.StreamCommand;
import org.seedstack.shell.internal.commands.JsonCommand;

class NonInteractiveShell extends AbstractShell {
private final String line;

private PrintStream errorPrintStream;
private PrintStream outputPrintStream;

private SubjectAwareExecutorService ses;

@Inject
Expand Down
32 changes: 7 additions & 25 deletions src/main/java/org/seedstack/shell/internal/ShellPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.seedstack.shell.internal;

import com.google.inject.Module;
import io.nuun.kernel.api.plugin.InitState;
import io.nuun.kernel.api.plugin.PluginException;
import io.nuun.kernel.api.plugin.context.Context;
import io.nuun.kernel.api.plugin.context.InitContext;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.SecurityManager;
Expand All @@ -24,35 +29,22 @@
import org.apache.sshd.server.UserAuth;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.seedstack.seed.core.internal.AbstractSeedPlugin;
import org.seedstack.seed.security.internal.SecurityGuiceConfigurer;
import org.seedstack.seed.security.internal.SecurityProvider;
import org.seedstack.shell.ShellConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* This plugin provides shell-style interaction over SSH with the SEED application.
*
* @author [email protected]
*/
public class ShellPlugin extends AbstractSeedPlugin implements SecurityProvider {
public class ShellPlugin extends AbstractSeedPlugin {
private static final Logger LOGGER = LoggerFactory.getLogger(ShellPlugin.class);

private ShellConfig shellConfig;
private SshServer sshServer;

@Inject
private ShellFactory shellFactory;

@Inject
@Named("shell")
private SecurityManager securityManager;

@Override
Expand Down Expand Up @@ -135,16 +127,6 @@ public Object nativeUnitModule() {
return new ShellModule();
}

@Override
public Module provideMainSecurityModule(SecurityGuiceConfigurer securityGuiceConfigurer) {
return null;
}

@Override
public Module provideAdditionalSecurityModule() {
return new ShellSecurityModule();
}

private final class ShiroAuthFactory implements NamedFactory<UserAuth> {
@Override
public String getName() {
Expand Down

This file was deleted.

0 comments on commit ef76fdd

Please sign in to comment.