use of com.artipie.asto.Storage in project front by artipie.
the class YamlStorage method storage.
/**
* Provides a storage.
*
* @return Storage instance.
*/
public Storage storage() {
@SuppressWarnings("deprecation") final YamlMapping strict = new StrictYamlMapping(this.yaml);
final String type = strict.string("type");
final Storage storage;
if ("fs".equals(type)) {
storage = new FileStorage(Path.of(strict.string("path")));
} else if ("s3".equals(type)) {
storage = new S3Storage(this.s3Client(), strict.string("bucket"), !"false".equals(this.yaml.string("multipart")));
} else if ("etcd".equals(type)) {
storage = new EtcdStorage(YamlStorage.etcdClient(strict.yamlMapping("connection")));
} else {
throw new IllegalStateException(String.format("Unsupported storage type: '%s'", type));
}
return storage;
}
use of com.artipie.asto.Storage in project artipie by artipie.
the class ConfigFileTest method valueFromStorageReturnsYamlWhenBothExist.
@Test
void valueFromStorageReturnsYamlWhenBothExist() {
final Storage storage = new InMemoryStorage();
final String yaml = String.join("", Arrays.toString(ConfigFileTest.CONTENT), "some");
this.saveByKey(storage, ".yml");
this.saveByKey(storage, ".yaml", yaml.getBytes());
MatcherAssert.assertThat(new PublisherAs(new ConfigFile(new Key.From(ConfigFileTest.NAME)).valueFrom(storage).toCompletableFuture().join()).asciiString().toCompletableFuture().join(), new IsEqual<>(yaml));
}
use of com.artipie.asto.Storage 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));
}
use of com.artipie.asto.Storage 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();
}
use of com.artipie.asto.Storage in project maven-adapter by artipie.
the class AstoMavenTest method addFilesToStorage.
private void addFilesToStorage(final Predicate<String> condition, final Key base) {
final Storage resources = new FileStorage(new TestResource("com/artipie/asto").asPath());
final BlockingStorage bsto = new BlockingStorage(resources);
bsto.list(Key.ROOT).stream().map(Key::string).filter(condition).forEach(item -> new BlockingStorage(this.storage).save(new Key.From(base, item), bsto.value(new Key.From(item))));
}
Aggregations