use of com.artipie.conda.CondaConfig 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));
}
Aggregations