Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The shell performs the following Linux like commands:
set <arg> - set environment variable with arg value in the following format: key=value
touch <arg> - create empty member if does not exist, arg represents a member or dataset(member)
uname - show current connected host name
usermod <arg> - modify username or password of current connection, arg can be -u or -p"
vi <arg> - where arg is a sequential dataset or member name, arg will be downloaded
and displayed for editing, use save command to save changes
whoami - show current connected user name
Expand Down Expand Up @@ -150,23 +151,27 @@ You can override the default file name and its location by setting the following

The configuration file consists of JSON data. The configuration JSON string is defined as a JSON array structure. The array will consist of one or more profile(s).

A profile is a one-to-one relationship of Profile.java file within the project. It contains variables as a placeholder for configuration information, such as z/OSMF and ssh connection information and properties to control the Window environment.
A profile is a one-to-one relationship of Profile.java file within the project. It contains variables as a placeholder for configuration information, such as z/OSMF and SSH connection information and properties to control the Window environment.

In addition, each profile contains path variable to control location for download directory.

The first JSON array entry in the example below shows all the attributes defined to be read by the application.
In addition, each profile contains path variable to control location for the download directory.

The other JSON array entries shows that you don't need to specify all attributes and its values. The attributes most critical are those that specify a z/OSMF connection: hostname, zosmfport, username, and password.
The first JSON array entry in the example below shows all the attributes defined to be read by the application.

The other JSON array entries shows that you don't need to specify all attributes and its values. The attributes most critical are those that specify a z/OSMF connection: hostname and zosmfport.

The username and password entries are optional. It is recommended to not specify those settings. When not specified, the application will prompt end user for username and password for the current connection.

