Search in sources :

Example 1 with GetRepository

use of com.artipie.front.api.GetRepository 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());
}
Also used : GetUser(com.artipie.front.api.GetUser) HealthRoute(com.artipie.front.internal.HealthRoute) AuthByPassword(com.artipie.front.auth.AuthByPassword) DeleteUser(com.artipie.front.api.DeleteUser) Options(org.apache.commons.cli.Options) HandlebarsTemplateEngine(spark.template.handlebars.HandlebarsTemplateEngine) GetRepositoryPermissions(com.artipie.front.api.GetRepositoryPermissions) HelpFormatter(org.apache.commons.cli.HelpFormatter) GetRepository(com.artipie.front.api.GetRepository) DefaultParser(org.apache.commons.cli.DefaultParser) ArtipieYaml(com.artipie.front.settings.ArtipieYaml) UserPage(com.artipie.front.ui.UserPage) PutRepository(com.artipie.front.api.PutRepository) Json(javax.json.Json) CommandLine(org.apache.commons.cli.CommandLine) Repositories(com.artipie.front.api.Repositories) NotFoundException(com.artipie.front.api.NotFoundException) SignInPage(com.artipie.front.ui.SignInPage) Option(org.apache.commons.cli.Option) Users(com.artipie.front.api.Users) DeleteRepository(com.artipie.front.api.DeleteRepository) CommandLineParser(org.apache.commons.cli.CommandLineParser) ApiAuthFilter(com.artipie.front.api.ApiAuthFilter) HeadUser(com.artipie.front.api.HeadUser) RequestPath(com.artipie.front.misc.RequestPath) HeadRepository(com.artipie.front.api.HeadRepository) IOException(java.io.IOException) Yaml(com.amihaiemil.eoyaml.Yaml) File(java.io.File) PutUser(com.artipie.front.api.PutUser) ParseException(org.apache.commons.cli.ParseException) PostSignIn(com.artipie.front.ui.PostSignIn) RepoSettings(com.artipie.front.settings.RepoSettings) Logger(com.jcabi.log.Logger) MimeTypes(org.eclipse.jetty.http.MimeTypes) Repositories(com.artipie.front.api.Repositories) RequestPath(com.artipie.front.misc.RequestPath) PutRepository(com.artipie.front.api.PutRepository) GetRepository(com.artipie.front.api.GetRepository) GetRepositoryPermissions(com.artipie.front.api.GetRepositoryPermissions) DeleteUser(com.artipie.front.api.DeleteUser) Users(com.artipie.front.api.Users) UserPage(com.artipie.front.ui.UserPage) ApiAuthFilter(com.artipie.front.api.ApiAuthFilter) DeleteRepository(com.artipie.front.api.DeleteRepository) PostSignIn(com.artipie.front.ui.PostSignIn) HeadUser(com.artipie.front.api.HeadUser) HealthRoute(com.artipie.front.internal.HealthRoute) RepoSettings(com.artipie.front.settings.RepoSettings) HeadRepository(com.artipie.front.api.HeadRepository) SignInPage(com.artipie.front.ui.SignInPage) HandlebarsTemplateEngine(spark.template.handlebars.HandlebarsTemplateEngine) PutUser(com.artipie.front.api.PutUser) GetUser(com.artipie.front.api.GetUser)

Aggregations

Yaml (com.amihaiemil.eoyaml.Yaml)1 ApiAuthFilter (com.artipie.front.api.ApiAuthFilter)1 DeleteRepository (com.artipie.front.api.DeleteRepository)1 DeleteUser (com.artipie.front.api.DeleteUser)1 GetRepository (com.artipie.front.api.GetRepository)1 GetRepositoryPermissions (com.artipie.front.api.GetRepositoryPermissions)1 GetUser (com.artipie.front.api.GetUser)1 HeadRepository (com.artipie.front.api.HeadRepository)1 HeadUser (com.artipie.front.api.HeadUser)1 NotFoundException (com.artipie.front.api.NotFoundException)1 PutRepository (com.artipie.front.api.PutRepository)1 PutUser (com.artipie.front.api.PutUser)1 Repositories (com.artipie.front.api.Repositories)1 Users (com.artipie.front.api.Users)1 AuthByPassword (com.artipie.front.auth.AuthByPassword)1 HealthRoute (com.artipie.front.internal.HealthRoute)1 RequestPath (com.artipie.front.misc.RequestPath)1 ArtipieYaml (com.artipie.front.settings.ArtipieYaml)1 RepoSettings (com.artipie.front.settings.RepoSettings)1 PostSignIn (com.artipie.front.ui.PostSignIn)1