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<>());
}
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")));
}
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());
}
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");
}
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);
}
Aggregations