Search in sources :

Example 1 with Json2Yaml

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));
}
Also used : JsonObject(javax.json.JsonObject) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Collection(java.util.Collection) Yaml2Json(com.artipie.front.misc.Yaml2Json) IOException(java.io.IOException) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Yaml(com.amihaiemil.eoyaml.Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) Optional(java.util.Optional) NotFoundException(com.artipie.front.api.NotFoundException) Json2Yaml(com.artipie.front.misc.Json2Yaml) Collections(java.util.Collections) Json2Yaml(com.artipie.front.misc.Json2Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Example 2 with Json2Yaml

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;
}
Also used : Json2Yaml(com.artipie.front.misc.Json2Yaml) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject)

Example 3 with Json2Yaml

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));
}
Also used : Json2Yaml(com.artipie.front.misc.Json2Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Aggregations

Json2Yaml (com.artipie.front.misc.Json2Yaml)3 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)2 YamlMappingBuilder (com.amihaiemil.eoyaml.YamlMappingBuilder)2 YamlNode (com.amihaiemil.eoyaml.YamlNode)2 JsonObject (javax.json.JsonObject)2 Yaml (com.amihaiemil.eoyaml.Yaml)1 Key (com.artipie.asto.Key)1 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)1 NotFoundException (com.artipie.front.api.NotFoundException)1 Yaml2Json (com.artipie.front.misc.Yaml2Json)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 UncheckedIOException (java.io.UncheckedIOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1