Search in sources :

Example 1 with RepoSettings

use of com.artipie.front.settings.RepoSettings in project front by artipie.

the class HeadRepositoryTest method returnOkWhenRepoFound.

@ParameterizedTest
@CsvSource({ "flat,binary-repo.yaml,binary-repo", "org,Mark/pypi.yml,pypi" })
void returnOkWhenRepoFound(final String layout, final String key, final String name) {
    final String uid = "Mark";
    this.blsto.save(new Key.From(key), new byte[] {});
    final var rqs = Mockito.mock(Request.class);
    Mockito.when(rqs.params(GetRepository.NAME_PARAM.toString())).thenReturn(name);
    Mockito.when(rqs.attribute(RequestAttr.Standard.USER_ID.attrName())).thenReturn(uid);
    MatcherAssert.assertThat(new HeadRepository(new RepoSettings(layout, this.blsto)).handle(rqs, Mockito.mock(Response.class)), new IsAnything<>());
}
Also used : RepoSettings(com.artipie.front.settings.RepoSettings) Key(com.artipie.asto.Key) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with RepoSettings

use of com.artipie.front.settings.RepoSettings in project front by artipie.

the class PutRepositoryTest method addsNewRepo.

@Test
void addsNewRepo() {
    final var resp = Mockito.mock(Response.class);
    final var rqs = Mockito.mock(Request.class);
    Mockito.when(rqs.params(GetRepository.NAME_PARAM.toString())).thenReturn("my-rpm");
    Mockito.when(rqs.attribute(RequestAttr.Standard.USER_ID.attrName())).thenReturn("any");
    Mockito.when(rqs.body()).thenReturn(new String(new TestResource("PutRepositoryTest/request.json").asBytes(), StandardCharsets.UTF_8));
    MatcherAssert.assertThat("Failed to return empty response", new PutRepository(new RepoSettings("flat", this.blsto)).handle(rqs, resp), new IsAnything<>());
    Mockito.verify(resp).status(HttpStatus.CREATED_201);
    MatcherAssert.assertThat(new String(this.blsto.value(new Key.From("my-rpm.yml")), StandardCharsets.UTF_8), new IsEqual<>(String.join(System.lineSeparator(), "repo:", "  type: rpm", "  storage:", "    type: fs", "    path: /var/artipie/data/", "  settings:", "    digest: sha1", "    filelists: false", "  permissions:", "    alice:", "      - read", "      - write", "    bob:", "      - read")));
}
Also used : RepoSettings(com.artipie.front.settings.RepoSettings) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with RepoSettings

use of com.artipie.front.settings.RepoSettings 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)

Example 4 with RepoSettings

use of com.artipie.front.settings.RepoSettings in project front by artipie.

the class RepositoriesTest method listsRepositories.

@Test
void listsRepositories() throws JSONException {
    final BlockingStorage blsto = new BlockingStorage(new InMemoryStorage());
    blsto.save(new Key.From("Jane", "maven.yaml"), new byte[] {});
    blsto.save(new Key.From("Jane", "python.yaml"), new byte[] {});
    blsto.save(new Key.From("Jane", "binary.yaml"), new byte[] {});
    blsto.save(new Key.From("John", "anaconda.yml"), new byte[] {});
    blsto.save(new Key.From("John", "maven.yml"), new byte[] {});
    blsto.save(new Key.From("rpm.yml"), new byte[] {});
    final var resp = Mockito.mock(Response.class);
    JSONAssert.assertEquals(new Repositories(new RepoSettings("org", blsto)).handle(Mockito.mock(Request.class), resp), String.join("\n", "[", "{\"fullName\":\"Jane/binary\"},", "{\"fullName\":\"Jane/maven\"},", "{\"fullName\":\"Jane/python\"},", "{\"fullName\":\"John/anaconda\"},", "{\"fullName\":\"John/maven\"},", "{\"fullName\":\"rpm\"}", "]"), true);
    Mockito.verify(resp).type("application/json");
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) RepoSettings(com.artipie.front.settings.RepoSettings) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 5 with RepoSettings

use of com.artipie.front.settings.RepoSettings in project front by artipie.

the class GetRepositoryPermissionsTest method init.

@BeforeEach
void init() {
    this.blsto = new BlockingStorage(new InMemoryStorage());
    this.snt = new RepoSettings("flat", this.blsto);
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) RepoSettings(com.artipie.front.settings.RepoSettings) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

RepoSettings (com.artipie.front.settings.RepoSettings)8 Key (com.artipie.asto.Key)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)3 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)3 Test (org.junit.jupiter.api.Test)3 TestResource (com.artipie.asto.test.TestResource)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 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