Search in sources :

Example 1 with YamlMappingBuilder

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

the class YamlStoragesTest method createSettings.

void createSettings(final Key key, final String... aliases) {
    YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
    for (final String alias : aliases) {
        builder = builder.add(alias, Yaml.createYamlMappingBuilder().add("type", "file").add("path", String.format("/data/%s", alias)).build());
    }
    this.blsto.save(key, Yaml.createYamlMappingBuilder().add("storages", builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
}
Also used : YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder)

Example 2 with YamlMappingBuilder

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

the class YamlRepoPermissions method add.

@Override
public void add(final String repo, final String uid, final JsonArray perms) {
    final Optional<YamlMapping> creds = this.permsYaml(repo);
    YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
    if (creds.isPresent()) {
        for (final YamlNode node : creds.get().keys()) {
            final String usr = node.asScalar().value();
            if (!uid.equals(usr)) {
                builder = builder.add(usr, creds.get().yamlSequence(usr));
            }
        }
    }
    YamlSequenceBuilder seq = Yaml.createYamlSequenceBuilder();
    for (final String item : perms.getValuesAs(JsonValue::toString)) {
        seq = seq.add(item);
    }
    builder = builder.add(uid, seq.build());
    this.updateRepoSettings(repo, builder.build());
}
Also used : YamlNode(com.amihaiemil.eoyaml.YamlNode) JsonValue(javax.json.JsonValue) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlSequenceBuilder(com.amihaiemil.eoyaml.YamlSequenceBuilder)

Example 3 with YamlMappingBuilder

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

the class YamlRepoPermissions method updateRepoSettings.

/**
 * Updates credentials section in repository settings.
 * @param repo Repository name
 * @param creds New credentials section
 */
private void updateRepoSettings(final String repo, final YamlMapping creds) {
    try {
        final YamlMapping stngs = Yaml.createYamlInput(new String(this.blsto.value(this.key(repo)), StandardCharsets.UTF_8)).readYamlMapping().yamlMapping(YamlRepoPermissions.REPO);
        YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
        for (final YamlNode node : stngs.keys()) {
            final String map = node.asScalar().value();
            if (!YamlRepoPermissions.PERMS.equals(map)) {
                builder = builder.add(map, creds.yamlSequence(map));
            }
        }
        builder = builder.add(YamlRepoPermissions.PERMS, creds);
        this.blsto.save(this.key(repo), Yaml.createYamlMappingBuilder().add(YamlRepoPermissions.REPO, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
    } catch (final IOException err) {
        throw new UncheckedIOException(err);
    }
}
Also used : YamlNode(com.amihaiemil.eoyaml.YamlNode) UncheckedIOException(java.io.UncheckedIOException) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 4 with YamlMappingBuilder

use of com.amihaiemil.eoyaml.YamlMappingBuilder 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 YamlMappingBuilder

use of com.amihaiemil.eoyaml.YamlMappingBuilder 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)

Aggregations

YamlMappingBuilder (com.amihaiemil.eoyaml.YamlMappingBuilder)12 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)8 YamlNode (com.amihaiemil.eoyaml.YamlNode)8 YamlSequenceBuilder (com.amihaiemil.eoyaml.YamlSequenceBuilder)6 Yaml (com.amihaiemil.eoyaml.Yaml)4 Key (com.artipie.asto.Key)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Collections (java.util.Collections)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 NotFoundException (com.artipie.front.api.NotFoundException)3 Json2Yaml (com.artipie.front.misc.Json2Yaml)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 Collection (java.util.Collection)3 Content (com.artipie.asto.Content)2 Storage (com.artipie.asto.Storage)2 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)2 List (java.util.List)2 CompletionStage (java.util.concurrent.CompletionStage)2