Search in sources :

Example 1 with NotFoundException

use of com.artipie.front.api.NotFoundException in project front by artipie.

the class RepoSettings method key.

/**
 * Find repository settings key by repository name and username, throws exception
 * if settings file is not found.
 * @param name Repository name
 * @param uid User id (=name)
 * @return Repository settings
 * @throws NotFoundException If such repository does not exist
 */
public Key key(final String name, final String uid) {
    final Pair<Key, Key> pair = this.keys(name, uid);
    Key res = pair.getLeft();
    if (!this.repos.exists(res)) {
        res = pair.getRight();
        if (!this.repos.exists(res)) {
            throw new NotFoundException(String.format("Repository %s not found", name));
        }
    }
    return res;
}
Also used : NotFoundException(com.artipie.front.api.NotFoundException) Key(com.artipie.asto.Key)

Example 2 with NotFoundException

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

Example 3 with NotFoundException

use of com.artipie.front.api.NotFoundException 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));
}
Also used : JsonObject(javax.json.JsonObject) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Collection(java.util.Collection) 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) ArtipieYaml(com.artipie.front.settings.ArtipieYaml) 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) YamlNode(com.amihaiemil.eoyaml.YamlNode) NotFoundException(com.artipie.front.api.NotFoundException) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Aggregations

NotFoundException (com.artipie.front.api.NotFoundException)3 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)2 YamlMappingBuilder (com.amihaiemil.eoyaml.YamlMappingBuilder)2 YamlNode (com.amihaiemil.eoyaml.YamlNode)2 Key (com.artipie.asto.Key)2 Yaml (com.amihaiemil.eoyaml.Yaml)1 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)1 Json2Yaml (com.artipie.front.misc.Json2Yaml)1 ArtipieYaml (com.artipie.front.settings.ArtipieYaml)1 IOException (java.io.IOException)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 JsonObject (javax.json.JsonObject)1