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;
}
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);
});
}
Aggregations