Add deployment routes for use by Ansible
This commit is contained in:
parent
76c0148b89
commit
db0adc8b87
@ -55,6 +55,7 @@ import net.frozenorb.apiv3.route.chatFilter.DELETEChatFilterId;
|
|||||||
import net.frozenorb.apiv3.route.chatFilter.GETChatFilter;
|
import net.frozenorb.apiv3.route.chatFilter.GETChatFilter;
|
||||||
import net.frozenorb.apiv3.route.chatFilter.GETChatFilterId;
|
import net.frozenorb.apiv3.route.chatFilter.GETChatFilterId;
|
||||||
import net.frozenorb.apiv3.route.chatFilter.POSTChatFilter;
|
import net.frozenorb.apiv3.route.chatFilter.POSTChatFilter;
|
||||||
|
import net.frozenorb.apiv3.route.deployment.POSTDeploymentUpdateServer;
|
||||||
import net.frozenorb.apiv3.route.disposableLoginTokens.POSTDisposableLoginTokens;
|
import net.frozenorb.apiv3.route.disposableLoginTokens.POSTDisposableLoginTokens;
|
||||||
import net.frozenorb.apiv3.route.disposableLoginTokens.POSTDisposableLoginTokensIdUse;
|
import net.frozenorb.apiv3.route.disposableLoginTokens.POSTDisposableLoginTokensIdUse;
|
||||||
import net.frozenorb.apiv3.route.emailTokens.GETEmailTokensIdOwner;
|
import net.frozenorb.apiv3.route.emailTokens.GETEmailTokensIdOwner;
|
||||||
@ -372,6 +373,8 @@ public final class APIv3 extends AbstractVerticle {
|
|||||||
//http.put("/chatFilter/:chatFilterEntryId").blockingHandler(new PUTChatFilterId(), false);
|
//http.put("/chatFilter/:chatFilterEntryId").blockingHandler(new PUTChatFilterId(), false);
|
||||||
http.delete("/chatFilter/:chatFilterEntryId").blockingHandler(new DELETEChatFilterId(), false);
|
http.delete("/chatFilter/:chatFilterEntryId").blockingHandler(new DELETEChatFilterId(), false);
|
||||||
|
|
||||||
|
http.post("/deployment/updateServer/:serverId").blockingHandler(new POSTDeploymentUpdateServer(), false);
|
||||||
|
|
||||||
http.post("/disposableLoginTokens").blockingHandler(new POSTDisposableLoginTokens(), false);
|
http.post("/disposableLoginTokens").blockingHandler(new POSTDisposableLoginTokens(), false);
|
||||||
http.post("/disposableLoginTokens/:disposableLoginToken/use").blockingHandler(new POSTDisposableLoginTokensIdUse(), false);
|
http.post("/disposableLoginTokens/:disposableLoginToken/use").blockingHandler(new POSTDisposableLoginTokensIdUse(), false);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import fr.javatic.mongo.jacksonCodec.Entity;
|
|||||||
import fr.javatic.mongo.jacksonCodec.objectId.Id;
|
import fr.javatic.mongo.jacksonCodec.objectId.Id;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -31,9 +32,9 @@ public final class AccessToken {
|
|||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private String actorName;
|
@Getter private String actorName;
|
||||||
@Getter private ActorType actorType;
|
@Getter private ActorType actorType;
|
||||||
@Getter private List<String> lockedIps;
|
@Getter @Setter private List<String> lockedIps;
|
||||||
@Getter private Instant createdAt;
|
@Getter private Instant createdAt;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter @Setter private Instant lastUpdatedAt;
|
||||||
|
|
||||||
public static void findAll(SingleResultCallback<List<AccessToken>> callback) {
|
public static void findAll(SingleResultCallback<List<AccessToken>> callback) {
|
||||||
accessTokensCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
accessTokensCollection.find().into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||||
|
@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import fr.javatic.mongo.jacksonCodec.Entity;
|
import fr.javatic.mongo.jacksonCodec.Entity;
|
||||||
import fr.javatic.mongo.jacksonCodec.objectId.Id;
|
import fr.javatic.mongo.jacksonCodec.objectId.Id;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public final class Server {
|
public final class Server {
|
||||||
@ -39,8 +40,8 @@ public final class Server {
|
|||||||
@Getter @Id private String id;
|
@Getter @Id private String id;
|
||||||
@Getter private String displayName;
|
@Getter private String displayName;
|
||||||
@Getter private String serverGroup;
|
@Getter private String serverGroup;
|
||||||
@Getter private String serverIp;
|
@Getter @Setter private String serverIp;
|
||||||
@Getter private Instant lastUpdatedAt;
|
@Getter @Setter private Instant lastUpdatedAt;
|
||||||
@Getter private double lastTps;
|
@Getter private double lastTps;
|
||||||
@Getter @ExcludeFromReplies private Set<UUID> players;
|
@Getter @ExcludeFromReplies private Set<UUID> players;
|
||||||
|
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
package net.frozenorb.apiv3.route.deployment;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import net.frozenorb.apiv3.actor.ActorType;
|
||||||
|
import net.frozenorb.apiv3.model.AccessToken;
|
||||||
|
import net.frozenorb.apiv3.model.Server;
|
||||||
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.SyncUtils;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
import io.vertx.core.Handler;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.ext.web.RoutingContext;
|
||||||
|
|
||||||
|
public final class POSTDeploymentUpdateServer implements Handler<RoutingContext> {
|
||||||
|
|
||||||
|
public void handle(RoutingContext ctx) {
|
||||||
|
String serverId = ctx.request().getParam("serverId");
|
||||||
|
|
||||||
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
|
String ip = requestBody.getString("ip");
|
||||||
|
int port = requestBody.getInteger("port", 0);
|
||||||
|
|
||||||
|
if (ip == null || port == 0) {
|
||||||
|
ErrorUtils.respondInvalidInput(ctx, "'ip' and 'port' are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Server server = Server.findById(serverId);
|
||||||
|
AccessToken accessToken = SyncUtils.runBlocking(v -> AccessToken.findByNameAndType(serverId, ActorType.SERVER, v));
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
ErrorUtils.respondNotFound(ctx, "server", serverId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessToken == null) {
|
||||||
|
ErrorUtils.respondNotFound(ctx, "access token", serverId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
server.setServerIp(ip + ":" + port);
|
||||||
|
server.setLastUpdatedAt(Instant.now());
|
||||||
|
|
||||||
|
accessToken.setLockedIps(ImmutableList.of(ip));
|
||||||
|
accessToken.setLastUpdatedAt(Instant.now());
|
||||||
|
|
||||||
|
SyncUtils.<Void>runBlocking(server::save);
|
||||||
|
SyncUtils.<Void>runBlocking(accessToken::save);
|
||||||
|
|
||||||
|
ctx.response().end(accessToken.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user