Search in sources :

Example 11 with Key

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

the class SettingsFromPath method find.

/**
 * Searches settings by the provided path, if no settings are found,
 * example setting set is used.
 * @param port Port for info logging
 * @return Artipie settings
 * @throws IOException On IO error
 */
public Settings find(final int port) throws IOException {
    boolean initialize = Boolean.parseBoolean(System.getenv("ARTIPIE_INIT"));
    if (!Files.exists(this.path)) {
        new JavaResource("example/artipie.yaml").copy(this.path);
        initialize = true;
    }
    final Settings settings = new YamlSettings(Yaml.createYamlInput(this.path.toFile()).readYamlMapping(), new SettingsCaches.All());
    final BlockingStorage bsto = new BlockingStorage(settings.storage());
    final Key init = new Key.From(".artipie", "initialized");
    if (initialize && !bsto.exists(init)) {
        final List<String> resources = Arrays.asList("_credentials.yaml", StorageAliases.FILE_NAME, "_permissions.yaml");
        for (final String res : resources) {
            final Path tmp = Files.createTempFile(res, ".tmp");
            new JavaResource(String.format("example/repo/%s", res)).copy(tmp);
            bsto.save(new Key.From(res), Files.readAllBytes(tmp));
            Files.delete(tmp);
        }
        bsto.save(init, "true".getBytes());
        Logger.info(VertxMain.class, String.join("\n", "", "", "\t+===============================================================+", "\t\t\t\t\tHello!", "\t\tArtipie configuration was not found, created default.", "\t\t\tDefault username/password: `artipie`/`artipie`. ", "\t\t\t\t   Check the dashboard at:", String.format("\t\t\thttp://localhost:%d/dashboard/artipie", port), "\t-===============================================================-", ""));
    }
    return settings;
}
Also used : Path(java.nio.file.Path) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) SettingsCaches(com.artipie.cache.SettingsCaches) Key(com.artipie.asto.Key)

Example 12 with Key

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

the class CachedProxySlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final RequestLineFrom req = new RequestLineFrom(line);
    final Key key = new KeyFromPath(req.uri().getPath());
    return new AsyncResponse(new RepoHead(this.client).head(req.uri().getPath()).thenCompose(head -> this.cache.load(key, new Remote.WithErrorHandling(() -> {
        final CompletableFuture<Optional<? extends Content>> promise = new CompletableFuture<>();
        this.client.response(line, Headers.EMPTY, Content.EMPTY).send((rsstatus, rsheaders, rsbody) -> {
            final CompletableFuture<Void> term = new CompletableFuture<>();
            if (rsstatus.success()) {
                final Flowable<ByteBuffer> res = Flowable.fromPublisher(rsbody).doOnError(term::completeExceptionally).doOnTerminate(() -> term.complete(null));
                promise.complete(Optional.of(new Content.From(res)));
            } else {
                promise.complete(Optional.empty());
            }
            return term;
        });
        return promise;
    }), new CacheControl.All(StreamSupport.stream(head.orElse(Headers.EMPTY).spliterator(), false).map(Header::new).map(CachedProxySlice::checksumControl).collect(Collectors.toUnmodifiableList()))).handle((content, throwable) -> {
        final Response result;
        if (throwable == null && content.isPresent()) {
            result = new RsWithBody(StandardRs.OK, new Content.From(content.get()));
        } else {
            result = StandardRs.NOT_FOUND;
        }
        return result;
    })));
}
Also used : Header(com.artipie.http.headers.Header) Slice(com.artipie.http.Slice) CompletableFuture(java.util.concurrent.CompletableFuture) Hex(org.apache.commons.codec.binary.Hex) DigestVerification(com.artipie.asto.cache.DigestVerification) RsWithBody(com.artipie.http.rs.RsWithBody) ByteBuffer(java.nio.ByteBuffer) Digests(com.artipie.asto.ext.Digests) Matcher(java.util.regex.Matcher) Flowable(io.reactivex.Flowable) Locale(java.util.Locale) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Remote(com.artipie.asto.cache.Remote) KeyFromPath(com.artipie.http.slice.KeyFromPath) Headers(com.artipie.http.Headers) DecoderException(org.apache.commons.codec.DecoderException) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Cache(com.artipie.asto.cache.Cache) Pattern(java.util.regex.Pattern) StandardRs(com.artipie.http.rs.StandardRs) CacheControl(com.artipie.asto.cache.CacheControl) Optional(java.util.Optional) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) ByteBuffer(java.nio.ByteBuffer) RsWithBody(com.artipie.http.rs.RsWithBody) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) CompletableFuture(java.util.concurrent.CompletableFuture) KeyFromPath(com.artipie.http.slice.KeyFromPath) Content(com.artipie.asto.Content) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Example 13 with Key

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

