Search in sources :

Example 6 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project front by artipie.

the class YamlStorages method remove.

@Override
public void remove(final String alias) {
    final Optional<YamlMapping> storages = this.storages();
    if (storages.isPresent() && storages.get().value(alias) != null) {
        YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
        for (final YamlNode node : storages.get().keys()) {
            final String name = node.asScalar().value();
            if (!alias.equals(name)) {
                builder = builder.add(name, storages.get().yamlMapping(name));
            }
        }
        this.blsto.save(this.key().get(), Yaml.createYamlMappingBuilder().add(YamlStorages.STORAGES_NODE, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
        return;
    }
    throw new NotFoundException(String.format("Storage alias %s does not exist", alias));
}
Also used : YamlNode(com.amihaiemil.eoyaml.YamlNode) NotFoundException(com.artipie.front.api.NotFoundException) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder)

Example 7 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.

the class CachedCredsTest method getsOriginForSameConfigurationButDifferentStorages.

@Test
void getsOriginForSameConfigurationButDifferentStorages() {
    final String path = "_credentials.yaml";
    final Key key = new Key.From(path);
    final CredsConfigCache configs = new CachedCreds(this.cache);
    final Storage another = new InMemoryStorage();
    new TestResource(path).saveTo(this.storage);
    new BlockingStorage(another).save(key, "credentials: another val".getBytes(StandardCharsets.UTF_8));
    final YamlMapping frst = configs.credentials(this.storage, key).toCompletableFuture().join();
    final YamlMapping scnd = configs.credentials(another, key).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) TestResource(com.artipie.asto.test.TestResource) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 8 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.

the class CachedCredsTest method getsValueFromCache.

@Test
void getsValueFromCache() {
    final Key path = new Key.From("creds.yaml");
    final CredsConfigCache configs = new CachedCreds(this.cache);
    this.storage.save(path, Content.EMPTY).join();
    final YamlMapping creds = configs.credentials(this.storage, path).toCompletableFuture().join();
    final YamlMapping same = configs.credentials(this.storage, path).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were different", creds.equals(same), new IsEqual<>(true));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(1L));
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 9 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.

the class CachedCredsTest method getsOriginForDifferentConfigurations.

@Test
void getsOriginForDifferentConfigurations() {
    final CredsConfigCache configs = new CachedCreds(this.cache);
    final Key onekey = new Key.From("first.yml");
    final Key twokey = new Key.From("credentials.yml");
    final BlockingStorage blck = new BlockingStorage(this.storage);
    blck.save(onekey, "credentials: val".getBytes(StandardCharsets.UTF_8));
    blck.save(twokey, "credentials: another val".getBytes(StandardCharsets.UTF_8));
    final YamlMapping frst = configs.credentials(this.storage, onekey).toCompletableFuture().join();
    final YamlMapping scnd = configs.credentials(this.storage, twokey).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
Also used : BlockingStorage(com.artipie.asto.blocking.BlockingStorage) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 10 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.

the class UsersFromStorageYaml method removeUserRecord.

/**
 * Removes user record from credentials.yaml.
 * @param username User name to remove
 * @param yaml Credentials mapping
 * @return YamlMappingBuilder without removed user
 */
private static YamlMappingBuilder removeUserRecord(final String username, final YamlMapping yaml) {
    YamlMappingBuilder result = Yaml.createYamlMappingBuilder();
    final YamlMapping credentials = yaml.yamlMapping(UsersFromStorageYaml.CREDENTIALS);
    final List<YamlNode> keep = credentials.keys().stream().filter(node -> !node.asScalar().value().equals(username)).collect(Collectors.toList());
    for (final YamlNode node : keep) {
        result = result.add(node, credentials.value(node));
    }
    return result;
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Users(com.artipie.auth.Users) AuthFromYaml(com.artipie.auth.AuthFromYaml) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Yaml(com.amihaiemil.eoyaml.Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) YamlSequenceBuilder(com.amihaiemil.eoyaml.YamlSequenceBuilder) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Storage(com.artipie.asto.Storage) Locale(java.util.Locale) Optional(java.util.Optional) Authentication(com.artipie.http.auth.Authentication) Collections(java.util.Collections) CredsConfigCache(com.artipie.cache.CredsConfigCache) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Aggregations

YamlMapping (com.amihaiemil.eoyaml.YamlMapping)23 YamlNode (com.amihaiemil.eoyaml.YamlNode)10 Key (com.artipie.asto.Key)9 YamlMappingBuilder (com.amihaiemil.eoyaml.YamlMappingBuilder)8 Storage (com.artipie.asto.Storage)7 Collectors (java.util.stream.Collectors)6 IOException (java.io.IOException)5 UncheckedIOException (java.io.UncheckedIOException)5 StrictYamlMapping (com.amihaiemil.eoyaml.StrictYamlMapping)4 Yaml (com.amihaiemil.eoyaml.Yaml)4 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)4 EtcdStorage (com.artipie.asto.etcd.EtcdStorage)4 FileStorage (com.artipie.asto.fs.FileStorage)4 S3Storage (com.artipie.asto.s3.S3Storage)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Collections (java.util.Collections)4 Optional (java.util.Optional)4 YamlSequenceBuilder (com.amihaiemil.eoyaml.YamlSequenceBuilder)3 NotFoundException (com.artipie.front.api.NotFoundException)3 Json2Yaml (com.artipie.front.misc.Json2Yaml)3