Remove metrics, change GET /ipLog/:id to accept both ips and user uuids
This commit is contained in:
parent
d55325d255
commit
f999319666
@ -34,10 +34,8 @@ 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.MetricsHandler;
|
||||
import net.frozenorb.apiv3.model.*;
|
||||
import net.frozenorb.apiv3.route.GETDumpsType;
|
||||
import net.frozenorb.apiv3.route.GETMetrics;
|
||||
import net.frozenorb.apiv3.route.GETWhoAmI;
|
||||
import net.frozenorb.apiv3.route.accessTokens.DELETEAccessTokensId;
|
||||
import net.frozenorb.apiv3.route.accessTokens.GETAccessTokens;
|
||||
@ -259,7 +257,6 @@ public final class APIv3 extends AbstractVerticle {
|
||||
});
|
||||
http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create());
|
||||
http.route().handler(new ActorAttributeHandler());
|
||||
http.route().handler(new MetricsHandler());
|
||||
http.route().handler(new AuthorizationHandler());
|
||||
http.exceptionHandler(Throwable::printStackTrace);
|
||||
|
||||
@ -306,7 +303,7 @@ public final class APIv3 extends AbstractVerticle {
|
||||
|
||||
http.get("/ipIntel/:userIp").handler(new GETIpInteld());
|
||||
|
||||
http.get("/ipLog/:userId").handler(new GETIpLogId());
|
||||
http.get("/ipLog/:id").handler(new GETIpLogId());
|
||||
|
||||
http.get("/notificationTemplates/:notificationTemplateId").handler(new GETNotificationTemplatesId());
|
||||
http.get("/notificationTemplates").handler(new GETNotificationTemplates());
|
||||
@ -359,7 +356,6 @@ public final class APIv3 extends AbstractVerticle {
|
||||
http.post("/users/:userId/verifyTotp").handler(new POSTUsersIdVerifyTotp());
|
||||
|
||||
http.get("/dumps/:dumpType").handler(new GETDumpsType());
|
||||
http.get("/metrics").handler(new GETMetrics());
|
||||
http.get("/whoami").handler(new GETWhoAmI());
|
||||
|
||||
int port = Integer.parseInt(config.getProperty("http.port"));
|
||||
|
@ -1,43 +0,0 @@
|
||||
package net.frozenorb.apiv3.handler;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import io.vertx.redis.RedisClient;
|
||||
import io.vertx.redis.RedisOptions;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.actor.Actor;
|
||||
|
||||
public final class MetricsHandler implements Handler<RoutingContext> {
|
||||
|
||||
private static final RedisClient redisClient = RedisClient.create(APIv3.getVertxInstance(),
|
||||
new RedisOptions()
|
||||
.setAddress(APIv3.getConfig().getProperty("redis.address"))
|
||||
.setPort(Integer.parseInt(APIv3.getConfig().getProperty("redis.port")))
|
||||
);
|
||||
|
||||
@Override
|
||||
public void handle(RoutingContext ctx) {
|
||||
redisClient.incr("apiv3:requests:total", (totalUpdateResult) -> {
|
||||
if (totalUpdateResult.failed()) {
|
||||
totalUpdateResult.cause().printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
redisClient.incr("apiv3:requests:method:" + ctx.request().method(), (methodUpdateResult) -> {
|
||||
if (methodUpdateResult.failed()) {
|
||||
methodUpdateResult.cause().printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
redisClient.incr("apiv3:requests:actor:" + ((Actor) ctx.get("actor")).getType(), (actorUpdateResult) -> {
|
||||
if (actorUpdateResult.failed()) {
|
||||
actorUpdateResult.cause().printStackTrace();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
ctx.next();
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ import fr.javatic.mongo.jacksonCodec.objectId.Id;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.util.SyncUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
@ -20,7 +21,7 @@ import java.util.UUID;
|
||||
@AllArgsConstructor
|
||||
public final class IpLogEntry {
|
||||
|
||||
private static final MongoCollection<IpLogEntry> ipLogCollection = APIv3.getDatabase().getCollection("ipLog", IpLogEntry.class);
|
||||
private static final MongoCollection<IpLogEntry> ipLogCollection = APIv3.getDatabase().getCollection("ipLog", IpLogEntry.class);
|
||||
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID user;
|
||||
@ -30,11 +31,11 @@ public final class IpLogEntry {
|
||||
@Getter private int uses;
|
||||
|
||||
public static void findAll(SingleResultCallback<List<IpLogEntry>> callback) {
|
||||
ipLogCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), callback);
|
||||
ipLogCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public static void findById(String id, SingleResultCallback<IpLogEntry> callback) {
|
||||
ipLogCollection.find(new Document("_id", id)).first(callback);
|
||||
ipLogCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public static void findByUser(User user, SingleResultCallback<List<IpLogEntry>> callback) {
|
||||
@ -42,7 +43,11 @@ public final class IpLogEntry {
|
||||
}
|
||||
|
||||
public static void findByUser(UUID user, SingleResultCallback<List<IpLogEntry>> callback) {
|
||||
ipLogCollection.find(new Document("user", user)).sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), callback);
|
||||
ipLogCollection.find(new Document("user", user)).sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public static void findByIp(String userIp, SingleResultCallback<List<IpLogEntry>> callback) {
|
||||
ipLogCollection.find(new Document("userIp", userIp)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public static void findByUserAndIp(User user, String userIp, SingleResultCallback<IpLogEntry> callback) {
|
||||
@ -50,7 +55,7 @@ public final class IpLogEntry {
|
||||
}
|
||||
|
||||
public static void findByUserAndIp(UUID user, String userIp, SingleResultCallback<IpLogEntry> callback) {
|
||||
ipLogCollection.find(new Document("user", user).append("userIp", userIp)).first(callback);
|
||||
ipLogCollection.find(new Document("user", user).append("userIp", userIp)).first(SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
private IpLogEntry() {} // For Jackson
|
||||
@ -70,11 +75,11 @@ public final class IpLogEntry {
|
||||
}
|
||||
|
||||
public void insert(SingleResultCallback<Void> callback) {
|
||||
ipLogCollection.insertOne(this, callback);
|
||||
ipLogCollection.insertOne(this, SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public void save(SingleResultCallback<UpdateResult> callback) {
|
||||
ipLogCollection.replaceOne(new Document("_id", id), this, callback);
|
||||
ipLogCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package net.frozenorb.apiv3.route;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.dropwizard.MetricsService;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
|
||||
public final class GETMetrics implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
MetricsService metricsService = MetricsService.create(APIv3.getVertxInstance());
|
||||
JsonObject metrics = metricsService.getMetricsSnapshot(APIv3.getVertxInstance());
|
||||
|
||||
APIv3.respondJson(ctx, 200, metrics);
|
||||
}
|
||||
|
||||
}
|
@ -10,21 +10,33 @@ import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
public final class GETIpLogId implements Handler<RoutingContext> {
|
||||
|
||||
public void handle(RoutingContext ctx) {
|
||||
User.findById(ctx.request().getParam("userId"), (user, error) -> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else if (user == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("userId"));
|
||||
} else {
|
||||
IpLogEntry.findByUser(user, (ipLog, error2) -> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, 200, ipLog);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
String search = ctx.request().getParam("id");
|
||||
|
||||
if (search.length() >= 32) {
|
||||
User.findById(search, (user, error) -> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else if (user == null) {
|
||||
ErrorUtils.respondNotFound(ctx, "User", search);
|
||||
} else {
|
||||
IpLogEntry.findByUser(user, (ipLog, error2) -> {
|
||||
if (error2 != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error2);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, 200, ipLog);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
IpLogEntry.findByIp(search, (ipLogs, error) -> {
|
||||
if (error != null) {
|
||||
ErrorUtils.respondInternalError(ctx, error);
|
||||
} else {
|
||||
APIv3.respondJson(ctx, 200, ipLogs);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user