the class AstoValidUpload method validateMetadata.

/**
 * Validates uploaded and existing metadata by comparing group and artifact ids.
 * @param upload Uploaded artifacts location
 * @param artifact Artifact location
 * @return Completable validation action: true if group and artifact ids are equal,
 *  false otherwise.
 */
private CompletionStage<Boolean> validateMetadata(final Key upload, final Key artifact) {
    final ArtifactsMetadata metadata = new ArtifactsMetadata(this.storage);
    final String meta = "maven-metadata.xml";
    return this.storage.exists(new Key.From(artifact, meta)).thenCompose(exists -> {
        final CompletionStage<Boolean> res;
        if (exists) {
            res = metadata.groupAndArtifact(new Key.From(upload, PutMetadataSlice.SUB_META)).thenCompose(existing -> metadata.groupAndArtifact(artifact).thenApply(uploaded -> uploaded.equals(existing)));
        } else {
            res = CompletableFuture.completedStage(true);
        }
        return res;
    }).thenCompose(same -> {
        final CompletionStage<Boolean> res;
        if (same) {
            res = this.validateArtifactChecksums(new Key.From(upload, meta)).to(SingleInterop.get());
        } else {
            res = CompletableFuture.completedStage(false);
        }
        return res;
    });
}
Also used : ContentDigest(com.artipie.asto.ext.ContentDigest) ArtifactsMetadata(com.artipie.maven.metadata.ArtifactsMetadata) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) CompletableFuture(java.util.concurrent.CompletableFuture) Key(com.artipie.asto.Key) Single(io.reactivex.Single) Collectors(java.util.stream.Collectors) Digests(com.artipie.asto.ext.Digests) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) ArrayList(java.util.ArrayList) ValidUpload(com.artipie.maven.ValidUpload) CompletionStage(java.util.concurrent.CompletionStage) RxStorageWrapper(com.artipie.asto.rx.RxStorageWrapper) Storage(com.artipie.asto.Storage) Locale(java.util.Locale) Map(java.util.Map) Observable(io.reactivex.Observable) Pattern(java.util.regex.Pattern) ArtifactsMetadata(com.artipie.maven.metadata.ArtifactsMetadata) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Example 14 with Key

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

the class AstoMavenTest method addFilesToStorage.

private void addFilesToStorage(final Predicate<String> condition, final Key base) {
    final Storage resources = new FileStorage(new TestResource("com/artipie/asto").asPath());
    final BlockingStorage bsto = new BlockingStorage(resources);
    bsto.list(Key.ROOT).stream().map(Key::string).filter(condition).forEach(item -> new BlockingStorage(this.storage).save(new Key.From(base, item), bsto.value(new Key.From(item))));
}
Also used : BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) FileStorage(com.artipie.asto.fs.FileStorage) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key)

Example 15 with Key

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

the class AstoMavenTest method addsMetadataChecksums.

@Test
void addsMetadataChecksums() {
    final String version = "0.1";
    new TestResource("maven-metadata.xml.example").saveTo(this.storage, new Key.From(AstoMavenTest.LGR_UPLOAD, version, PutMetadataSlice.SUB_META, "maven-metadata.xml"));
    new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.LGR_UPLOAD, version), AstoMavenTest.LGR).toCompletableFuture().join();
    MatcherAssert.assertThat(this.storage.list(AstoMavenTest.LGR).join().stream().map(key -> new KeyLastPart(key).get()).filter(key -> key.contains("maven-metadata.xml")).toArray(String[]::new), Matchers.arrayContainingInAnyOrder("maven-metadata.xml", "maven-metadata.xml.sha1", "maven-metadata.xml.sha256", "maven-metadata.xml.sha512", "maven-metadata.xml.md5"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataXml(com.artipie.maven.MetadataXml) XhtmlMatchers(com.jcabi.matchers.XhtmlMatchers) AllOf(org.hamcrest.core.AllOf) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) ListOf(org.cactoos.list.ListOf) IsEqual(org.hamcrest.core.IsEqual) TestResource(com.artipie.asto.test.TestResource) XMLDocument(com.jcabi.xml.XMLDocument) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Predicate(java.util.function.Predicate) KeyLastPart(com.artipie.asto.ext.KeyLastPart) Matchers(org.hamcrest.Matchers) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) PublisherAs(com.artipie.asto.ext.PublisherAs) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) XML(com.jcabi.xml.XML) KeyLastPart(com.artipie.asto.ext.KeyLastPart) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

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