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