use of com.artipie.front.api.DeleteRepository in project front by artipie.
the class Service method start.
/**
* Start service.
* @param port Port for service
*/
private void start(final int port) {
if (this.ignite != null) {
throw new IllegalStateException("already started");
}
Logger.info(this, "starting service on port: %d", port);
this.ignite = spark.Service.ignite().port(port);
this.ignite.get("/.health", new HealthRoute());
this.ignite.path("/api", () -> {
this.ignite.before("/*", new ApiAuthFilter((tkn, time) -> "anonymous"));
this.ignite.path("/repositories", () -> {
final RepoSettings stn = new RepoSettings(this.settings.layout(), this.settings.repoConfigsStorage());
this.ignite.get("", MimeTypes.Type.APPLICATION_JSON.asString(), new Repositories(stn));
final RequestPath path = new RequestPath().with(GetRepository.NAME_PARAM);
this.ignite.get(path.toString(), MimeTypes.Type.APPLICATION_JSON.asString(), new GetRepository(stn));
this.ignite.head(path.toString(), new HeadRepository(stn));
this.ignite.delete(path.toString(), new DeleteRepository(stn));
this.ignite.put(path.toString(), new PutRepository(stn));
this.ignite.get(path.with("permissions").toString(), new GetRepositoryPermissions(stn));
});
this.ignite.path("/users", () -> {
this.ignite.get("/", MimeTypes.Type.APPLICATION_JSON.asString(), new Users(this.settings.users()));
final String path = new RequestPath().with(GetUser.USER_PARAM).toString();
this.ignite.get(path, new GetUser(this.settings.credentials()));
this.ignite.put(path, new PutUser(this.settings.users()));
this.ignite.head(path, new HeadUser(this.settings.credentials()));
this.ignite.delete(path, new DeleteUser(this.settings.users()));
});
});
final var engine = new HandlebarsTemplateEngine("/html");
this.ignite.path("/signin", () -> {
this.ignite.get("", MimeTypes.Type.APPLICATION_JSON.asString(), new SignInPage(), engine);
this.ignite.post("", new PostSignIn(AuthByPassword.withCredentials(this.settings.credentials())));
});
this.ignite.path("/dashboard", () -> {
this.ignite.get("", new UserPage(new RepoSettings(this.settings.layout(), this.settings.repoConfigsStorage())), engine);
});
this.ignite.before(AuthFilters.AUTHENTICATE);
this.ignite.before(AuthFilters.SESSION_ATTRS);
this.ignite.exception(NotFoundException.class, (ex, rqs, rsp) -> {
rsp.type("application/json");
rsp.body(Json.createObjectBuilder().add("error", ex.getLocalizedMessage()).build().toString());
});
this.ignite.awaitInitialization();
Logger.info(this, "service started on port: %d", this.ignite.port());
}
Aggregations