Search in sources :

Example 21 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class PutMetadataSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Response res;
    final Matcher matcher = PutMetadataSlice.PTN_META.matcher(new RequestLineFrom(line).uri().getPath());
    if (matcher.matches()) {
        final Key pkg = new KeyFromPath(matcher.group("pkg"));
        res = new AsyncResponse(new PublisherAs(body).asciiString().thenCombine(this.asto.list(new Key.From(UploadSlice.TEMP, pkg)), (xml, list) -> {
            final Optional<String> snapshot = new DeployMetadata(xml).snapshots().stream().filter(item -> list.stream().anyMatch(key -> key.string().contains(item))).findFirst();
            final Key key;
            if (snapshot.isPresent()) {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), snapshot.get(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            } else {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), new DeployMetadata(xml).release(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            }
            return this.asto.save(key, new Content.From(xml.getBytes(StandardCharsets.US_ASCII)));
        }).thenApply(nothing -> new RsWithStatus(RsStatus.CREATED)));
    } else {
        res = new RsWithStatus(RsStatus.BAD_REQUEST);
    }
    return res;
}
Also used : PublisherAs(com.artipie.asto.ext.PublisherAs) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) RsWithStatus(com.artipie.http.rs.RsWithStatus) KeyFromPath(com.artipie.http.slice.KeyFromPath) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) Slice(com.artipie.http.Slice) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) ByteBuffer(java.nio.ByteBuffer) StandardCharsets(java.nio.charset.StandardCharsets) PublisherAs(com.artipie.asto.ext.PublisherAs) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Map(java.util.Map) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Optional(java.util.Optional) Matcher(java.util.regex.Matcher) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) KeyFromPath(com.artipie.http.slice.KeyFromPath) RsWithStatus(com.artipie.http.rs.RsWithStatus) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Example 22 with Key

use of com.artipie.asto.Key in project front by artipie.

the class ArtipieYaml method credentials.

/**
 * Credentials from config.
 * @return Credentials
 */
public Credentials credentials() {
    final Optional<Key> key = this.fileCredentialsKey();
    Optional<YamlMapping> res = Optional.empty();
    if (key.isPresent() && this.storage().exists(key.get())) {
        try {
            res = Optional.of(Yaml.createYamlInput(new String(this.storage().value(key.get()), StandardCharsets.UTF_8)).readYamlMapping());
        } catch (final IOException err) {
            throw new UncheckedIOException(err);
        }
    } else if (key.isPresent()) {
        res = Optional.of(Yaml.createYamlMappingBuilder().build());
    }
    return new YamlCredentials(res.orElseThrow(() -> new NotImplementedException("Not implemented yet")));
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) UncheckedIOException(java.io.UncheckedIOException) YamlCredentials(com.artipie.front.auth.YamlCredentials) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Key(com.artipie.asto.Key)

Example 23 with Key

use of com.artipie.asto.Key in project front by artipie.

the class RepoSettings method list.

/**
 * List existing repositories.
 * @param uid User id (=name)
 * @return List of the existing repositories
 */
public Collection<String> list(final Optional<String> uid) {
    Key key = Key.ROOT;
    if ("org".equals(this.layout) && uid.isPresent()) {
        key = new Key.From(uid.get());
    }
    final Collection<String> res = new ArrayList<>(5);
    for (final Key item : this.repos.list(key)) {
        final String name = item.string();
        // @checkstyle BooleanExpressionComplexityCheck (5 lines)
        if ((name.endsWith(".yaml") || name.endsWith(".yml")) && !name.contains(YamlStorages.FILE_NAME) && !name.contains("_permissions") && !name.contains("_credentials")) {
            res.add(name.replaceAll("\\.yaml|\\.yml", ""));
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) Key(com.artipie.asto.Key)

Example 24 with Key

use of com.artipie.asto.Key in project front by artipie.

the class DeleteRepositoryTest method removesRepository.

@ParameterizedTest
@CsvSource({ "flat,binary-repo.yaml,binary-repo", "org,Alice/docker.yml,docker" })
void removesRepository(final String layout, final String key, final String name) {
    final String uid = "Alice";
    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("Failed to process request", new DeleteRepository(new RepoSettings(layout, this.blsto)).handle(rqs, Mockito.mock(Response.class)), new IsAnything<>());
    MatcherAssert.assertThat("Item was not removed from storage", this.blsto.exists(new Key.From(key)), new IsEqual<>(false));
}
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 25 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class AstoValidUploadTest method returnsTrueWhenReady.

@ParameterizedTest
@CsvSource({ "pom;pom.sha1;jar;jar.sha1,xml;xml.sha1,true", "war;war.md5;war.sha1,xml;xml.sha1;xml.md5,true", "pom;rar,xml;xml.sha1;xml.sha256,false", "'',xml;xml.sha1;xml.md5,false", "jar;jar.sha256,xml;xml.sha1,false", "war;war.sha256,xml,false" })
void returnsTrueWhenReady(final String artifacts, final String meta, final boolean res) {
    final Key location = new Key.From(".upload/com/artipie/example/0.2");
    Arrays.stream(artifacts.split(";")).forEach(item -> this.bsto.save(new Key.From(location, String.format("example-0.2.%s", item)), new byte[] {}));
    Arrays.stream(meta.split(";")).forEach(item -> this.bsto.save(new Key.From(location, PutMetadataSlice.SUB_META, String.format("maven-metadata.%s", item)), new byte[] {}));
    MatcherAssert.assertThat(this.validupload.ready(location).toCompletableFuture().join(), new IsEqual<>(res));
}
Also used : Key(com.artipie.asto.Key) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Key (com.artipie.asto.Key)37 Test (org.junit.jupiter.api.Test)17 Storage (com.artipie.asto.Storage)16 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)13 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)9 Content (com.artipie.asto.Content)8 Optional (java.util.Optional)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)6 PublisherAs (com.artipie.asto.ext.PublisherAs)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6 Collectors (java.util.stream.Collectors)5 TestResource (com.artipie.asto.test.TestResource)4 Response (com.artipie.http.Response)4 Slice (com.artipie.http.Slice)4 AsyncResponse (com.artipie.http.async.AsyncResponse)4 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)4 CompletionStage (java.util.concurrent.CompletionStage)4