use of com.artipie.front.misc.Json2Yaml 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.artipie.front.misc.Json2Yaml in project front by artipie.
the class PutRepository method handle.
@Override
@SuppressWarnings("PMD.OnlyOneReturn")
public Object handle(final Request request, final Response response) {
final String param = GetRepository.NAME_PARAM.parse(request);
final String uid = RequestAttr.Standard.USER_ID.readOrThrow(request);
if (this.stn.exists(param, uid)) {
response.status(HttpStatus.CONFLICT_409);
return String.format("Repository %s already exists", param);
}
final JsonObject body = Json.createReader(new StringReader(request.body())).readObject();
final JsonObject repo = body.getJsonObject("repo");
if (repo == null) {
response.status(HttpStatus.BAD_REQUEST_400);
return "Section `repo` is required";
}
if (!repo.containsKey("type")) {
response.status(HttpStatus.BAD_REQUEST_400);
return "Repository type is required";
}
if (!repo.containsKey("storage")) {
response.status(HttpStatus.BAD_REQUEST_400);
return "Repository storage is required";
}
this.stn.save(param, uid, new Json2Yaml().apply(body.toString()).toString().getBytes(StandardCharsets.UTF_8));
response.status(HttpStatus.CREATED_201);
return null;
}
use of com.artipie.front.misc.Json2Yaml 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));
}
Aggregations