Add version in jar
- Cli argument - In HTTP client - /version endpoint
This commit is contained in:
@@ -152,6 +152,14 @@ dependencies {
|
|||||||
testCompile 'com.icegreen:greenmail:1.5.9'
|
testCompile 'com.icegreen:greenmail:1.5.9'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
'Implementation-Version': mxisdVersion()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
baseName = project.name
|
baseName = project.name
|
||||||
classifier = null
|
classifier = null
|
||||||
|
|||||||
@@ -36,10 +36,13 @@ import io.kamax.mxisd.http.undertow.handler.profile.v1.InternalProfileHandler;
|
|||||||
import io.kamax.mxisd.http.undertow.handler.profile.v1.ProfileHandler;
|
import io.kamax.mxisd.http.undertow.handler.profile.v1.ProfileHandler;
|
||||||
import io.kamax.mxisd.http.undertow.handler.register.v1.Register3pidRequestTokenHandler;
|
import io.kamax.mxisd.http.undertow.handler.register.v1.Register3pidRequestTokenHandler;
|
||||||
import io.kamax.mxisd.http.undertow.handler.status.StatusHandler;
|
import io.kamax.mxisd.http.undertow.handler.status.StatusHandler;
|
||||||
|
import io.kamax.mxisd.http.undertow.handler.status.VersionHandler;
|
||||||
import io.undertow.Handlers;
|
import io.undertow.Handlers;
|
||||||
import io.undertow.Undertow;
|
import io.undertow.Undertow;
|
||||||
import io.undertow.server.HttpHandler;
|
import io.undertow.server.HttpHandler;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class HttpMxisd {
|
public class HttpMxisd {
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
@@ -67,6 +70,7 @@ public class HttpMxisd {
|
|||||||
|
|
||||||
// Status endpoints
|
// Status endpoints
|
||||||
.get(StatusHandler.Path, SaneHandler.around(new StatusHandler()))
|
.get(StatusHandler.Path, SaneHandler.around(new StatusHandler()))
|
||||||
|
.get(VersionHandler.Path, SaneHandler.around(new VersionHandler()))
|
||||||
|
|
||||||
// Authentication endpoints
|
// Authentication endpoints
|
||||||
.get(LoginHandler.Path, SaneHandler.around(new LoginGetHandler(m.getAuth(), m.getHttpClient())))
|
.get(LoginHandler.Path, SaneHandler.around(new LoginGetHandler(m.getAuth(), m.getHttpClient())))
|
||||||
@@ -119,7 +123,9 @@ public class HttpMxisd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
httpSrv.stop();
|
// Because it might have never been initialized if an exception is thrown early
|
||||||
|
if (Objects.nonNull(httpSrv)) httpSrv.stop();
|
||||||
|
|
||||||
m.stop();
|
m.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import io.kamax.mxisd.storage.crypto.Ed25519KeyManager;
|
|||||||
import io.kamax.mxisd.storage.crypto.KeyManager;
|
import io.kamax.mxisd.storage.crypto.KeyManager;
|
||||||
import io.kamax.mxisd.storage.crypto.SignatureManager;
|
import io.kamax.mxisd.storage.crypto.SignatureManager;
|
||||||
import io.kamax.mxisd.storage.ormlite.OrmLiteSqlStorage;
|
import io.kamax.mxisd.storage.ormlite.OrmLiteSqlStorage;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
|
||||||
@@ -58,6 +59,8 @@ import java.util.ServiceLoader;
|
|||||||
|
|
||||||
public class Mxisd {
|
public class Mxisd {
|
||||||
|
|
||||||
|
public static final String Version = StringUtils.defaultIfBlank(Mxisd.class.getPackage().getImplementationVersion(), "UNKNOWN");
|
||||||
|
|
||||||
private MxisdConfig cfg;
|
private MxisdConfig cfg;
|
||||||
|
|
||||||
private CloseableHttpClient httpClient;
|
private CloseableHttpClient httpClient;
|
||||||
@@ -86,7 +89,7 @@ public class Mxisd {
|
|||||||
|
|
||||||
private void build() {
|
private void build() {
|
||||||
httpClient = HttpClients.custom()
|
httpClient = HttpClients.custom()
|
||||||
.setUserAgent("mxisd")
|
.setUserAgent("mxisd/" + Version)
|
||||||
.setMaxConnPerRoute(Integer.MAX_VALUE)
|
.setMaxConnPerRoute(Integer.MAX_VALUE)
|
||||||
.setMaxConnTotal(Integer.MAX_VALUE)
|
.setMaxConnTotal(Integer.MAX_VALUE)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -37,21 +37,33 @@ public class MxisdStandaloneExec {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
log.info("------------- mxisd starting -------------");
|
|
||||||
MxisdConfig cfg = null;
|
MxisdConfig cfg = null;
|
||||||
|
|
||||||
Iterator<String> argsIt = Arrays.asList(args).iterator();
|
Iterator<String> argsIt = Arrays.asList(args).iterator();
|
||||||
while (argsIt.hasNext()) {
|
while (argsIt.hasNext()) {
|
||||||
String arg = argsIt.next();
|
String arg = argsIt.next();
|
||||||
if (StringUtils.equals("-c", arg)) {
|
if (StringUtils.equalsAny(arg, "-h", "--help", "-?", "--usage")) {
|
||||||
|
System.out.println("Available arguments:" + System.lineSeparator());
|
||||||
|
System.out.println(" -h, --help Show this help message");
|
||||||
|
System.out.println(" --version Print the version then exit");
|
||||||
|
System.out.println(" -c, --config Set the configuration file location");
|
||||||
|
System.out.println(" ");
|
||||||
|
System.exit(0);
|
||||||
|
} else if (StringUtils.equalsAny(arg, "-c", "--config")) {
|
||||||
String cfgFile = argsIt.next();
|
String cfgFile = argsIt.next();
|
||||||
cfg = YamlConfigLoader.loadFromFile(cfgFile);
|
cfg = YamlConfigLoader.loadFromFile(cfgFile);
|
||||||
|
} else if (StringUtils.equals("--version", arg)) {
|
||||||
|
System.out.println(Mxisd.Version);
|
||||||
|
System.exit(0);
|
||||||
} else {
|
} else {
|
||||||
log.info("Invalid argument: {}", arg);
|
System.err.println("Invalid argument: " + arg);
|
||||||
|
System.err.println("Try '--help' for available arguments");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("mxisd starting");
|
||||||
|
log.info("Version: {}", Mxisd.Version);
|
||||||
|
|
||||||
if (Objects.isNull(cfg)) {
|
if (Objects.isNull(cfg)) {
|
||||||
cfg = YamlConfigLoader.tryLoadFromFile("mxisd.yaml").orElseGet(MxisdConfig::new);
|
cfg = YamlConfigLoader.tryLoadFromFile("mxisd.yaml").orElseGet(MxisdConfig::new);
|
||||||
}
|
}
|
||||||
@@ -59,11 +71,11 @@ public class MxisdStandaloneExec {
|
|||||||
HttpMxisd mxisd = new HttpMxisd(cfg);
|
HttpMxisd mxisd = new HttpMxisd(cfg);
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
mxisd.stop();
|
mxisd.stop();
|
||||||
log.info("------------- mxisd stopped -------------");
|
log.info("mxisd stopped");
|
||||||
}));
|
}));
|
||||||
mxisd.start();
|
mxisd.start();
|
||||||
|
|
||||||
log.info("------------- mxisd started -------------");
|
log.info("mxisd started");
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
log.error(e.getDetailedMessage());
|
log.error(e.getDetailedMessage());
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import io.undertow.server.HttpServerExchange;
|
|||||||
|
|
||||||
public class StatusHandler extends BasicHttpHandler {
|
public class StatusHandler extends BasicHttpHandler {
|
||||||
|
|
||||||
public static final String Path = "/_matrix/identity/status";
|
public static final String Path = "/status";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(HttpServerExchange exchange) {
|
public void handleRequest(HttpServerExchange exchange) {
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* mxisd - Matrix Identity Server Daemon
|
||||||
|
* Copyright (C) 2019 Kamax Sarl
|
||||||
|
*
|
||||||
|
* https://www.kamax.io/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.kamax.mxisd.http.undertow.handler.status;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import io.kamax.matrix.json.GsonUtil;
|
||||||
|
import io.kamax.mxisd.Mxisd;
|
||||||
|
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||||
|
import io.undertow.server.HttpServerExchange;
|
||||||
|
|
||||||
|
public class VersionHandler extends BasicHttpHandler {
|
||||||
|
|
||||||
|
public static final String Path = "/version";
|
||||||
|
|
||||||
|
private final String body;
|
||||||
|
|
||||||
|
public VersionHandler() {
|
||||||
|
JsonObject server = new JsonObject();
|
||||||
|
server.addProperty("name", "mxisd");
|
||||||
|
server.addProperty("version", Mxisd.Version);
|
||||||
|
|
||||||
|
body = GsonUtil.getPrettyForLog(GsonUtil.makeObj("server", server));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleRequest(HttpServerExchange exchange) {
|
||||||
|
respondJson(exchange, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user