Search in sources :

Example 1 with Key

use of com.artipie.asto.Key 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 Key

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

the class RepoSettings method key.

/**
 * Find repository settings key by repository name and username, throws exception
 * if settings file is not found.
 * @param name Repository name
 * @param uid User id (=name)
 * @return Repository settings
 * @throws NotFoundException If such repository does not exist
 */
public Key key(final String name, final String uid) {
    final Pair<Key, Key> pair = this.keys(name, uid);
    Key res = pair.getLeft();
    if (!this.repos.exists(res)) {
        res = pair.getRight();
        if (!this.repos.exists(res)) {
            throw new NotFoundException(String.format("Repository %s not found", name));
        }
    }
    return res;
}
Also used : NotFoundException(com.artipie.front.api.NotFoundException) Key(com.artipie.asto.Key)

Example 3 with Key

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

the class YamlStorages method storages.

/**
 * Returns storages yaml mapping if found.
 * @return Settings storages yaml
 */
private Optional<YamlMapping> storages() {
    final Optional<Key> key = this.key();
    Optional<YamlMapping> res = Optional.empty();
    if (key.isPresent()) {
        try {
            res = Optional.ofNullable(Yaml.createYamlInput(new String(this.blsto.value(key.get()), StandardCharsets.UTF_8)).readYamlMapping().yamlMapping(YamlStorages.STORAGES_NODE));
        } catch (final IOException err) {
            throw new UncheckedIOException(err);
        }
    }
    return res;
}
Also used : UncheckedIOException(java.io.UncheckedIOException) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Key(com.artipie.asto.Key)

Example 4 with Key

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

the class YamlStorages method add.

@Override
public void add(final String alias, final JsonObject info) {
    YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
    final Optional<YamlMapping> storages = this.storages();
    if (storages.isPresent()) {
        for (final YamlNode node : storages.get().keys()) {
            final String name = node.asScalar().value();
            builder = builder.add(name, storages.get().yamlMapping(name));
        }
    }
    builder = builder.add(alias, new Json2Yaml().apply(info.toString()));
    this.blsto.save(this.key().orElse(this.repo.<Key>map(val -> new Key.From(val, YamlStorages.YAML)).orElse(YamlStorages.YAML)), Yaml.createYamlMappingBuilder().add(YamlStorages.STORAGES_NODE, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
}
Also used : JsonObject(javax.json.JsonObject) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Collection(java.util.Collection) Yaml2Json(com.artipie.front.misc.Yaml2Json) IOException(java.io.IOException) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Yaml(com.amihaiemil.eoyaml.Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) Optional(java.util.Optional) NotFoundException(com.artipie.front.api.NotFoundException) Json2Yaml(com.artipie.front.misc.Json2Yaml) Collections(java.util.Collections) Json2Yaml(com.artipie.front.misc.Json2Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Example 5 with Key

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

the class StorageYamlConfigTest method returnsSubStorageWithCorrectPrefix.

@Test
void returnsSubStorageWithCorrectPrefix() throws IOException {
    final Key prefix = new Key.From("prefix");
    final Key path = new Key.From("some/path");
    final Key full = new Key.From(prefix, path);
    final byte[] data = "content".getBytes();
    this.config().subStorage(prefix).save(path, new Content.From(data)).join();
    MatcherAssert.assertThat(new PublisherAs(new FileStorage(this.tmp).value(full).join()).bytes().toCompletableFuture().join(), new IsEqual<>(data));
}
Also used : PublisherAs(com.artipie.asto.ext.PublisherAs) FileStorage(com.artipie.asto.fs.FileStorage) 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