karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject karaf git commit: [KARAF-5331] Use shell command access control lists during command completion
Date Fri, 01 Sep 2017 13:42:05 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 6d5355e48 -> e1f7aff43


[KARAF-5331] Use shell command access control lists during command completion

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e1f7aff4
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e1f7aff4
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e1f7aff4

Branch: refs/heads/master
Commit: e1f7aff434bbb548e7ddfbdbc1f284504224365c
Parents: 6d5355e
Author: Guillaume Nodet <gnodet@apache.org>
Authored: Fri Sep 1 15:41:52 2017 +0200
Committer: Guillaume Nodet <gnodet@apache.org>
Committed: Fri Sep 1 15:41:52 2017 +0200

----------------------------------------------------------------------
 .../shell/impl/console/ConsoleSessionImpl.java  | 24 ++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/e1f7aff4/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
index 7e3d5fe..2a4a516 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
@@ -35,6 +35,7 @@ import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 import org.apache.felix.gogo.jline.ParsedLineImpl;
 import org.apache.felix.gogo.jline.Shell;
@@ -71,6 +72,8 @@ import org.jline.terminal.impl.DumbTerminal;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.felix.gogo.jline.Shell.VAR_SCOPE;
+
 public class ConsoleSessionImpl implements Session {
 
     private static final String SUPPRESS_WELCOME = "karaf.shell.suppress.welcome";
@@ -221,11 +224,28 @@ public class ConsoleSessionImpl implements Session {
             }
             @Override
             public Set<String> getCommands() {
-                return Shell.getCommands(session);
+                return factory.getRegistry().getCommands().stream()
+                        .map(c -> c.getScope() + ":" + c.getName())
+                        .collect(Collectors.toSet());
             }
             @Override
             public String resolveCommand(String command) {
-                return Shell.resolve(session, command);
+                String resolved = command;
+                if (command.indexOf(':') < 0) {
+                    Set<String> commands = getCommands();
+                    Object path = session.get(VAR_SCOPE);
+                    String scopePath = (null == path ? "*" : path.toString());
+                    for (String scope : scopePath.split(":")) {
+                        for (String entry : commands) {
+                            if ("*".equals(scope) && entry.endsWith(":" + command)
+                                    || entry.equals(scope + ":" + command)) {
+                                resolved = entry;
+                                break;
+                            }
+                        }
+                    }
+                }
+                return resolved;
             }
             @Override
             public String commandName(String command) {


Mime
View raw message