For further details on username and password usage see [here](https://github.com/Zowe-Java-SDK/ZosShell/issues/178)

Example of config.json:

[
{
"hostname": "xxxxxxxxx",
"zosmfport": "xxxx",
"sshport" : "xxxx",
"username": "xxxxx",
"password": "xxxxxx",
"username": "",
"password": "",
"downloadpath": "/ZosShell",
"consolename": "",
"window": {
Expand All @@ -180,8 +185,6 @@ Example of config.json:
"hostname": "xxxxxxxxx",
"zosmfport": "xxxx",
"sshport" : "xxxx",
"username": "xxxxx",
"password": "xxxxxx",
"downloadpath": "C:\\ZosShell3",
"consolename": "",
"window": {}
Expand All @@ -190,8 +193,6 @@ Example of config.json:
"hostname": "xxxxxxxxx",
"zosmfport": "xxxx",
"sshport" : "xxxx",
"username": "xxxxx",
"password": "xxxxxx",
"downloadpath": "C:\\ZosShell",
"consolename": "",
"window": {}
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/zos/shell/ZosShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import zos.shell.singleton.configuration.ConfigSingleton;
import zos.shell.utility.PromptUtil;
import zos.shell.utility.StrUtil;
import zowe.client.sdk.core.SshConnection;
import zowe.client.sdk.core.ZosConnection;
import zowe.client.sdk.utility.ValidateUtils;

import java.io.IOException;
Expand Down Expand Up @@ -53,7 +55,7 @@ public static void main(String[] args) {

// initialize ConnSingleton object
var connSingleton = ConnSingleton.getInstance();
connSingleton.setCurrZosConnection(ConfigSingleton.getInstance().getZosConnectionByIndex(0));
connSingleton.setCurrZosConnection(ConfigSingleton.getInstance().getZosConnectionByIndex(0), 0);
connSingleton.setCurrSshConnection(ConfigSingleton.getInstance().getSshConnectionByIndex(0));
var title = Constants.APP_TITLE + " - " + connSingleton.getCurrSshConnection().getHost().toUpperCase();
TerminalSingleton.getInstance().getMainTerminal().setPaneTitle(title);
Expand Down Expand Up @@ -86,13 +88,37 @@ public void accept(TextIO textIO, RunnerData runnerData) {
// local variables copies from singletons
TextTerminal<?> terminal = TerminalSingleton.getInstance().getTerminal();
var currConnection = ConnSingleton.getInstance().getCurrZosConnection();
var currSshConnection = ConnSingleton.getInstance().getCurrSshConnection();

// display information on initial first connection defined and set for usage
// setup initial first connection definition and prompt for username and password if applicable.
try {
ValidateUtils.checkConnection(currConnection);
var host = currConnection.getHost();
var user = currConnection.getUser();
terminal.println("Connected to " + host + " as user " + user + ".");
var zosmfport = currConnection.getZosmfPort();
var username = currConnection.getUser();
var password = currConnection.getPassword();
if (host.isBlank() || zosmfport.isBlank() || "0".equals(zosmfport)) {
throw new IllegalStateException("Error: Hostname or z/OSMF port value(s) missing\n" +
"Check configuration file and try again...");
}

if (username.isBlank() || password.isBlank()) {
terminal.println("Enter username and password for host " + host);
username = PromptUtil.getPromptInfo("username:", false);
password = PromptUtil.getPromptInfo("password:", true);

currConnection = new ZosConnection(host, zosmfport, username, password);

ValidateUtils.checkConnection(currConnection);
ConfigSingleton.getInstance().setZosConnectionByIndex(currConnection, 0);
ConnSingleton.getInstance().setCurrZosConnection(currConnection, 0);
currSshConnection = new SshConnection(host, currSshConnection.getPort(), username, password);
ConfigSingleton.getInstance().setSshConnectionByIndex(currSshConnection, 0);
ConnSingleton.getInstance().setCurrSshConnection(currSshConnection);
}
var msg = String.format("Connection defined:\nhost:%s\nuser:%s\nzosmfport:%s\nsshport:%s",
currConnection.getHost(), currConnection.getUser(), currConnection.getZosmfPort(),
currSshConnection.getPort());
terminal.println(msg);
} catch (Exception e) {
var mainTerminal = TerminalSingleton.getInstance().getMainTerminal();
mainTerminal.println("ERROR: Default connection invalid, try again...");
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/zos/shell/command/CommandRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,25 @@ public void routeCommand(String[] params) {
if (isParamsExceeded(2, params)) {
return;
}
int changeIndex;
try {
changeIndex = Integer.parseInt(params[1]);
} catch (NumberFormatException e) {
terminal.println(Constants.INVALID_COMMAND);
return;
}
var previousCurrConnection = currConnection;
var changeConnController = controllerContainer.getChangeConnController(terminal);
currConnection = changeConnController.changeZosConnection(currConnection, params);
ConnSingleton.getInstance().setCurrZosConnection(currConnection);
ConnSingleton.getInstance().setCurrZosConnection(currConnection, changeIndex);
currSshConnection = changeConnController.changeSshConnection(currSshConnection, params);
ConnSingleton.getInstance().setCurrSshConnection(currSshConnection);
var msg = "Connected to " + currConnection.getHost() + " as user " + currConnection.getUser() + ".";
terminal.println(msg);
if (previousCurrConnection != currConnection) {
var msg = String.format("Connection changed:\nhost:%s\nuser:%s\nzosmfport:%s\nsshport:%s",
currConnection.getHost(), currConnection.getUser(), currConnection.getZosmfPort(),
currSshConnection.getPort());
terminal.println(msg);
}
TerminalSingleton.getInstance().getMainTerminal()
.setPaneTitle(Constants.APP_TITLE + " - " + currConnection.getHost().toUpperCase());
break;
Expand Down Expand Up @@ -633,6 +645,19 @@ public void routeCommand(String[] params) {
String unameResult = unameController.uname(currConnection);
terminal.println(unameResult);
break;
case "usermod":
if (isParamsMissing(1, params)) {
return;
}
if (isParamsExceeded(2, params)) {
return;
}
var usermodController = controllerContainer.getUsermodController(currConnection,
ConnSingleton.getInstance().getCurrZosConnectionIndex());
var flag = params[1];
String usermodResult = usermodController.change(flag);
terminal.println(usermodResult);
break;
case "ussh":
if (isParamsMissing(1, params)) {
return;
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/zos/shell/controller/UsermodController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package zos.shell.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zos.shell.constants.Constants;
import zos.shell.service.usermod.UsermodService;

public class UsermodController {

private static final Logger LOG = LoggerFactory.getLogger(UsermodController.class);

private final UsermodService usermodService;

public UsermodController(final UsermodService usermodService) {
LOG.debug("*** UsermodController ***");
this.usermodService = usermodService;
}

public String change(final String flag) {
LOG.debug("*** change ***");
if ("-u".equalsIgnoreCase(flag)) {
return usermodService.changeUsername();
}
if ("-p".equalsIgnoreCase(flag)) {
return usermodService.changePassword();
} else {
return Constants.INVALID_COMMAND;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import zos.shell.service.rename.RenameService;
import zos.shell.service.search.SearchCacheService;
import zos.shell.service.tso.TsoService;
import zos.shell.service.usermod.UsermodService;
import zowe.client.sdk.core.SshConnection;
import zowe.client.sdk.core.ZosConnection;
import zowe.client.sdk.zosconsole.method.IssueConsole;
Expand Down Expand Up @@ -503,6 +504,12 @@ public UnameController getUnameController(final ZosConnection connection, final
return this.unameController;
}

public UsermodController getUsermodController(final ZosConnection connection, final int index) {
LOG.debug("*** getUsermodController ***");
var usermodService = new UsermodService(connection, index);
return new UsermodController(usermodService);
}

public UssController getUssController(final SshConnection connection) {
LOG.debug("*** getUssController ***");
if (this.ussController == null ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public final class SearchCommandService {
private static final String[] commands = new String[]{"browsejob", "cancel", "cat", "cd", "change", "clear",
"color", "connections", "count", "copy", "download", "downloadjob", "end", "env", "files", "grep",
"help", "history", "hostname", "ls", "mkdir", "mvs", "purge", "ps", "pwd", "rename", "rm", "rn", "save",
"search", "set", "stop", "submit", "tail", "timeout", "touch", "tso", "uname", "ussh", "vi", "visited",
"whoami"};
"search", "set", "stop", "submit", "tail", "timeout", "touch", "tso", "uname", "usermod", "ussh", "vi",
"visited", "whoami"};

private final TriePreFix dictionary = new TriePreFix(commands);

Expand Down
39 changes: 37 additions & 2 deletions src/main/java/zos/shell/service/change/ChangeConnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import zos.shell.constants.Constants;
import zos.shell.singleton.configuration.ConfigSingleton;
import zos.shell.singleton.configuration.record.ConfigSettings;
import zos.shell.utility.PromptUtil;
import zowe.client.sdk.core.SshConnection;
import zowe.client.sdk.core.ZosConnection;

Expand Down Expand Up @@ -33,7 +34,29 @@ public ZosConnection changeZosConnection(final ZosConnection zosConnection, fina
var profile = configSingleton.getProfileByIndex(index);
ConfigSingleton.getInstance().setConfigSettings(new ConfigSettings(profile.getDownloadpath(),
profile.getConsolename(), profile.getWindow()));

var zosConnectionByIndex = configSingleton.getZosConnectionByIndex(index);
var host = zosConnectionByIndex.getHost();
var username = zosConnectionByIndex.getUser();
var password = zosConnectionByIndex.getPassword();
var zosmfport = zosConnectionByIndex.getZosmfPort();

if (host.isBlank() || zosmfport.isBlank()) {
terminal.println("Error: Hostname or z/OSMF port value(s) missing");
terminal.println("Check configuration file and try again...");
return zosConnection;
}

if (!username.isBlank() && !password.isBlank()) {
ConfigSingleton.getInstance().updateWindowSittings(terminal);
return zosConnectionByIndex;
}

terminal.println("Enter username and password for host " + host);
username = PromptUtil.getPromptInfo("username:", false);
password = PromptUtil.getPromptInfo("password:", true);
ConfigSingleton.getInstance().updateWindowSittings(terminal);
configSingleton.setZosConnectionByIndex(new ZosConnection(host, zosmfport, username, password), index);
return configSingleton.getZosConnectionByIndex(index);
}

Expand All @@ -43,14 +66,26 @@ public SshConnection changeSshConnection(final SshConnection sshConnection, fina
if (index-- > configSingleton.getZosConnections().size()) {
return sshConnection;
}

var zosConnectionByIndex = configSingleton.getZosConnectionByIndex(index);
var zosUsername = zosConnectionByIndex.getUser();
var zosPassword = zosConnectionByIndex.getPassword();

var sshConnectionByIndex = configSingleton.getSshConnectionByIndex(index);
var sshHost = sshConnectionByIndex.getHost();
var sshPort = sshConnectionByIndex.getPort();

configSingleton.setSshConnectionByIndex(new SshConnection(sshHost, sshPort, zosUsername, zosPassword), index);
return configSingleton.getSshConnectionByIndex(index);
}

public void displayConnections() {
LOG.debug("*** displayConnections ***");
var i = new AtomicInteger(1);
configSingleton.getZosConnections().forEach(c -> terminal.println(i.getAndIncrement() + " " + "hostname: " +
c.getHost() + ", port: " + c.getZosmfPort() + ", user: " + c.getUser()));
configSingleton.getZosConnections().forEach(
c -> terminal.println(i.getAndIncrement() + " " + "hostname: " +
(c.getHost().isBlank() ? "n\\a" : c.getHost()) + ", zosmfport: " +
(c.getZosmfPort().isBlank() ? "n\\a" : c.getZosmfPort())));
if (configSingleton.getZosConnections().isEmpty()) {
terminal.println(Constants.NO_CONNECTION_INFO);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/zos/shell/service/help/HelpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class HelpService {
"touch <arg> - create empty member if does not exist, arg represents a member or dataset(member)",
"tso <arg> - execute a tso command where arg is a command string within double quotes",
"uname - show current connected host name",
"usermod <arg> - modify username or password of current connection, arg can be -u or -p",
"ussh <arg> - execute USS/UNIX command via SSH connection where arg is a command string within double quotes",
"vi <arg> - where arg is a sequential dataset or member name, arg will be downloaded",
" and displayed for editing, use save command to save changes",
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/zos/shell/service/usermod/UsermodService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package zos.shell.service.usermod;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zos.shell.singleton.ConnSingleton;
import zos.shell.singleton.configuration.ConfigSingleton;
import zos.shell.utility.PromptUtil;
import zowe.client.sdk.core.SshConnection;
import zowe.client.sdk.core.ZosConnection;

public class UsermodService {

private static final Logger LOG = LoggerFactory.getLogger(UsermodService.class);

private final String host;
private final String zosmfPort;
private final String username;
private final String password;
private final int sshPort;

private final int index;

public UsermodService(final ZosConnection connection, final int index) {
LOG.debug("*** UsermodService ***");
this.host = connection.getHost();
this.zosmfPort = connection.getZosmfPort();
this.username = connection.getUser();
this.password = connection.getPassword();
this.sshPort = ConfigSingleton.getInstance().getSshConnectionByIndex(index).getPort();
this.index = index;
}

public String changePassword() {
LOG.debug("*** changePassword ***");
var password = PromptUtil.getPromptInfo("password:", true);
var zosConnection = new ZosConnection(this.host, this.zosmfPort, this.username, password);
var sshConnection = new SshConnection(this.host, this.sshPort, this.username, password);
ConfigSingleton.getInstance().setZosConnectionByIndex(zosConnection, index);
ConnSingleton.getInstance().setCurrZosConnection(zosConnection, index);
ConfigSingleton.getInstance().setSshConnectionByIndex(sshConnection, index);
ConnSingleton.getInstance().setCurrSshConnection(sshConnection);
return "password changed";
}

public String changeUsername() {
LOG.debug("*** changeUsername ***");
var username = PromptUtil.getPromptInfo("username:", false);
var zosConnection = new ZosConnection(this.host, this.zosmfPort, username, this.password);
var sshConnection = new SshConnection(this.host, this.sshPort, username, this.password);
ConfigSingleton.getInstance().setZosConnectionByIndex(zosConnection, index);
ConnSingleton.getInstance().setCurrZosConnection(zosConnection, index);
ConfigSingleton.getInstance().setSshConnectionByIndex(sshConnection, index);
ConnSingleton.getInstance().setCurrSshConnection(sshConnection);
return "username changed";
}

}
Loading