Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
refactor: use storages instead of settings storage (#56)
Browse files Browse the repository at this point in the history
* Add absent repos

* cicd(release): added release config for #38

* Fixed parameters and storage settings format in `ApiRepoUpdateSlice`

Closes #39 - fixed 2 problems in ApiRepoUpdateSlice:
 1) parameters separator was expected to be ; instead of &
 2) storage settings were always expected to be yaml, but there also can be string for default value

PR: #40

* Repo config should be url decoded

Closes #39 - Body with repo configs should be url-decoded.

PR: #41

* Improved updating storage settings functionality (#43)

Closes #42 - simplified and fixed updating storage scenario in ApiRepoUpdateSlice.

On dashboard we always work with whole yaml repo settings, so there is no need to update section by section, we can simply rewrite the whole file after checking that required fields (type and storage) are present in the new version.

* fix: added repository configuration descriptions

Added description for several repositories.

Issue: artipie/artipie#317
PR: #44

* fix: handle errors in `ApiRepoUpdateSlice` (#45)

Handle errors in `ApiRepoUpdateSlice` (#45)

Closes: artipie/artipie#320

* feat(conda): added conda repository to dashboard (#46)

Added anaconda repository option to dashboard and configuration description.

Ticket: artipie/artipie#317

* doc: verbose link name

Clarified API reference link name.

Closes: #47

* fix: add rq line to get users in `FromRqLine` (#48)

Part of artipie/artipie#965
Added rq line to get users in FromRqLine, corresponding test and updated http and asto.

* feat: added slice for repo delete (#49)

Add slice to delete a repo. Added disabled test for this slice as it is necessary to implement delete operation in FakeConfigFile class.

Ticket: artipie/artipie#321

* feat: add slice for routing `POST` requests (#51)

Added slice ApiRepoPostRtSlice for routing post requests by parsing body content. This class will be used in artipie module. Test will be added in next PR.

Ticket: artipie/artipie#321

* deps: bumped ppom and other deps (#53)

 * Bumped ppom from 0.5.1 to 1.1.0
 * Bumped asto from v1.9.0 to v1.10.0
 * Bumped http-client from 0.3.2 to 0.3.6
 * Bumped vert-server from 0.4 to 0.5

* refactor: extract class for body parsing (#52)

Extract class for parsing body content for receiving some content.

Close: #50

* test: enable test for delete and add for postRt (#55)

Enable and a bit extend test for ApiRepoDeleteSlice and add test for ApiRepoPostRtSlice.

Ref: artipie/artipie#321

* refactor: use storages instead of settings storage

Co-authored-by: Kirill <g4s8.public@gmail.com>
Co-authored-by: Alena <olena.gerasimova@gmail.com>
  • Loading branch information
3 people committed Dec 22, 2021
1 parent 22d4568 commit 5695cf8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Response response(
}

/**
* Removes conifuration file and items from the storage.
* Removes configuration file and items from the storage.
* @param repo Key to the repo configuration
* @param prefix Key to the repo with items
* @return Result of completion
Expand Down
52 changes: 31 additions & 21 deletions src/main/java/com/artipie/management/api/ApiRepoPostRtSlice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
package com.artipie.management.api;

import com.artipie.asto.Content;
import com.artipie.asto.Storage;
import com.artipie.asto.ext.PublisherAs;
import com.artipie.http.Response;
import com.artipie.http.Slice;
import com.artipie.http.async.AsyncResponse;
import com.artipie.http.rs.RsStatus;
import com.artipie.http.rs.RsWithStatus;
import com.artipie.management.ConfigFiles;
import com.artipie.management.Storages;
import com.artipie.management.misc.ValueFromBody;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.regex.Pattern;
import org.reactivestreams.Publisher;

Expand All @@ -38,17 +40,17 @@ public final class ApiRepoPostRtSlice implements Slice {
private final ConfigFiles configfile;

/**
* Storage.
* Artipie storages.
*/
private final Storage storage;
private final Storages storages;

/**
* Ctor.
* @param storage Storage
* @param storages Artipie storages
* @param configfile Config file to support `.yaml` and `.yml` extensions
*/
public ApiRepoPostRtSlice(final Storage storage, final ConfigFiles configfile) {
this.storage = storage;
public ApiRepoPostRtSlice(final Storages storages, final ConfigFiles configfile) {
this.storages = storages;
this.configfile = configfile;
}

Expand All @@ -61,29 +63,37 @@ public Response response(
return new AsyncResponse(
new PublisherAs(content)
.asciiString()
.thenApply(
.thenCompose(
form -> {
final Response res;
final CompletionStage<Response> res;
final ValueFromBody vals = new ValueFromBody(form);
final Optional<String> meth = vals.byName("action");
if (meth.isPresent() && Action.UPDATE.value().equals(meth.get())) {
res = new ApiRepoUpdateSlice(this.configfile)
.response(
line, headers,
new Content.From(
vals.payload().getBytes(StandardCharsets.UTF_8)
)
res = CompletableFuture.allOf()
.thenApply(
noth -> new ApiRepoUpdateSlice(this.configfile)
.response(
line, headers,
new Content.From(
vals.payload().getBytes(StandardCharsets.UTF_8)
)
)
);
} else if (meth.isPresent() && Action.DELETE.value().equals(meth.get())) {
res = new ApiRepoDeleteSlice(this.storage, this.configfile)
.response(
line, headers,
new Content.From(
vals.payload().getBytes(StandardCharsets.UTF_8)
)
res = this.storages.repoStorage(vals.byNameOrThrow("repo"))
.thenApply(
storage -> new ApiRepoDeleteSlice(storage, this.configfile)
.response(
line, headers,
new Content.From(
vals.payload().getBytes(StandardCharsets.UTF_8)
)
)
);
} else {
res = new RsWithStatus(RsStatus.BAD_REQUEST);
res = CompletableFuture.completedFuture(
new RsWithStatus(RsStatus.BAD_REQUEST)
);
}
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import com.artipie.http.rq.RqMethod;
import com.artipie.http.rs.RsStatus;
import com.artipie.management.FakeConfigFile;
import com.artipie.management.Storages;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
Expand All @@ -30,19 +32,26 @@
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
final class ApiRepoPostRtSliceTest {
/**
* Storage.
* Repo storage.
*/
private Storage storage;
private Storages storages;

/**
* Artipie configuration files storage.
*/
private Storage artipie;

@BeforeEach
void setUp() {
this.storage = new InMemoryStorage();
this.artipie = new InMemoryStorage();
this.storages = new Storages.Fake(new InMemoryStorage());
}

@ParameterizedTest
@ValueSource(strings = {"action=unknown", "no_key=ignore"})
void returnBadRequest(final String body) {
MatcherAssert.assertThat(
new ApiRepoPostRtSlice(this.storage, new FakeConfigFile(this.storage)),
new ApiRepoPostRtSlice(this.storages, new FakeConfigFile(this.artipie)),
new SliceHasResponse(
new RsHasStatus(RsStatus.BAD_REQUEST),
new RequestLine(RqMethod.POST, "/api/repos/user"),
Expand All @@ -62,7 +71,7 @@ void returnFoundForUpdate() {
)
);
MatcherAssert.assertThat(
new ApiRepoPostRtSlice(this.storage, new FakeConfigFile(this.storage)),
new ApiRepoPostRtSlice(this.storages, new FakeConfigFile(this.artipie)),
new SliceHasResponse(
new RsHasStatus(RsStatus.FOUND),
new RequestLine(RqMethod.POST, "/api/repos/user"),
Expand All @@ -74,9 +83,9 @@ void returnFoundForUpdate() {

@Test
void returnFoundOkForDelete() {
this.storage.save(new Key.From("user", "bin.yaml"), Content.EMPTY).join();
this.artipie.save(new Key.From("user", "bin.yaml"), Content.EMPTY).join();
MatcherAssert.assertThat(
new ApiRepoPostRtSlice(this.storage, new FakeConfigFile(this.storage)),
new ApiRepoPostRtSlice(this.storages, new FakeConfigFile(this.artipie)),
new SliceHasResponse(
new RsHasStatus(RsStatus.OK),
new RequestLine(RqMethod.POST, "/api/repos/user"),
Expand Down

0 comments on commit 5695cf8

Please sign in to comment.