use of com.amihaiemil.eoyaml.YamlMapping 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.YamlMapping 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.YamlMapping in project front by artipie.
the class YamlStorage method storage.
/**
* Provides a storage.
*
* @return Storage instance.
*/
public Storage storage() {
@SuppressWarnings("deprecation") final YamlMapping strict = new StrictYamlMapping(this.yaml);
final String type = strict.string("type");
final Storage storage;
if ("fs".equals(type)) {
storage = new FileStorage(Path.of(strict.string("path")));
} else if ("s3".equals(type)) {
storage = new S3Storage(this.s3Client(), strict.string("bucket"), !"false".equals(this.yaml.string("multipart")));
} else if ("etcd".equals(type)) {
storage = new EtcdStorage(YamlStorage.etcdClient(strict.yamlMapping("connection")));
} else {
throw new IllegalStateException(String.format("Unsupported storage type: '%s'", type));
}
return storage;
}
use of com.amihaiemil.eoyaml.YamlMapping in project front by artipie.
the class YamlStorages method storages.
/**
* Returns storages yaml mapping if found.
* @return Settings storages yaml
*/
private Optional<YamlMapping> storages() {
final Optional<Key> key = this.key();
Optional<YamlMapping> res = Optional.empty();
if (key.isPresent()) {
try {
res = Optional.ofNullable(Yaml.createYamlInput(new String(this.blsto.value(key.get()), StandardCharsets.UTF_8)).readYamlMapping().yamlMapping(YamlStorages.STORAGES_NODE));
} catch (final IOException err) {
throw new UncheckedIOException(err);
}
}
return res;
}
use of com.amihaiemil.eoyaml.YamlMapping 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));
}
Aggregations