Search in sources :

Example 1 with AstoRepository

use of com.artipie.composer.AstoRepository in project artipie by artipie.

the class ComposerProxy method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Collection<? extends ProxyConfig.Remote> remotes = this.cfg.proxy().remotes();
    if (remotes.isEmpty()) {
        throw new IllegalArgumentException("No remotes were specified");
    }
    if (remotes.size() > 1) {
        throw new IllegalArgumentException("Only one remote is allowed");
    }
    final ProxyConfig.Remote remote = remotes.iterator().next();
    return remote.cache().map(cache -> new ComposerProxySlice(this.client, URI.create(remote.url()), new AstoRepository(this.cfg.storage()), remote.auth(), new ComposerStorageCache(new AstoRepository(cache.storage())))).orElseGet(() -> new ComposerProxySlice(this.client, URI.create(remote.url()), new AstoRepository(this.cfg.storage()), remote.auth())).response(line, headers, body);
}
Also used : ComposerProxySlice(com.artipie.composer.http.proxy.ComposerProxySlice) AstoRepository(com.artipie.composer.AstoRepository) ProxyConfig(com.artipie.repo.ProxyConfig) ComposerStorageCache(com.artipie.composer.http.proxy.ComposerStorageCache)

Example 2 with AstoRepository

use of com.artipie.composer.AstoRepository 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

AstoRepository (com.artipie.composer.AstoRepository)2 SubStorage (com.artipie.asto.SubStorage)1 LoggingAuth (com.artipie.auth.LoggingAuth)1 PhpComposer (com.artipie.composer.http.PhpComposer)1 ComposerProxySlice (com.artipie.composer.http.proxy.ComposerProxySlice)1 ComposerStorageCache (com.artipie.composer.http.proxy.ComposerStorageCache)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 FileProxy (com.artipie.file.FileProxy)1 FilesSlice (com.artipie.files.FilesSlice)1 GemSlice (com.artipie.gem.http.GemSlice)1