Search in sources :

Example 1 with ClientSlices

use of com.artipie.http.client.ClientSlices 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 2 with ClientSlices

use of com.artipie.http.client.ClientSlices in project artipie by artipie.

the class RepositoriesFromStorageCacheTest method readConfigFromCacheAfterSavingNewValueInStorage.

@Test
void readConfigFromCacheAfterSavingNewValueInStorage() {
    final Key key = new Key.From("some-repo.yaml");
    final byte[] old = "some: data".getBytes();
    final byte[] upd = "some: new data".getBytes();
    new BlockingStorage(this.storage).save(key, old);
    final ClientSlices http = new JettyClientSlices();
    new RepositoriesFromStorage(http, this.storage).config(key.string()).toCompletableFuture().join();
    new BlockingStorage(this.storage).save(key, upd);
    MatcherAssert.assertThat(new RepositoriesFromStorage(http, this.storage).config(key.string()).toCompletableFuture().join().toString(), new IsEqual<>(new String(old)));
}
Also used : BlockingStorage(com.artipie.asto.blocking.BlockingStorage) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) 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 3 with ClientSlices

use of com.artipie.http.client.ClientSlices in project artipie by artipie.

the class SliceFromConfig method build.

/**
 * Find a slice implementation for config.
 *
 * @param http HTTP client
 * @param settings Artipie settings
 * @param auth Authentication
 * @param cfg Repository config
 * @param aliases Storage aliases
 * @param standalone Standalone flag
 * @return Slice completionStage
 * @checkstyle LineLengthCheck (150 lines)
 * @checkstyle ExecutableStatementCountCheck (100 lines)
 * @checkstyle JavaNCSSCheck (500 lines)
 * @checkstyle MethodLengthCheck (500 lines)
 */
