Whoa stuff
This commit is contained in:
parent
53c7222107
commit
1b05b16fed
@ -1,5 +1,6 @@
|
|||||||
general.id=main
|
general.id=main
|
||||||
general.releaseStage=production
|
general.releaseStage=production
|
||||||
|
logging.level=info
|
||||||
mongo.address=ds055505.mongolab.com
|
mongo.address=ds055505.mongolab.com
|
||||||
mongo.port=55505
|
mongo.port=55505
|
||||||
mongo.database=minehqapi
|
mongo.database=minehqapi
|
||||||
@ -15,6 +16,6 @@ twillio.authToken=982592505a171d3be6b0722f5ecacc0e
|
|||||||
mandrill.apiKey=0OYtwymqJP6oqvszeJu0vQ
|
mandrill.apiKey=0OYtwymqJP6oqvszeJu0vQ
|
||||||
librato.email=cmcdonald.main@gmail.com
|
librato.email=cmcdonald.main@gmail.com
|
||||||
librato.apiKey=a818c3eca8a59d6d9cf76dc9f0d237c6aa97f257c482ce3363cf55a5431bc153
|
librato.apiKey=a818c3eca8a59d6d9cf76dc9f0d237c6aa97f257c482ce3363cf55a5431bc153
|
||||||
bugsnag.apiKey=
|
bugsnag.apiKey=0e47fba8b825416b7cbc839066184509
|
||||||
auth.permittedUserRanks=developer,owner
|
auth.permittedUserRanks=developer,owner
|
||||||
auth.websiteApiKey=RVbp4hY6sCFVaf
|
auth.websiteApiKey=RVbp4hY6sCFVaf
|
11
pom.xml
11
pom.xml
@ -17,6 +17,17 @@
|
|||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>net.frozenorb.apiv3.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
@ -68,9 +68,9 @@ public final class APIv3 {
|
|||||||
.create();
|
.create();
|
||||||
|
|
||||||
APIv3() {
|
APIv3() {
|
||||||
//System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace");
|
|
||||||
|
|
||||||
setupConfig();
|
setupConfig();
|
||||||
|
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", config.getProperty("logging.level"));
|
||||||
|
|
||||||
setupDatabase();
|
setupDatabase();
|
||||||
setupRedis();
|
setupRedis();
|
||||||
setupMetrics();
|
setupMetrics();
|
||||||
@ -89,13 +89,15 @@ public final class APIv3 {
|
|||||||
private void setupDatabase() {
|
private void setupDatabase() {
|
||||||
MongoClient mongoClient = new MongoClient(new ServerAddress(
|
MongoClient mongoClient = new MongoClient(new ServerAddress(
|
||||||
config.getProperty("mongo.address"),
|
config.getProperty("mongo.address"),
|
||||||
Integer.parseInt(config.getProperty("mongo.port"))),
|
Integer.parseInt(config.getProperty("mongo.port")))/*,
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
MongoCredential.createCredential(
|
MongoCredential.createCredential(
|
||||||
config.getProperty("mongo.username"),
|
config.getProperty("mongo.username"),
|
||||||
config.getProperty("mongo.database"),
|
config.getProperty("mongo.database"),
|
||||||
config.getProperty("mongo.password").toCharArray())
|
config.getProperty("mongo.password").toCharArray())
|
||||||
));
|
)*/);
|
||||||
|
|
||||||
|
// TODO: DISABLE CREDS IF NOT NEEDED
|
||||||
|
|
||||||
MorphiaLoggerFactory.reset();
|
MorphiaLoggerFactory.reset();
|
||||||
MorphiaLoggerFactory.registerLogger(SLF4JLoggerImplFactory.class);
|
MorphiaLoggerFactory.registerLogger(SLF4JLoggerImplFactory.class);
|
||||||
@ -136,6 +138,9 @@ public final class APIv3 {
|
|||||||
private void setupBugsnag() {
|
private void setupBugsnag() {
|
||||||
bugsnagClient = new Client(config.getProperty("bugsnag.apiKey"));
|
bugsnagClient = new Client(config.getProperty("bugsnag.apiKey"));
|
||||||
bugsnagClient.setReleaseStage(config.getProperty("general.releaseStage"));
|
bugsnagClient.setReleaseStage(config.getProperty("general.releaseStage"));
|
||||||
|
bugsnagClient.setProjectPackages("net.frozenorb.apiv3");
|
||||||
|
|
||||||
|
// TODO: Use .setLogger to use slf4j with this
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupHttp() {
|
private void setupHttp() {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.frozenorb.apiv3.filters;
|
package net.frozenorb.apiv3.filters;
|
||||||
|
|
||||||
import com.sun.xml.internal.messaging.saaj.util.Base64;
|
|
||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.actors.*;
|
import net.frozenorb.apiv3.actors.*;
|
||||||
import net.frozenorb.apiv3.models.Server;
|
import net.frozenorb.apiv3.models.Server;
|
||||||
@ -11,6 +10,8 @@ import spark.Request;
|
|||||||
import spark.Response;
|
import spark.Response;
|
||||||
import spark.Spark;
|
import spark.Spark;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
public final class ActorAttributeFilter implements Filter {
|
public final class ActorAttributeFilter implements Filter {
|
||||||
|
|
||||||
public void handle(Request req, Response res) {
|
public void handle(Request req, Response res) {
|
||||||
@ -29,7 +30,7 @@ public final class ActorAttributeFilter implements Filter {
|
|||||||
@SuppressWarnings("deprecation") // We purposely get the User by their last username.
|
@SuppressWarnings("deprecation") // We purposely get the User by their last username.
|
||||||
private Actor processBasicAuthorization(String authHeader, Response res) {
|
private Actor processBasicAuthorization(String authHeader, Response res) {
|
||||||
String encodedHeader = authHeader.substring("Basic ".length());
|
String encodedHeader = authHeader.substring("Basic ".length());
|
||||||
String[] credentials = Base64.base64Decode(encodedHeader).split(":");
|
String[] credentials = new String(Base64.getDecoder().decode(encodedHeader.getBytes())).split(":");
|
||||||
|
|
||||||
if (credentials.length == 2) {
|
if (credentials.length == 2) {
|
||||||
User user = User.byLastUsername(credentials[0]);
|
User user = User.byLastUsername(credentials[0]);
|
||||||
|
@ -15,11 +15,8 @@ public final class MetricsAfterFilter implements Filter {
|
|||||||
public void handle(Request req, Response res) {
|
public void handle(Request req, Response res) {
|
||||||
responseLengthMetric.update(req.contentLength());
|
responseLengthMetric.update(req.contentLength());
|
||||||
|
|
||||||
Timer.Context timerMetricActorType = req.attribute("timerMetric.actorType");
|
Timer.Context timerMetric = req.attribute("timerMetric");
|
||||||
Timer.Context timerMetricGlobal = req.attribute("timerMetric.global");
|
timerMetric.stop();
|
||||||
|
|
||||||
timerMetricActorType.stop();
|
|
||||||
timerMetricGlobal.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -3,22 +3,16 @@ package net.frozenorb.apiv3.filters;
|
|||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import com.codahale.metrics.Timer;
|
import com.codahale.metrics.Timer;
|
||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.actors.Actor;
|
|
||||||
import spark.Filter;
|
import spark.Filter;
|
||||||
import spark.Request;
|
import spark.Request;
|
||||||
import spark.Response;
|
import spark.Response;
|
||||||
|
|
||||||
public final class MetricsBeforeFilter implements Filter {
|
public final class MetricsBeforeFilter implements Filter {
|
||||||
|
|
||||||
private Timer responseTimesGlobalMetric = APIv3.getMetrics().timer(MetricRegistry.name(getClass(), "responseTimes", "global"));
|
private Timer responseTimesMetric = APIv3.getMetrics().timer(MetricRegistry.name("apiv3", "http", "responseTimes"));
|
||||||
|
|
||||||
public void handle(Request req, Response res) {
|
public void handle(Request req, Response res) {
|
||||||
Actor actor = req.attribute("actor");
|
req.attribute("timerMetric", responseTimesMetric.time());
|
||||||
String metricName = MetricRegistry.name(getClass(), "responseTimes", actor.getType().name());
|
|
||||||
Timer responseTimesActorTypeMetric = APIv3.getMetrics().timer(metricName);
|
|
||||||
|
|
||||||
req.attribute("timerMetric.global", responseTimesGlobalMetric.time());
|
|
||||||
req.attribute("timerMetric.actorType", responseTimesActorTypeMetric.time());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ public final class ServerGroup {
|
|||||||
// We define these HashSets up here because, in the event they're
|
// We define these HashSets up here because, in the event they're
|
||||||
// empty, Morphia will load them as null, not empty sets.
|
// empty, Morphia will load them as null, not empty sets.
|
||||||
@Getter @Setter @ExcludeFromReplies private Set<String> announcements = new HashSet<>();
|
@Getter @Setter @ExcludeFromReplies private Set<String> announcements = new HashSet<>();
|
||||||
@Getter private Map<String, List<String>> permissions = new HashMap<>();
|
@Getter @ExcludeFromReplies private Map<String, List<String>> permissions = new HashMap<>();
|
||||||
|
|
||||||
public static ServerGroup byId(String id) {
|
public static ServerGroup byId(String id) {
|
||||||
return APIv3.getDatastore().createQuery(ServerGroup.class).field("id").equal(id).get();
|
return APIv3.getDatastore().createQuery(ServerGroup.class).field("id").equal(id).get();
|
||||||
|
@ -30,7 +30,7 @@ public final class GETDump implements Route {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return effectedUsers;
|
return effectedUsers;
|
||||||
case "accessDeniable":
|
case "accessdeniable": // Lowercase d because we convert to lowercase above
|
||||||
// We have to name it effectedUsers2 because Java's
|
// We have to name it effectedUsers2 because Java's
|
||||||
// scoping in switch statements is really dumb.
|
// scoping in switch statements is really dumb.
|
||||||
List<UUID> effectedUsers2 = new ArrayList<>();
|
List<UUID> effectedUsers2 = new ArrayList<>();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.frozenorb.apiv3.routes;
|
package net.frozenorb.apiv3.routes;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.utils.ErrorUtils;
|
import net.frozenorb.apiv3.utils.ErrorUtils;
|
||||||
import spark.Request;
|
import spark.Request;
|
||||||
@ -7,9 +8,11 @@ import spark.Response;
|
|||||||
import spark.Route;
|
import spark.Route;
|
||||||
import spark.Spark;
|
import spark.Spark;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public final class NotFound implements Route {
|
public final class NotFound implements Route {
|
||||||
|
|
||||||
public Object handle(Request req, Response res) {
|
public Object handle(Request req, Response res) {
|
||||||
|
log.info(req.requestMethod().toUpperCase() + " " + req.url());
|
||||||
Spark.halt(404, APIv3.getGson().toJson(ErrorUtils.notFound("Route", req.url())));
|
Spark.halt(404, APIv3.getGson().toJson(ErrorUtils.notFound("Route", req.url())));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public final class POSTServer implements Route {
|
|||||||
|
|
||||||
public Object handle(Request req, Response res) {
|
public Object handle(Request req, Response res) {
|
||||||
String id = req.queryParams("id");
|
String id = req.queryParams("id");
|
||||||
String bungeeId = req.queryParams("id");
|
String bungeeId = req.queryParams("bungeeId");
|
||||||
String displayName = req.queryParams("displayName");
|
String displayName = req.queryParams("displayName");
|
||||||
String apiKey = req.queryParams("apiKey");
|
String apiKey = req.queryParams("apiKey");
|
||||||
ServerGroup group = ServerGroup.byId(req.queryParams("group"));
|
ServerGroup group = ServerGroup.byId(req.queryParams("group"));
|
||||||
|
@ -13,11 +13,8 @@ import spark.Response;
|
|||||||
public final class LoggingExceptionHandler implements ExceptionHandler {
|
public final class LoggingExceptionHandler implements ExceptionHandler {
|
||||||
|
|
||||||
public void handle(Exception ex, Request req, Response res) {
|
public void handle(Exception ex, Request req, Response res) {
|
||||||
Timer.Context timerMetricActorType = req.attribute("timerMetric.actorType");
|
Timer.Context timerMetric = req.attribute("timerMetric");
|
||||||
Timer.Context timerMetricGlobal = req.attribute("timerMetric.global");
|
timerMetric.stop();
|
||||||
|
|
||||||
timerMetricActorType.stop();
|
|
||||||
timerMetricGlobal.stop();
|
|
||||||
|
|
||||||
String code = new ObjectId().toHexString();
|
String code = new ObjectId().toHexString();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user