Part 1 of the big "make this closer to a RESTful api" commit

This commit is contained in:
Colin McDonald 2016-06-21 17:08:17 -04:00
parent 217683407e
commit 8ade7066f9
41 changed files with 146 additions and 526 deletions

View File

@ -27,40 +27,37 @@ import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.handler.LoggerFormat;
import io.vertx.ext.web.handler.LoggerHandler;
import io.vertx.ext.web.handler.TimeoutHandler;
import io.vertx.redis.RedisClient;
import io.vertx.redis.RedisOptions;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.handler.ActorAttributeHandler;
import net.frozenorb.apiv3.handler.AuthorizationHandler;
import net.frozenorb.apiv3.handler.LoaderIoHandler;
import net.frozenorb.apiv3.route.GETDump;
import net.frozenorb.apiv3.route.GETDumps;
import net.frozenorb.apiv3.route.GETWhoAmI;
import net.frozenorb.apiv3.route.POSTMetrics;
import net.frozenorb.apiv3.route.announcements.GETAnnouncements;
import net.frozenorb.apiv3.route.announcements.PUTAnnouncements;
import net.frozenorb.apiv3.route.auditLog.GETAuditLog;
import net.frozenorb.apiv3.route.auditLog.POSTUserAuditLogEntry;
import net.frozenorb.apiv3.route.chatFilterList.GETChatFilterList;
import net.frozenorb.apiv3.route.emailToken.GETEmailTokenOwner;
import net.frozenorb.apiv3.route.emailToken.POSTEmailTokenConfirm;
import net.frozenorb.apiv3.route.auditLog.POSTAuditLog;
import net.frozenorb.apiv3.route.chatFilterList.GETChatFilter;
import net.frozenorb.apiv3.route.emailToken.GETEmailTokensOwner;
import net.frozenorb.apiv3.route.emailToken.POSTEmailTokensConfirm;
import net.frozenorb.apiv3.route.grants.*;
import net.frozenorb.apiv3.route.ipBans.*;
import net.frozenorb.apiv3.route.ipIntel.GETIpIntel;
import net.frozenorb.apiv3.route.ipLog.GETUserIpLog;
import net.frozenorb.apiv3.route.notificationTemplates.DELETENotificationTemplate;
import net.frozenorb.apiv3.route.notificationTemplates.GETNotificationTemplate;
import net.frozenorb.apiv3.route.ipLog.GETIpLog;
import net.frozenorb.apiv3.route.notificationTemplates.DELETENotificationTemplatesId;
import net.frozenorb.apiv3.route.notificationTemplates.GETNotificationTemplatesId;
import net.frozenorb.apiv3.route.notificationTemplates.GETNotificationTemplates;
import net.frozenorb.apiv3.route.notificationTemplates.POSTNotificationTemplate;
import net.frozenorb.apiv3.route.notificationTemplates.POSTNotificationTemplates;
import net.frozenorb.apiv3.route.punishments.*;
import net.frozenorb.apiv3.route.ranks.DELETERank;
import net.frozenorb.apiv3.route.ranks.GETRank;
import net.frozenorb.apiv3.route.ranks.DELETERanksId;
import net.frozenorb.apiv3.route.ranks.GETRanksId;
import net.frozenorb.apiv3.route.ranks.GETRanks;
import net.frozenorb.apiv3.route.ranks.POSTRank;
import net.frozenorb.apiv3.route.serverGroups.DELETEServerGroup;
import net.frozenorb.apiv3.route.serverGroups.GETServerGroup;
import net.frozenorb.apiv3.route.ranks.POSTRanks;
import net.frozenorb.apiv3.route.serverGroups.DELETEServerGroupsId;
import net.frozenorb.apiv3.route.serverGroups.GETServerGroupsId;
import net.frozenorb.apiv3.route.serverGroups.GETServerGroups;
import net.frozenorb.apiv3.route.serverGroups.POSTServerGroup;
import net.frozenorb.apiv3.route.serverGroups.POSTServerGroups;
import net.frozenorb.apiv3.route.servers.*;
import net.frozenorb.apiv3.route.users.*;
import net.frozenorb.apiv3.serialization.gson.FollowAnnotationExclusionStrategy;
@ -75,18 +72,14 @@ import org.bson.Document;
import org.bson.codecs.BsonValueCodecProvider;
import org.bson.codecs.DocumentCodecProvider;
import org.bson.codecs.ValueCodecProvider;
import org.bson.codecs.configuration.CodecProvider;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecRegistry;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Slf4j
public final class APIv3 extends AbstractVerticle {
@ -97,9 +90,9 @@ public final class APIv3 extends AbstractVerticle {
@Getter private static Properties config = new Properties();
@Getter private static RedisClient redisClient;
private static final Gson gson = new GsonBuilder()
.registerTypeAdapter(Instant.class, new InstantTypeAdapter())
.setExclusionStrategies(new FollowAnnotationExclusionStrategy())
.create();
.registerTypeAdapter(Instant.class, new InstantTypeAdapter())
.setExclusionStrategies(new FollowAnnotationExclusionStrategy())
.create();
@Override
public void start() {
@ -144,7 +137,13 @@ public final class APIv3 extends AbstractVerticle {
MongoClient mongoClient = MongoClients.create(MongoClientSettings
.builder()
.codecRegistry(createCodecRegistry())
.codecRegistry(CodecRegistries.fromProviders(ImmutableList.of(
new UuidCodecProvider(), // MHQ, fixes uuid serialization
new ValueCodecProvider(),
new DocumentCodecProvider(),
new BsonValueCodecProvider(),
new JacksonCodecProvider(createMongoJacksonMapper()) // Jackson codec, provides serialization/deserialization
)))
.credentialList(credentials)
.clusterSettings(ClusterSettings.builder()
.applyConnectionString(connectionString)
@ -187,34 +186,21 @@ public final class APIv3 extends AbstractVerticle {
), (a, b) -> {});
}
private CodecRegistry createCodecRegistry() {
ObjectMapper objectMapper = ObjectMapperFactory.createObjectMapper();
SimpleModule simpleModule = new SimpleModule();
private ObjectMapper createMongoJacksonMapper() {
ObjectMapper mongoJacksonMapper = ObjectMapperFactory.createObjectMapper();
SimpleModule module = new SimpleModule();
simpleModule.addSerializer(Instant.class, new InstantJsonSerializer());
simpleModule.addDeserializer(Instant.class, new InstantJsonDeserializer());
simpleModule.addSerializer(UUID.class, new UuidJsonSerializer());
simpleModule.addDeserializer(UUID.class, new UuidJsonDeserializer());
module.addSerializer(Instant.class, new InstantJsonSerializer());
module.addDeserializer(Instant.class, new InstantJsonDeserializer());
module.addSerializer(UUID.class, new UuidJsonSerializer());
module.addDeserializer(UUID.class, new UuidJsonDeserializer());
objectMapper.registerModule(simpleModule);
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mongoJacksonMapper.registerModule(module);
mongoJacksonMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
mongoJacksonMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mongoJacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
List<CodecProvider> providers = new ArrayList<>();
// Our fixed uuid codec
providers.add(new UuidCodecProvider());
// Normal providers
providers.add(new ValueCodecProvider());
providers.add(new DocumentCodecProvider());
providers.add(new BsonValueCodecProvider());
// Jackson parser codec
providers.add(new JacksonCodecProvider(objectMapper));
return CodecRegistries.fromProviders(providers);
return mongoJacksonMapper;
}
private void setupRedis() {
@ -235,99 +221,95 @@ public final class APIv3 extends AbstractVerticle {
// TODO: blockingHandler -> handler
private void setupHttpServer() {
HttpServer webServer = vertx.createHttpServer();
Router mainRouter = Router.router(vertx);
HttpServer webServer = vertx.createHttpServer(
new HttpServerOptions()
//.setSsl(true)
.setCompressionSupported(true)
);
mainRouter.route().handler(new LoaderIoHandler());
mainRouter.route().handler(new ActorAttributeHandler());
mainRouter.route().handler(new AuthorizationHandler());
mainRouter.route().handler(LoggerHandler.create(LoggerFormat.TINY));
mainRouter.route().method(HttpMethod.PUT).method(HttpMethod.POST).handler(BodyHandler.create());
Router http = Router.router(vertx);
http.route().handler(LoggerHandler.create(LoggerFormat.TINY));
http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5)));
http.route().method(HttpMethod.PUT).method(HttpMethod.POST).handler(BodyHandler.create());
http.route().handler(new ActorAttributeHandler());
http.route().handler(new AuthorizationHandler());
http.exceptionHandler(Throwable::printStackTrace); // TODO: BUGSNAG
// TODO: The commented out routes
mainRouter.get("/announcements/:id").handler(new GETAnnouncements());
mainRouter.put("/announcements/:id").handler(new PUTAnnouncements());
http.get("/auditLog").handler(new GETAuditLog());
http.post("/auditLog").handler(new POSTAuditLog());
mainRouter.get("/auditLog").handler(new GETAuditLog());
mainRouter.post("/user/:id/auditLogEntry").handler(new POSTUserAuditLogEntry());
http.get("/chatFilter").handler(new GETChatFilter());
mainRouter.get("/emailToken/:emailToken/owner").blockingHandler(new GETEmailTokenOwner(), false);
mainRouter.post("/emailToken/:emailToken/confirm").blockingHandler(new POSTEmailTokenConfirm(), false);
http.get("/emailTokens/:emailToken/owner").blockingHandler(new GETEmailTokensOwner(), false);
http.post("/emailTokens/:emailToken/confirm").blockingHandler(new POSTEmailTokensConfirm(), false);
mainRouter.get("/chatFilterList").handler(new GETChatFilterList());
http.get("/grants/:id").handler(new GETGrantsId());
http.get("/grants").handler(new GETGrants());
http.post("/grants").blockingHandler(new POSTGrants(), false);
http.delete("/grants/:id").blockingHandler(new DELETEGrantsId(), false);
mainRouter.get("/grant/:id").handler(new GETGrant());
mainRouter.get("/grants").handler(new GETGrants());
mainRouter.get("/user/:id/grants").handler(new GETUserGrants());
mainRouter.post("/user/:id/grant").blockingHandler(new POSTUserGrant(), false);
mainRouter.delete("/grant/:id").blockingHandler(new DELETEGrant(), false);
http.get("/ipBans/:id").handler(new GETIpBan());
http.get("/ipBans").handler(new GETIpBans());
http.post("/ipBans").blockingHandler(new POSTIpBans(), false);
http.delete("/ipBans/:id").blockingHandler(new DELETEIpBan(), false);
mainRouter.get("/ipBan/:id").handler(new GETIpBan());
mainRouter.get("/ipBans").handler(new GETIpBans());
mainRouter.get("/ip/:id/ipBans").handler(new GETIpIpBans());
mainRouter.post("/ip/:id/ipBan").blockingHandler(new POSTIpIpBan(), false);
mainRouter.delete("/ipBan/:id").blockingHandler(new DELETEIpBan(), false);
http.get("/ipIntel").handler(new GETIpIntel());
mainRouter.get("/ip/:id/intel").handler(new GETIpIntel());
http.get("/ipLog").handler(new GETIpLog());
mainRouter.get("/user/:id/ipLog").handler(new GETUserIpLog());
http.get("/notificationTemplates/:id").handler(new GETNotificationTemplatesId());
http.get("/notificationTemplates").handler(new GETNotificationTemplates());
http.post("/notificationTemplates").blockingHandler(new POSTNotificationTemplates(), false);
//http.put("/notificationTemplates/:id").blockingHandler(new PUTNotificationTemplates(), false);
http.delete("/notificationTemplates/:id").blockingHandler(new DELETENotificationTemplatesId(), false);
mainRouter.get("/notificationTemplate/:id").handler(new GETNotificationTemplate());
mainRouter.get("/notificationTemplates").handler(new GETNotificationTemplates());
mainRouter.post("/notificationTemplate").blockingHandler(new POSTNotificationTemplate(), false);
//mainRouter.put("/notificationTemplate/:id").blockingHandler(new PUTNotificationTemplate(), false);
mainRouter.delete("/notificationTemplate/:id").blockingHandler(new DELETENotificationTemplate(), false);
http.get("/punishments/:id").handler(new GETPunishmentsId());
http.get("/punishments").handler(new GETPunishments());
http.post("/punishments").blockingHandler(new POSTUserPunish(), false);
http.delete("/punishments/:id").blockingHandler(new DELETEPunishments(), false);
http.delete("/user/:id/activePunishment").blockingHandler(new DELETEUserActivePunishment(), false);
mainRouter.get("/punishment/:id").handler(new GETPunishment());
mainRouter.get("/punishments").handler(new GETPunishments());
mainRouter.get("/user/:id/punishments").handler(new GETUserPunishments());
mainRouter.post("/user/:id/punish").blockingHandler(new POSTUserPunish(), false);
mainRouter.delete("/punishment/:id").blockingHandler(new DELETEPunishment(), false);
mainRouter.delete("/user/:id/punishment").blockingHandler(new DELETEUserPunishment(), false);
http.get("/ranks/:id").handler(new GETRanksId());
http.get("/ranks").handler(new GETRanks());
http.post("/ranks").blockingHandler(new POSTRanks(), false);
//http.put("/ranks/:id").blockingHandler(new PUTRank(), false);
http.delete("/ranks/:id").blockingHandler(new DELETERanksId(), false);
mainRouter.get("/rank/:id").handler(new GETRank());
mainRouter.get("/ranks").handler(new GETRanks());
mainRouter.post("/rank").blockingHandler(new POSTRank(), false);
//mainRouter.put("/rank/:id").blockingHandler(new PUTRank(), false);
mainRouter.delete("/rank/:id").blockingHandler(new DELETERank(), false);
http.get("/serverGroups/:id").handler(new GETServerGroupsId());
http.get("/serverGroups").handler(new GETServerGroups());
http.post("/serverGroups").blockingHandler(new POSTServerGroups(), false);
//http.put("/serverGroups/:id").blockingHandler(new PUTServerGroup(), false);
http.delete("/serverGroups/:id").blockingHandler(new DELETEServerGroupsId(), false);
mainRouter.get("/serverGroup/:id").handler(new GETServerGroup());
mainRouter.get("/serverGroups").handler(new GETServerGroups());
mainRouter.post("/serverGroup").blockingHandler(new POSTServerGroup(), false);
//mainRouter.put("/serverGroup/:id").blockingHandler(new PUTServerGroup(), false);
mainRouter.delete("/serverGroup/:id").blockingHandler(new DELETEServerGroup(), false);
http.get("/servers/:id").handler(new GETServersId());
http.get("/servers").handler(new GETServers());
http.post("/servers/heartbeat").handler(new POSTServersHeartbeat());
http.post("/servers").blockingHandler(new POSTServers(), false);
//http.put("/servers/:id").blockingHandler(new PUTServer(), false);
http.delete("/servers/:id").blockingHandler(new DELETEServersId(), false);
mainRouter.get("/server/:id").handler(new GETServer());
mainRouter.get("/servers").handler(new GETServers());
mainRouter.post("/server/heartbeat").handler(new POSTServerHeartbeat());
mainRouter.post("/server").blockingHandler(new POSTServer(), false);
//mainRouter.put("/server/:id").blockingHandler(new PUTServer(), false);
mainRouter.delete("/server/:id").blockingHandler(new DELETEServer(), false);
http.get("/staff").blockingHandler(new GETStaff(), false);
http.get("/users/:id").handler(new GETUser());
http.get("/users/:id/details").blockingHandler(new GETUserDetails(), false);
http.get("/users/:id/permissions").blockingHandler(new GETUserPermissions(), false);
http.get("/users/:id/requiresTOTP").handler(new GETUserRequiresTOTP());
http.get("/users/:id/verifyPassword").blockingHandler(new GETUserVerifyPassword(), false);
http.post("/users/:id/changePassword").blockingHandler(new POSTUserChangePassword(), false);
http.post("/users/:id/leave").handler(new POSTUserLeave());
http.post("/users/:id/login").blockingHandler(new POSTUserLogin());
http.post("/users/:id/notify").blockingHandler(new POSTUserNotify(), false);
http.post("/users/:id/register").blockingHandler(new POSTUserRegister(), false);
http.post("/users/:id/setupTOTP").blockingHandler(new POSTUserSetupTOTP(), false);
http.post("/users/:id/verifyTOTP").blockingHandler(new POSTUserVerifyTOTP(), false);
mainRouter.get("/staff").blockingHandler(new GETStaff(), false);
mainRouter.get("/user/:id").handler(new GETUser());
mainRouter.get("/user/:id/details").blockingHandler(new GETUserDetails(), false);
mainRouter.get("/user/:id/meta/:serverGroup").blockingHandler(new GETUserMeta(), false);
mainRouter.get("/user/:id/permissions").blockingHandler(new GETUserPermissions(), false);
mainRouter.get("/user/:id/requiresTOTP").handler(new GETUserRequiresTOTP());
mainRouter.get("/user/:id/verifyPassword").blockingHandler(new GETUserVerifyPassword(), false);
mainRouter.post("/user/:id/changePassword").blockingHandler(new POSTUserChangePassword(), false);
mainRouter.post("/user/:id/leave").handler(new POSTUserLeave());
mainRouter.post("/user/:id/login").blockingHandler(new POSTUserLogin());
mainRouter.post("/user/:id/notify").blockingHandler(new POSTUserNotify(), false);
mainRouter.post("/user/:id/register").blockingHandler(new POSTUserRegister(), false);
mainRouter.post("/user/:id/setupTOTP").blockingHandler(new POSTUserSetupTOTP(), false);
mainRouter.post("/user/:id/verifyTOTP").blockingHandler(new POSTUserVerifyTOTP(), false);
mainRouter.put("/user/:id/meta/:serverGroup").blockingHandler(new PUTUserMeta(), false);
mainRouter.delete("/user/:id/meta/:serverGroup").blockingHandler(new DELETEUserMeta(), false);
mainRouter.get("/dump/:type").handler(new GETDump());
mainRouter.get("/whoami").handler(new GETWhoAmI());
mainRouter.post("/metrics").handler(new POSTMetrics());
http.get("/dumps/:type").handler(new GETDumps());
http.get("/whoami").handler(new GETWhoAmI());
int port = Integer.parseInt(config.getProperty("http.port"));
webServer.requestHandler(mainRouter::accept).listen(port);
webServer.requestHandler(http::accept).listen(port);
}
private void setupHttpClient() {

View File

@ -1,19 +0,0 @@
package net.frozenorb.apiv3.handler;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
public final class LoaderIoHandler implements Handler<RoutingContext> {
@Override
public void handle(RoutingContext ctx) {
String path = ctx.request().path().replace("/", "");
if (path.equals("loaderio-1c81aa574f79c573e7220e15e30a96aa")) {
ctx.response().end(path);
} else {
ctx.next();
}
}
}

View File

@ -34,16 +34,12 @@ public final class AuditLogEntry {
@Getter private AuditLogActionType type;
@Getter private Map<String, Object> metadata;
public static List<AuditLogEntry> findByUserSync(UUID user) {
return SyncUtils.blockMulti(auditLogCollection.find(new Document("user", user)));
}
public static void findAllPaginated(int skip, int pageSize, SingleResultCallback<List<AuditLogEntry>> callback) {
auditLogCollection.find().sort(new Document("performedAt", -1)).skip(skip).limit(pageSize).into(new ArrayList<>(), callback);
}
public static void findByUser(UUID user, SingleResultCallback<List<AuditLogEntry>> callback) {
auditLogCollection.find(new Document("user", user)).into(new ArrayList<>(), callback);
public static void find(Document query, SingleResultCallback<List<AuditLogEntry>> callback) {
auditLogCollection.find(query).into(new ArrayList<>(), callback);
}
public AuditLogEntry() {} // For Jackson

View File

@ -29,7 +29,7 @@ public final class ServerGroup {
@Getter @Id private String id;
@Getter private String image;
@Getter @Setter @ExcludeFromReplies private Set<String> announcements;
@Getter @Setter private Set<String> announcements;
@Getter @Setter @ExcludeFromReplies private Map<String, List<String>> permissions;
// make this and other stuff async

View File

@ -40,8 +40,8 @@ public final class User {
@Getter @ExcludeFromReplies @Setter private String totpSecret;
@Getter @ExcludeFromReplies private String password;
@Getter private String email;
@Getter @ExcludeFromReplies private Instant registeredAt;
@Getter private String pendingEmail;
@Getter private Instant registeredAt;
@Getter @ExcludeFromReplies private String pendingEmail;
@Getter @ExcludeFromReplies private String pendingEmailToken;
@Getter @ExcludeFromReplies private Instant pendingEmailTokenSetAt;
@Getter private String phoneNumber;
@ -238,6 +238,7 @@ public final class User {
});
}
// TODO: CLEAN
public enum RequiresTotpResult {
NOT_REQUIRED_NOT_SET,

View File

@ -1,65 +0,0 @@
package net.frozenorb.apiv3.model;
import com.google.common.collect.ImmutableMap;
import com.mongodb.async.client.MongoCollection;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import fr.javatic.mongo.jacksonCodec.Entity;
import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.Getter;
import lombok.Setter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.util.Map;
import java.util.UUID;
@Entity
public final class UserMetaEntry {
private static final MongoCollection<UserMetaEntry> userMetaCollection = APIv3.getDatabase().getCollection("userMeta", UserMetaEntry.class);
@Getter @Id private String id;
@Getter private UUID user;
@Getter private String serverGroup;
@Getter @Setter private Map<String, Object> data;
public static UserMetaEntry findByUserAndGroupSync(User user, ServerGroup serverGroup) {
return findByUserAndGroupSync(user.getId(), serverGroup);
}
public static UserMetaEntry findByUserAndGroupSync(UUID user, ServerGroup serverGroup) {
return SyncUtils.blockOne(userMetaCollection.find(new Document("user", user).append("serverGroup", serverGroup.getId())));
}
public UserMetaEntry() {} // For Jackson
public UserMetaEntry(User user, ServerGroup serverGroup, Map<String, Object> data) {
this.id = new ObjectId().toString();
this.user = user.getId();
this.serverGroup = serverGroup.getId();
this.data = ImmutableMap.copyOf(data);
}
public void insert() {
BlockingCallback<Void> callback = new BlockingCallback<>();
userMetaCollection.insertOne(this, callback);
callback.get();
}
public void save() {
BlockingCallback<UpdateResult> callback = new BlockingCallback<>();
userMetaCollection.replaceOne(new Document("_id", id), this, callback);
callback.get();
}
public void delete() {
BlockingCallback<DeleteResult> callback = new BlockingCallback<>();
userMetaCollection.deleteOne(new Document("_id", id), callback);
callback.get();
}
}

View File

@ -11,13 +11,13 @@ import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.*;
import java.util.concurrent.TimeUnit;
public final class GETDump implements Handler<RoutingContext> {
public final class GETDumps implements Handler<RoutingContext> {
private List<UUID> banCache = new ArrayList<>();
private List<UUID> blacklistCache = new ArrayList<>();
private Map<String, List<UUID>> grantCache = new HashMap<>();
public GETDump() {
public GETDumps() {
// TODO: Use vertx scheduler
Thread dumpUpdater = new Thread() {
@ -45,8 +45,8 @@ public final class GETDump implements Handler<RoutingContext> {
}
});
GETDump.this.banCache = banCache;
GETDump.this.blacklistCache = blacklistCache;
GETDumps.this.banCache = banCache;
GETDumps.this.blacklistCache = blacklistCache;
}
if (tick == 0 || tick % 2 == 0) {
@ -65,7 +65,7 @@ public final class GETDump implements Handler<RoutingContext> {
}
});
GETDump.this.grantCache = grantCache;
GETDumps.this.grantCache = grantCache;
}
try {

View File

@ -1,14 +0,0 @@
package net.frozenorb.apiv3.route;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
public final class POSTMetrics implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, ImmutableMap.of());
}
}

View File

@ -1,21 +0,0 @@
package net.frozenorb.apiv3.route.announcements;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETAnnouncements implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("id"));
if (serverGroup == null) {
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("id"));
} else {
APIv3.respondJson(ctx, serverGroup.getAnnouncements());
}
}
}

View File

@ -1,37 +0,0 @@
package net.frozenorb.apiv3.route.announcements;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.HashSet;
import java.util.Set;
public final class PUTAnnouncements implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("id"));
if (serverGroup == null) {
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("id"));
} else {
Set<String> announcements = new HashSet<>();
for (Object announcement : ctx.getBodyAsJsonArray()) {
announcements.add((String) announcement);
}
serverGroup.setAnnouncements(announcements);
serverGroup.save((ignored, error) -> {
if (error != null) {
ErrorUtils.respondInternalError(ctx, error);
} else {
APIv3.respondJson(ctx, serverGroup.getAnnouncements());
}
});
}
}
}

