Search in sources :

Example 6 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class CachedCredsTest method getsOriginForSameConfigurationButDifferentStorages.

@Test
void getsOriginForSameConfigurationButDifferentStorages() {
    final String path = "_credentials.yaml";
    final Key key = new Key.From(path);
    final CredsConfigCache configs = new CachedCreds(this.cache);
    final Storage another = new InMemoryStorage();
    new TestResource(path).saveTo(this.storage);
    new BlockingStorage(another).save(key, "credentials: another val".getBytes(StandardCharsets.UTF_8));
    final YamlMapping frst = configs.credentials(this.storage, key).toCompletableFuture().join();
    final YamlMapping scnd = configs.credentials(another, key).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) TestResource(com.artipie.asto.test.TestResource) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 7 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class CachedCredsTest method getsValueFromCache.

@Test
void getsValueFromCache() {
    final Key path = new Key.From("creds.yaml");
    final CredsConfigCache configs = new CachedCreds(this.cache);
    this.storage.save(path, Content.EMPTY).join();
    final YamlMapping creds = configs.credentials(this.storage, path).toCompletableFuture().join();
    final YamlMapping same = configs.credentials(this.storage, path).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were different", creds.equals(same), new IsEqual<>(true));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(1L));
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 8 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class CachedCredsTest method getsOriginForDifferentConfigurations.

@Test
void getsOriginForDifferentConfigurations() {
    final CredsConfigCache configs = new CachedCreds(this.cache);
    final Key onekey = new Key.From("first.yml");
    final Key twokey = new Key.From("credentials.yml");
    final BlockingStorage blck = new BlockingStorage(this.storage);
    blck.save(onekey, "credentials: val".getBytes(StandardCharsets.UTF_8));
    blck.save(twokey, "credentials: another val".getBytes(StandardCharsets.UTF_8));
    final YamlMapping frst = configs.credentials(this.storage, onekey).toCompletableFuture().join();
    final YamlMapping scnd = configs.credentials(this.storage, twokey).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
Also used : BlockingStorage(com.artipie.asto.blocking.BlockingStorage) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 9 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class RepositoriesFromStorageCacheTest method readAliasesFromCache.

@Test
void readAliasesFromCache() {
    final Key alias = new Key.From("_storages.yaml");
    final Key config = new Key.From("bin.yaml");
    new TestResource(alias.string()).saveTo(this.storage);
    new BlockingStorage(this.storage).save(config, "repo:\n  storage: default".getBytes());
    final ClientSlices http = new JettyClientSlices();
    new RepositoriesFromStorage(http, this.storage).config(config.string()).toCompletableFuture().join();
    this.storage.save(alias, Content.EMPTY).join();
    MatcherAssert.assertThat(new RepositoriesFromStorage(http, this.storage).config(config.string()).toCompletableFuture().join().storageOpt().isPresent(), new IsEqual<>(true));
}
Also used : BlockingStorage(com.artipie.asto.blocking.BlockingStorage) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) Test(org.junit.jupiter.api.Test)

Example 10 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class VertxMain method startRepos.

/**
 * Start repository servers.
 *
 * @param settings Settings.
 * @param metrics Metrics.
 */
private void startRepos(final Settings settings, final Metrics metrics) {
    final Storage storage = settings.repoConfigsStorage();
    final Collection<RepoConfig> configs = storage.list(Key.ROOT).thenApply(keys -> keys.stream().map(key -> new ConfigFile(key)).filter(Predicate.not(ConfigFile::isSystem).and(ConfigFile::isYamlOrYml)).map(ConfigFile::name).map(name -> new RepositoriesFromStorage(this.http, storage).config(name)).map(stage -> stage.toCompletableFuture().join()).collect(Collectors.toList())).toCompletableFuture().join();
    for (final RepoConfig repo : configs) {
        try {
            repo.port().ifPresent(prt -> {
                final String name = new ConfigFile(repo.name()).name();
                this.listenOn(new ArtipieRepositories(this.http, settings).slice(new Key.From(name), true), metrics, prt);
                Logger.info(VertxMain.class, "Artipie repo '%s' was started on port %d", name, prt);
            });
        } catch (final IllegalStateException err) {
            Logger.error(this, "Invalid repo config file %s: %[exception]s", repo.name(), err);
        }
    }
    new QuartzScheduler(configs).start();
}
Also used : RepoConfig(com.artipie.repo.RepoConfig) Slice(com.artipie.http.Slice) Options(org.apache.commons.cli.Options) ArtipieRepositories(com.artipie.http.ArtipieRepositories) NopMetrics(com.artipie.metrics.nop.NopMetrics) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) BaseSlice(com.artipie.http.BaseSlice) Metrics(com.artipie.metrics.Metrics) Vertx(io.vertx.reactivex.core.Vertx) Storage(com.artipie.asto.Storage) ConfigFile(com.artipie.repo.ConfigFile) VertxSliceServer(com.artipie.vertx.VertxSliceServer) CommandLine(org.apache.commons.cli.CommandLine) MetricsFromConfig(com.artipie.metrics.MetricsFromConfig) Path(java.nio.file.Path) CommandLineParser(org.apache.commons.cli.CommandLineParser) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IOException(java.io.IOException) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) List(java.util.List) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) MainSlice(com.artipie.http.MainSlice) Optional(java.util.Optional) Logger(com.jcabi.log.Logger) ArtipieProperties(com.artipie.misc.ArtipieProperties) Storage(com.artipie.asto.Storage) RepoConfig(com.artipie.repo.RepoConfig) ConfigFile(com.artipie.repo.ConfigFile) ArtipieRepositories(com.artipie.http.ArtipieRepositories)

Aggregations

Key (com.artipie.asto.Key)37 Test (org.junit.jupiter.api.Test)17 Storage (com.artipie.asto.Storage)16 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)13 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)9 Content (com.artipie.asto.Content)8 Optional (java.util.Optional)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)6 PublisherAs (com.artipie.asto.ext.PublisherAs)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6 Collectors (java.util.stream.Collectors)5 TestResource (com.artipie.asto.test.TestResource)4 Response (com.artipie.http.Response)4 Slice (com.artipie.http.Slice)4 AsyncResponse (com.artipie.http.async.AsyncResponse)4 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)4 CompletionStage (java.util.concurrent.CompletionStage)4