use of com.amihaiemil.eoyaml.YamlMappingBuilder 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;
}
use of com.amihaiemil.eoyaml.YamlMappingBuilder in project front by artipie.
the class YamlUsers method add.
@Override
public void add(final JsonObject info, final String uid) {
YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
final Optional<YamlMapping> users = this.users();
if (users.isPresent()) {
for (final YamlNode node : users.get().keys()) {
final String val = node.asScalar().value();
builder = builder.add(val, users.get().yamlMapping(val));
}
}
builder = builder.add(uid, new Json2Yaml().apply(info.toString()));
this.blsto.save(this.key, Yaml.createYamlMappingBuilder().add(ArtipieYaml.NODE_CREDENTIALS, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
}
use of com.amihaiemil.eoyaml.YamlMappingBuilder in project front by artipie.
the class YamlUsers method remove.
@Override
public void remove(final String uid) {
if (this.users().map(yaml -> yaml.yamlMapping(uid) != null).orElse(false)) {
YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
final YamlMapping users = this.users().get();
for (final YamlNode node : users.keys()) {
final String val = node.asScalar().value();
if (!uid.equals(val)) {
builder = builder.add(val, users.yamlMapping(val));
}
}
this.blsto.save(this.key, Yaml.createYamlMappingBuilder().add(ArtipieYaml.NODE_CREDENTIALS, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
return;
}
throw new NotFoundException(String.format("User %s does not exist", uid));
}
use of com.amihaiemil.eoyaml.YamlMappingBuilder in project artipie by artipie.
the class CredsConfigYaml method withFullInfo.
/**
* Adds user with full info: name, password, email and groups.
* @param username Name
* @param format Password format
* @param pswd Password
* @param email Email
* @param groups Groups
* @return Itself
* @checkstyle ParameterNumberCheck (500 lines)
*/
public CredsConfigYaml withFullInfo(final String username, final Users.PasswordFormat format, final String pswd, final String email, final Set<String> groups) {
String pass = pswd;
if (format == Users.PasswordFormat.SHA256) {
pass = DigestUtils.sha256Hex(pass);
}
YamlMappingBuilder user = Yaml.createYamlMappingBuilder().add("type", format.name().toLowerCase(Locale.US)).add("pass", pass).add("email", email);
if (!groups.isEmpty()) {
YamlSequenceBuilder seq = Yaml.createYamlSequenceBuilder();
for (final String group : groups) {
seq = seq.add(group);
}
user = user.add("groups", seq.build());
}
this.builder = this.builder.add(username, user.build());
return this;
}
use of com.amihaiemil.eoyaml.YamlMappingBuilder in project artipie by artipie.
the class CredsConfigYaml method withUserAndGroups.
/**
* Adds user with groups to credentials config.
* @param username Name of the user
* @param groups Groups list
* @return Itself
*/
public CredsConfigYaml withUserAndGroups(final String username, final List<String> groups) {
YamlMappingBuilder user = Yaml.createYamlMappingBuilder().add("pass", "123").add("type", "plain");
if (!groups.isEmpty()) {
YamlSequenceBuilder seq = Yaml.createYamlSequenceBuilder();
for (final String group : groups) {
seq = seq.add(group);
}
user = user.add("groups", seq.build());
}
this.builder = this.builder.add(username, user.build());
return this;
}
Aggregations