View File

@ -10,7 +10,7 @@ import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
import org.bson.Document;
public final class POSTUserAuditLogEntry implements Handler<RoutingContext> {
public final class POSTAuditLog implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User.findById(ctx.request().getParam("id"), (user, error) -> {

View File

@ -5,7 +5,7 @@ import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
public final class GETChatFilterList implements Handler<RoutingContext> {
public final class GETChatFilter implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
// TODO

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETEmailTokenOwner implements Handler<RoutingContext> {
public final class GETEmailTokensOwner implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User.findByEmailTokenSync(ctx.request().getParam("id"), (user, error) -> {

View File

@ -9,7 +9,7 @@ import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.concurrent.TimeUnit;
public final class POSTEmailTokenConfirm implements Handler<RoutingContext> {
public final class POSTEmailTokensConfirm implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User user = User.findByEmailTokenSync(ctx.request().getParam("emailToken"));

View File

@ -12,7 +12,7 @@ import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEGrant implements Handler<RoutingContext> {
public final class DELETEGrantsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Grant grant = Grant.findByIdSync(ctx.request().getParam("id"));

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETGrant implements Handler<RoutingContext> {
public final class GETGrantsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Grant.findById(ctx.request().getParam("id"), (grant, error) -> {

View File

@ -1,30 +0,0 @@
package net.frozenorb.apiv3.route.grants;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserGrants implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User.findById(ctx.request().getParam("id"), (user, error) -> {
if (error != null) {
ErrorUtils.respondInternalError(ctx, error);
} else if (user == null) {
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("id"));
} else {
Grant.findByUser(user, (grants, error2) -> {
if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2);
} else {
APIv3.respondJson(ctx, grants);
}
});
}
});
}
}

View File

@ -13,7 +13,7 @@ import java.time.Instant;
import java.util.HashSet;
import java.util.Set;
public final class POSTUserGrant implements Handler<RoutingContext> {
public final class POSTGrants implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User target = User.findByIdSync(ctx.request().getParam("id"));

View File

@ -1,29 +0,0 @@
package net.frozenorb.apiv3.route.ipBans;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.IpBan;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
public final class GETIpIpBans implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
String userIp = ctx.request().getParam("id");
if (!IpUtils.isValidIp(userIp)) {
ErrorUtils.respondInvalidInput(ctx, "Ip address \"" + userIp + "\" is not valid.");
return;
}
IpBan.findByIp(userIp, (ipBans, error) -> {
if (error != null) {
ErrorUtils.respondInternalError(ctx, error);
} else {
APIv3.respondJson(ctx, ipBans);
}
});
}
}

View File

@ -10,7 +10,7 @@ import net.frozenorb.apiv3.util.IpUtils;
import java.time.Instant;
public final class POSTIpIpBan implements Handler<RoutingContext> {
public final class POSTIpBans implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
String userIp = ctx.request().getParam("id");

View File

@ -7,7 +7,7 @@ import net.frozenorb.apiv3.model.IpLogEntry;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserIpLog implements Handler<RoutingContext> {
public final class GETIpLog implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User.findById(ctx.request().getParam("id"), (user, error) -> {

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.NotificationTemplate;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETENotificationTemplate implements Handler<RoutingContext> {
public final class DELETENotificationTemplatesId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
NotificationTemplate notificationTemplate = NotificationTemplate.findByIdSync(ctx.request().getParam("id"));

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.NotificationTemplate;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETNotificationTemplate implements Handler<RoutingContext> {
public final class GETNotificationTemplatesId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
NotificationTemplate.findById(ctx.request().getParam("id"), (notificationTemplate, error) -> {

View File

@ -5,7 +5,7 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.NotificationTemplate;
public final class POSTNotificationTemplate implements Handler<RoutingContext> {
public final class POSTNotificationTemplates implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
String id = ctx.request().getParam("id");

View File

@ -12,7 +12,7 @@ import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEPunishment implements Handler<RoutingContext> {
public final class DELETEPunishments implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Punishment punishment = Punishment.findByIdSync(ctx.request().getParam("id"));

View File

@ -13,7 +13,7 @@ import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEUserPunishment implements Handler<RoutingContext> {
public final class DELETEUserActivePunishment implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User target = User.findByIdSync(ctx.request().getParam("id"));

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETPunishment implements Handler<RoutingContext> {
public final class GETPunishmentsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Punishment.findById(ctx.request().getParam("id"), (punishment, error) -> {

View File

@ -1,30 +0,0 @@
package net.frozenorb.apiv3.route.punishments;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserPunishments implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User.findById(ctx.request().getParam("id"), (user, error) -> {
if (error != null) {
ErrorUtils.respondInternalError(ctx, error);
} else if (user == null) {
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("id"));
} else {
Punishment.findByUser(user, (punishments, error2) -> {
if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2);
} else {
APIv3.respondJson(ctx, punishments);
}
});
}
});
}
}

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Rank;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETERank implements Handler<RoutingContext> {
public final class DELETERanksId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Rank rank = Rank.findById(ctx.request().getParam("id"));

View File

@ -5,7 +5,7 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Rank;
public final class GETRank implements Handler<RoutingContext> {
public final class GETRanksId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, Rank.findById(ctx.request().getParam("id")));

View File

@ -5,7 +5,7 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Rank;
public final class POSTRank implements Handler<RoutingContext> {
public final class POSTRanks implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
String id = ctx.request().getParam("id");

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEServerGroup implements Handler<RoutingContext> {
public final class DELETEServerGroupsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("id"));

View File

@ -5,7 +5,7 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
public final class GETServerGroup implements Handler<RoutingContext> {
public final class GETServerGroupsId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, ServerGroup.findById(ctx.request().getParam("id")));

View File

@ -5,7 +5,7 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
public final class POSTServerGroup implements Handler<RoutingContext> {
public final class POSTServerGroups implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
String id = ctx.request().getParam("id");

View File

@ -6,7 +6,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Server;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEServer implements Handler<RoutingContext> {
public final class DELETEServersId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Server server = Server.findById(ctx.request().getParam("id"));

View File

@ -5,7 +5,7 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.Server;
public final class GETServer implements Handler<RoutingContext> {
public final class GETServersId implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
APIv3.respondJson(ctx, Server.findById(ctx.request().getParam("id")));

View File

@ -11,7 +11,7 @@ import net.frozenorb.apiv3.util.IpUtils;
import java.math.BigInteger;
import java.util.Random;
public final class POSTServer implements Handler<RoutingContext> {
public final class POSTServers implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
String id = ctx.request().getParam("id");

View File

@ -22,7 +22,7 @@ import java.util.Map;
import java.util.UUID;
@Slf4j
public final class POSTServerHeartbeat implements Handler<RoutingContext> {
public final class POSTServersHeartbeat implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
Actor actor = ctx.get("actor");

View File

@ -1,39 +0,0 @@
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.model.UserMetaEntry;
import net.frozenorb.apiv3.util.ErrorUtils;
import org.bson.Document;
public final class DELETEUserMeta implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User user = User.findByIdSync(ctx.request().getParam("id"));
if (user == null) {
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("id"));
return;
}
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("serverGroup"));
if (serverGroup == null) {
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("serverGroup"));
return;
}
UserMetaEntry userMetaEntry = UserMetaEntry.findByUserAndGroupSync(user, serverGroup);
if (userMetaEntry != null) {
userMetaEntry.delete();
APIv3.respondJson(ctx, userMetaEntry.getData());
} else {
APIv3.respondJson(ctx, new Document());
}
}
}

View File

@ -1,32 +0,0 @@
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.model.UserMetaEntry;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserMeta implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User user = User.findByIdSync(ctx.request().getParam("id"));
if (user == null) {
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("id"));
return;
}
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("serverGroup"));
if (serverGroup == null) {
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("serverGroup"));
return;
}
UserMetaEntry userMetaEntry = UserMetaEntry.findByUserAndGroupSync(user, serverGroup);
APIv3.respondJson(ctx, userMetaEntry.getData());
}
}

View File

@ -1,43 +0,0 @@
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.model.UserMetaEntry;
import net.frozenorb.apiv3.util.ErrorUtils;
import org.bson.Document;
public final class PUTUserMeta implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) {
User user = User.findByIdSync(ctx.request().getParam("id"));
if (user == null) {
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("id"));
return;
}
ServerGroup serverGroup = ServerGroup.findById(ctx.request().getParam("serverGroup"));
if (serverGroup == null) {
ErrorUtils.respondNotFound(ctx, "Server group", ctx.request().getParam("serverGroup"));
return;
}
Document reqJson = Document.parse(ctx.getBodyAsString());
UserMetaEntry metaEntry = UserMetaEntry.findByUserAndGroupSync(user, serverGroup);
if (metaEntry == null) {
metaEntry = new UserMetaEntry(user, serverGroup, reqJson);
metaEntry.insert();
} else {
metaEntry.setData(reqJson);
metaEntry.save();
}
APIv3.respondJson(ctx, reqJson);
}
}