Set --password as a required option in JOpt parser

This commit is contained in:
Chris Beams 2020-04-26 21:05:22 +02:00
parent 822e6813f8
commit 5fa7939ec4
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
3 changed files with 8 additions and 28 deletions

View File

@ -75,7 +75,8 @@ public class CliMain {
.defaultsTo(9998);
var passwordOpt = parser.accepts("password", "rpc server password")
.withRequiredArg();
.withRequiredArg()
.required();
OptionSet options = null;
try {
@ -110,10 +111,8 @@ public class CliMain {
var host = options.valueOf(hostOpt);
var port = options.valueOf(portOpt);
var password = options.valueOf(passwordOpt);
if (password == null) {
err.println("Error: rpc server password not specified");
exit(EXIT_FAILURE);
}
var credentials = new PasswordCallCredentials(password);
var channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@ -126,8 +125,6 @@ public class CliMain {
}));
try {
var credentials = new PasswordCallCredentials(password);
switch (method) {
case getversion: {
var stub = GetVersionGrpc.newBlockingStub(channel).withCallCredentials(credentials);

View File

@ -21,7 +21,7 @@ class PasswordCallCredentials extends CallCredentials {
public PasswordCallCredentials(String passwordValue) {
if (passwordValue == null)
throw new IllegalArgumentException(format("'%s' header value must not be null", PASSWORD_KEY));
throw new IllegalArgumentException(format("'%s' value must not be null", PASSWORD_KEY));
this.passwordValue = passwordValue;
}

View File

@ -51,9 +51,9 @@ echo "========================================================================"
OUTPUT=$(expect -c '
# exp_internal 1
puts "TEST getversion (no pwd error)"
set expected "Error: rpc server password not specified"
spawn ./bisq-cli getversion
puts "TEST missing required password option error"
set expected "Error: Missing required option(s) \\\[password\\\]"
spawn ./bisq-cli anymethod
expect {
$expected { puts "PASS" }
default {
@ -118,23 +118,6 @@ OUTPUT=$(expect -c '
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
puts "TEST getbalance (no pwd error)"
# exp_internal 1
set expected "Error: rpc server password not specified"
spawn ./bisq-cli getbalance
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
OUTPUT=$(expect -c '
puts "TEST getbalance"
# exp_internal 1