@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.ExcessiveMethodLength", "PMD.AvoidDuplicateLiterals", "PMD.NcssCount" })
static Slice build(final ClientSlices http, final Settings settings, final Authentication auth, final RepoConfig cfg, final StorageAliases aliases, final boolean standalone) {
    final Slice slice;
    final Permissions permissions = new LoggingPermissions(cfg.permissions().orElse(Permissions.FREE));
    switch(cfg.type()) {
        case "file":
            slice = trimIfNotStandalone(settings, standalone, new FilesSlice(cfg.storage(), permissions, auth));
            break;
        case "file-proxy":
            slice = trimIfNotStandalone(settings, standalone, new FileProxy(http, cfg));
            break;
        case "npm":
            slice = trimIfNotStandalone(settings, standalone, new NpmSlice(cfg.url(), cfg.storage(), permissions, auth));
            break;
        case "gem":
            slice = trimIfNotStandalone(settings, standalone, new GemSlice(cfg.storage()));
            break;
        case "helm":
            slice = trimIfNotStandalone(settings, standalone, new HelmSlice(cfg.storage(), cfg.path(), permissions, auth));
            break;
        case "rpm":
            slice = trimIfNotStandalone(settings, standalone, new RpmSlice(cfg.storage(), permissions, auth, new com.artipie.rpm.RepoConfig.FromYaml(cfg.settings())));
            break;
        case "php":
            slice = trimIfNotStandalone(settings, standalone, new PhpComposer(new AstoRepository(cfg.storage(), Optional.of(cfg.url().toString()))));
            break;
        case "php-proxy":
            slice = trimIfNotStandalone(settings, standalone, new ComposerProxy(http, cfg));
            break;
        case "nuget":
            slice = trimIfNotStandalone(settings, standalone, new NuGet(cfg.url(), new com.artipie.nuget.AstoRepository(cfg.storage()), permissions, auth));
            break;
        case "maven":
            slice = trimIfNotStandalone(settings, standalone, new MavenSlice(cfg.storage(), permissions, auth));
            break;
        case "maven-proxy":
            slice = trimIfNotStandalone(settings, standalone, new MavenProxy(http, cfg));
            break;
        case "maven-group":
            slice = trimIfNotStandalone(settings, standalone, new GroupSlice(cfg.settings().orElseThrow().yamlSequence("repositories").values().stream().map(node -> node.asScalar().value()).map(name -> new AsyncSlice(new RepositoriesFromStorage(http, settings.storage()).config(name).thenApply(sub -> new SliceFromConfig(http, settings, sub, aliases, standalone)))).collect(Collectors.toList())));
            break;
        case "go":
            slice = trimIfNotStandalone(settings, standalone, new GoSlice(cfg.storage(), permissions, auth));
            break;
        case "npm-proxy":
            slice = new NpmProxySlice(cfg.path(), new NpmProxy(URI.create(cfg.settings().orElseThrow().yamlMapping("remote").string("url")), cfg.storage(), http));
            break;
        case "pypi":
            slice = trimIfNotStandalone(settings, standalone, new PySlice(cfg.storage(), permissions, auth));
            break;
        case "pypi-proxy":
            slice = trimIfNotStandalone(settings, standalone, new PypiProxy(http, cfg));
            break;
        case "docker":
            final Docker docker = new AstoDocker(new SubStorage(RegistryRoot.V2, cfg.storage()));
            if (standalone) {
                slice = new DockerSlice(docker, new DockerPermissions(permissions), new BasicAuthScheme(auth));
            } else {
                slice = new DockerRoutingSlice.Reverted(new DockerSlice(new TrimmedDocker(docker, cfg.name()), new DockerPermissions(permissions), new BasicAuthScheme(auth)));
            }
            break;
        case "docker-proxy":
            slice = new DockerProxy(http, standalone, cfg, permissions, auth);
            break;
        case "deb":
            slice = trimIfNotStandalone(settings, standalone, new DebianSlice(cfg.storage(), permissions, auth, new Config.FromYaml(cfg.name(), cfg.settings(), settings.storage())));
            break;
        case "conda":
            slice = trimIfNotStandalone(settings, standalone, new CondaSlice(cfg.storage(), permissions, auth, cfg.url().toString(), new CondaConfig(cfg.settings()).authTokenTtl()));
            break;
        default:
            throw new IllegalStateException(String.format("Unsupported repository type '%s", cfg.type()));
    }
    return new ContinueSlice(cfg.contentLengthMax().<Slice>map(limit -> new ContentLengthRestriction(slice, limit)).orElse(slice));
}
Also used : Config(com.artipie.debian.Config) RepoConfig(com.artipie.repo.RepoConfig) AstoDocker(com.artipie.docker.asto.AstoDocker) Slice(com.artipie.http.Slice) Permissions(com.artipie.http.auth.Permissions) GoSlice(com.artipie.http.GoSlice) GroupSlice(com.artipie.http.group.GroupSlice) DockerSlice(com.artipie.docker.http.DockerSlice) HelmSlice(com.artipie.helm.http.HelmSlice) ComposerProxy(com.artipie.php.ComposerProxy) RegistryRoot(com.artipie.docker.asto.RegistryRoot) DockerProxy(com.artipie.docker.DockerProxy) GemSlice(com.artipie.gem.http.GemSlice) MavenProxy(com.artipie.maven.MavenProxy) DockerPermissions(com.artipie.docker.DockerPermissions) TrimPathSlice(com.artipie.http.slice.TrimPathSlice) PhpComposer(com.artipie.composer.http.PhpComposer) URI(java.net.URI) FilesSlice(com.artipie.files.FilesSlice) Authentication(com.artipie.http.auth.Authentication) DockerRoutingSlice(com.artipie.http.DockerRoutingSlice) PypiProxy(com.artipie.pypi.PypiProxy) CondaConfig(com.artipie.conda.CondaConfig) SubStorage(com.artipie.asto.SubStorage) BasicAuthScheme(com.artipie.http.auth.BasicAuthScheme) NpmSlice(com.artipie.npm.http.NpmSlice) AsyncSlice(com.artipie.http.async.AsyncSlice) NpmProxy(com.artipie.npm.proxy.NpmProxy) CondaSlice(com.artipie.conda.http.CondaSlice) Docker(com.artipie.docker.Docker) Collectors(java.util.stream.Collectors) LoggingAuth(com.artipie.auth.LoggingAuth) DebianSlice(com.artipie.debian.http.DebianSlice) PySlice(com.artipie.pypi.http.PySlice) TrimmedDocker(com.artipie.docker.http.TrimmedDocker) NuGet(com.artipie.nuget.http.NuGet) ClientSlices(com.artipie.http.client.ClientSlices) MavenSlice(com.artipie.maven.http.MavenSlice) NpmProxySlice(com.artipie.npm.proxy.http.NpmProxySlice) FileProxy(com.artipie.file.FileProxy) Optional(java.util.Optional) AstoRepository(com.artipie.composer.AstoRepository) RpmSlice(com.artipie.rpm.http.RpmSlice) FilesSlice(com.artipie.files.FilesSlice) SubStorage(com.artipie.asto.SubStorage) NpmProxy(com.artipie.npm.proxy.NpmProxy) DockerPermissions(com.artipie.docker.DockerPermissions) AstoDocker(com.artipie.docker.asto.AstoDocker) Docker(com.artipie.docker.Docker) TrimmedDocker(com.artipie.docker.http.TrimmedDocker) Permissions(com.artipie.http.auth.Permissions) DockerPermissions(com.artipie.docker.DockerPermissions) AstoRepository(com.artipie.composer.AstoRepository) FileProxy(com.artipie.file.FileProxy) BasicAuthScheme(com.artipie.http.auth.BasicAuthScheme) NpmSlice(com.artipie.npm.http.NpmSlice) RpmSlice(com.artipie.rpm.http.RpmSlice) DockerRoutingSlice(com.artipie.http.DockerRoutingSlice) DockerProxy(com.artipie.docker.DockerProxy) CondaSlice(com.artipie.conda.http.CondaSlice) GemSlice(com.artipie.gem.http.GemSlice) ComposerProxy(com.artipie.php.ComposerProxy) HelmSlice(com.artipie.helm.http.HelmSlice) MavenProxy(com.artipie.maven.MavenProxy) Slice(com.artipie.http.Slice) GoSlice(com.artipie.http.GoSlice) GroupSlice(com.artipie.http.group.GroupSlice) DockerSlice(com.artipie.docker.http.DockerSlice) HelmSlice(com.artipie.helm.http.HelmSlice) GemSlice(com.artipie.gem.http.GemSlice) TrimPathSlice(com.artipie.http.slice.TrimPathSlice) FilesSlice(com.artipie.files.FilesSlice) DockerRoutingSlice(com.artipie.http.DockerRoutingSlice) NpmSlice(com.artipie.npm.http.NpmSlice) AsyncSlice(com.artipie.http.async.AsyncSlice) CondaSlice(com.artipie.conda.http.CondaSlice) DebianSlice(com.artipie.debian.http.DebianSlice) PySlice(com.artipie.pypi.http.PySlice) MavenSlice(com.artipie.maven.http.MavenSlice) NpmProxySlice(com.artipie.npm.proxy.http.NpmProxySlice) RpmSlice(com.artipie.rpm.http.RpmSlice) DebianSlice(com.artipie.debian.http.DebianSlice) Config(com.artipie.debian.Config) RepoConfig(com.artipie.repo.RepoConfig) CondaConfig(com.artipie.conda.CondaConfig) PhpComposer(com.artipie.composer.http.PhpComposer) NpmProxySlice(com.artipie.npm.proxy.http.NpmProxySlice) PySlice(com.artipie.pypi.http.PySlice) AstoDocker(com.artipie.docker.asto.AstoDocker) GoSlice(com.artipie.http.GoSlice) TrimmedDocker(com.artipie.docker.http.TrimmedDocker) GroupSlice(com.artipie.http.group.GroupSlice) AsyncSlice(com.artipie.http.async.AsyncSlice) NuGet(com.artipie.nuget.http.NuGet) CondaConfig(com.artipie.conda.CondaConfig) RepoConfig(com.artipie.repo.RepoConfig) PypiProxy(com.artipie.pypi.PypiProxy) MavenSlice(com.artipie.maven.http.MavenSlice) DockerSlice(com.artipie.docker.http.DockerSlice)

Aggregations

ClientSlices (com.artipie.http.client.ClientSlices)3 Key (com.artipie.asto.Key)2 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)2 JettyClientSlices (com.artipie.http.client.jetty.JettyClientSlices)2 SubStorage (com.artipie.asto.SubStorage)1 TestResource (com.artipie.asto.test.TestResource)1 LoggingAuth (com.artipie.auth.LoggingAuth)1 AstoRepository (com.artipie.composer.AstoRepository)1 PhpComposer (com.artipie.composer.http.PhpComposer)1 CondaConfig (com.artipie.conda.CondaConfig)1 CondaSlice (com.artipie.conda.http.CondaSlice)1 Config (com.artipie.debian.Config)1 DebianSlice (com.artipie.debian.http.DebianSlice)1 Docker (com.artipie.docker.Docker)1 DockerPermissions (com.artipie.docker.DockerPermissions)1 DockerProxy (com.artipie.docker.DockerProxy)1 AstoDocker (com.artipie.docker.asto.AstoDocker)1 RegistryRoot (com.artipie.docker.asto.RegistryRoot)1 DockerSlice (com.artipie.docker.http.DockerSlice)1 TrimmedDocker (com.artipie.docker.http.TrimmedDocker)1