Search in sources :

Example 1 with Yaml

use of com.amihaiemil.eoyaml.Yaml in project artipie by artipie.

the class DockerProxyTest method shouldFailBuildFromBadConfig.

@ParameterizedTest
@MethodSource("badConfigs")
void shouldFailBuildFromBadConfig(final String yaml) throws Exception {
    final Slice slice = dockerProxy(yaml);
    Assertions.assertThrows(RuntimeException.class, () -> slice.response(new RequestLine(RqMethod.GET, "/").toString(), Headers.EMPTY, Flowable.empty()).send((status, headers, body) -> CompletableFuture.allOf()).toCompletableFuture().join());
}
Also used : RqMethod(com.artipie.http.rq.RqMethod) RepoConfig(com.artipie.repo.RepoConfig) Headers(com.artipie.http.Headers) IsNot(org.hamcrest.core.IsNot) Slice(com.artipie.http.Slice) Permissions(com.artipie.http.auth.Permissions) CustomMatcher(org.hamcrest.CustomMatcher) RsStatus(com.artipie.http.rs.RsStatus) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) Key(com.artipie.asto.Key) Yaml(com.amihaiemil.eoyaml.Yaml) RsHasStatus(com.artipie.http.hm.RsHasStatus) RequestLine(com.artipie.http.rq.RequestLine) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Flowable(io.reactivex.Flowable) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) MethodSource(org.junit.jupiter.params.provider.MethodSource) RequestLine(com.artipie.http.rq.RequestLine) Slice(com.artipie.http.Slice) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with Yaml

use of com.amihaiemil.eoyaml.Yaml in project artipie by artipie.

the class UsersFromStorageYaml method removeUserRecord.

/**
 * Removes user record from credentials.yaml.
 * @param username User name to remove
 * @param yaml Credentials mapping
 * @return YamlMappingBuilder without removed user
 */
private static YamlMappingBuilder removeUserRecord(final String username, final YamlMapping yaml) {
    YamlMappingBuilder result = Yaml.createYamlMappingBuilder();
    final YamlMapping credentials = yaml.yamlMapping(UsersFromStorageYaml.CREDENTIALS);
    final List<YamlNode> keep = credentials.keys().stream().filter(node -> !node.asScalar().value().equals(username)).collect(Collectors.toList());
    for (final YamlNode node : keep) {
        result = result.add(node, credentials.value(node));
    }
    return result;
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Users(com.artipie.auth.Users) AuthFromYaml(com.artipie.auth.AuthFromYaml) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Yaml(com.amihaiemil.eoyaml.Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) YamlSequenceBuilder(com.amihaiemil.eoyaml.YamlSequenceBuilder) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Storage(com.artipie.asto.Storage) Locale(java.util.Locale) Optional(java.util.Optional) Authentication(com.artipie.http.auth.Authentication) Collections(java.util.Collections) CredsConfigCache(com.artipie.cache.CredsConfigCache) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Example 3 with Yaml

use of com.amihaiemil.eoyaml.Yaml 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)

Example 4 with Yaml

use of com.amihaiemil.eoyaml.Yaml in project artipie by artipie.

the class RepoPermissionsFromStorage method copyRepoSection.

/**
 * Copy `repo` section without permissions from existing yaml setting.
 * @param mapping Repo section mapping
 * @return Setting without permissions
 */
private static YamlMappingBuilder copyRepoSection(final YamlMapping mapping) {
    YamlMappingBuilder res = Yaml.createYamlMappingBuilder();
    final List<YamlNode> keep = mapping.keys().stream().filter(node -> !new SetOf<>(RepoPermissionsFromStorage.PERMS, RepoPermissionsFromStorage.INCLUDE_PATTERNS).contains(node.asScalar().value())).collect(Collectors.toList());
    for (final YamlNode node : keep) {
        res = res.add(node, mapping.value(node));
    }
    return res;
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Collection(java.util.Collection) CompletableFuture(java.util.concurrent.CompletableFuture) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Yaml(com.amihaiemil.eoyaml.Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) YamlSequenceBuilder(com.amihaiemil.eoyaml.YamlSequenceBuilder) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) ContentAsYaml(com.artipie.misc.ContentAsYaml) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Storage(com.artipie.asto.Storage) Optional(java.util.Optional) Collections(java.util.Collections) SetOf(org.cactoos.set.SetOf) YamlNode(com.amihaiemil.eoyaml.YamlNode) SetOf(org.cactoos.set.SetOf) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder)

Aggregations

Yaml (com.amihaiemil.eoyaml.Yaml)4 Key (com.artipie.asto.Key)4 Optional (java.util.Optional)4 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)3 YamlMappingBuilder (com.amihaiemil.eoyaml.YamlMappingBuilder)3 YamlNode (com.amihaiemil.eoyaml.YamlNode)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 YamlSequenceBuilder (com.amihaiemil.eoyaml.YamlSequenceBuilder)2 Content (com.artipie.asto.Content)2 Storage (com.artipie.asto.Storage)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionStage (java.util.concurrent.CompletionStage)2 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)1 AuthFromYaml (com.artipie.auth.AuthFromYaml)1 Users (com.artipie.auth.Users)1