Search in sources :

Example 11 with YamlMappingBuilder

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

the class RepoPermissionsFromStorage method copyRepoSection.

/**
 * Copy `repo` section without permissions from existing yaml setting.
 * @param mapping Repo section mapping
 * @return Setting without permissions
 */
private static YamlMappingBuilder copyRepoSection(final YamlMapping mapping) {
    YamlMappingBuilder res = Yaml.createYamlMappingBuilder();
    final List<YamlNode> keep = mapping.keys().stream().filter(node -> !new SetOf<>(RepoPermissionsFromStorage.PERMS, RepoPermissionsFromStorage.INCLUDE_PATTERNS).contains(node.asScalar().value())).collect(Collectors.toList());
    for (final YamlNode node : keep) {
        res = res.add(node, mapping.value(node));
    }
    return res;
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Collection(java.util.Collection) CompletableFuture(java.util.concurrent.CompletableFuture) 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) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) YamlSequenceBuilder(com.amihaiemil.eoyaml.YamlSequenceBuilder) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) ContentAsYaml(com.artipie.misc.ContentAsYaml) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Storage(com.artipie.asto.Storage) Optional(java.util.Optional) Collections(java.util.Collections) SetOf(org.cactoos.set.SetOf) YamlNode(com.amihaiemil.eoyaml.YamlNode) SetOf(org.cactoos.set.SetOf) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder)

Example 12 with YamlMappingBuilder

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

the class UsersFromStorageYaml method add.

@Override
public CompletionStage<Void> add(final User user, final String pswd, final PasswordFormat format) {
    return this.yaml().thenCompose(yaml -> {
        YamlMappingBuilder result = UsersFromStorageYaml.removeUserRecord(user.name(), yaml);
        YamlMappingBuilder info = Yaml.createYamlMappingBuilder().add("type", format.name().toLowerCase(Locale.US)).add("pass", pswd);
        if (user.email().isPresent()) {
            info = info.add(UsersFromStorageYaml.EMAIL, user.email().get());
        }
        if (!user.groups().isEmpty()) {
            YamlSequenceBuilder seq = Yaml.createYamlSequenceBuilder();
            for (final String group : user.groups()) {
                seq = seq.add(group);
            }
            info = info.add(UsersFromStorageYaml.GROUPS, seq.build());
        }
        result = result.add(user.name(), info.build());
        return this.buildAndSaveCredentials(result);
    });
}
Also used : YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlSequenceBuilder(com.amihaiemil.eoyaml.YamlSequenceBuilder)

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