Add 'apiPort' configuration option

This commit is contained in:
Chris Beams 2020-04-25 14:33:44 +02:00
parent 82f1b66818
commit 3badf299e3
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
2 changed files with 11 additions and 3 deletions

View File

@ -117,6 +117,7 @@ public class Config {
public static final String DUMP_DELAYED_PAYOUT_TXS = "dumpDelayedPayoutTxs"; public static final String DUMP_DELAYED_PAYOUT_TXS = "dumpDelayedPayoutTxs";
public static final String ALLOW_FAULTY_DELAYED_TXS = "allowFaultyDelayedTxs"; public static final String ALLOW_FAULTY_DELAYED_TXS = "allowFaultyDelayedTxs";
public static final String API_PASSWORD = "apiPassword"; public static final String API_PASSWORD = "apiPassword";
public static final String API_PORT = "apiPort";
// Default values for certain options // Default values for certain options
public static final int UNSPECIFIED_PORT = -1; public static final int UNSPECIFIED_PORT = -1;
@ -201,6 +202,7 @@ public class Config {
public final boolean dumpDelayedPayoutTxs; public final boolean dumpDelayedPayoutTxs;
public final boolean allowFaultyDelayedTxs; public final boolean allowFaultyDelayedTxs;
public final String apiPassword; public final String apiPassword;
public final int apiPort;
// Properties derived from options but not exposed as options themselves // Properties derived from options but not exposed as options themselves
public final File torDir; public final File torDir;
@ -622,6 +624,12 @@ public class Config {
.withRequiredArg() .withRequiredArg()
.defaultsTo(""); .defaultsTo("");
ArgumentAcceptingOptionSpec<Integer> apiPortOpt =
parser.accepts(API_PORT, "gRPC API port")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(9998);
try { try {
CompositeOptionSet options = new CompositeOptionSet(); CompositeOptionSet options = new CompositeOptionSet();
@ -735,6 +743,7 @@ public class Config {
this.dumpDelayedPayoutTxs = options.valueOf(dumpDelayedPayoutTxsOpt); this.dumpDelayedPayoutTxs = options.valueOf(dumpDelayedPayoutTxsOpt);
this.allowFaultyDelayedTxs = options.valueOf(allowFaultyDelayedTxsOpt); this.allowFaultyDelayedTxs = options.valueOf(allowFaultyDelayedTxsOpt);
this.apiPassword = options.valueOf(apiPasswordOpt); this.apiPassword = options.valueOf(apiPasswordOpt);
this.apiPort = options.valueOf(apiPortOpt);
} catch (OptionException ex) { } catch (OptionException ex) {
throw new ConfigException("problem parsing option '%s': %s", throw new ConfigException("problem parsing option '%s': %s",
ex.options().get(0), ex.options().get(0),

View File

@ -56,14 +56,13 @@ import lombok.extern.slf4j.Slf4j;
public class GrpcServer { public class GrpcServer {
private final CoreApi coreApi; private final CoreApi coreApi;
private final int port;
public GrpcServer(Config config, CoreApi coreApi) { public GrpcServer(Config config, CoreApi coreApi) {
this.coreApi = coreApi; this.coreApi = coreApi;
this.port = config.apiPort;
try { try {
// TODO add to options
int port = 9998;
var server = ServerBuilder.forPort(port) var server = ServerBuilder.forPort(port)
.addService(new GetVersionService()) .addService(new GetVersionService())
.addService(new GetBalanceService()) .addService(new GetBalanceService())