Skip to content

Commit

Permalink
[env-manager] proxy and authorization support
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Feb 11, 2024
1 parent 824937d commit e1c810f
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
public record CentralConfiguration(
@Property(documentation = "Base repository URL.", defaultValue = "\"https://repo.maven.apache.org/maven2/\"") String base,
@Property(documentation = "Local repository path.", defaultValue = "System.getProperty(\"user.home\", \"\") + \"/.m2/repository\"") String local,
@Property(documentation = "List of GAV to register (comma separated). Such a provider can be enabled/disabled using `artifactId.enabled` property.", defaultValue = "\"org.apache.maven:apache-maven:tar.gz:bin\"") String gavs) {
@Property(documentation = "List of GAV to register (comma separated). Such a provider can be enabled/disabled using `artifactId.enabled` property.", defaultValue = "\"org.apache.maven:apache-maven:tar.gz:bin\"") String gavs,
@Property(documentation = "Headers to add if the repository is authenticated. Syntax uses HTTP one: `--central-header 'Authorization: Basic xxxxx' for example`") String header) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.yupiik.fusion.framework.build.api.event.OnEvent;
import io.yupiik.fusion.framework.build.api.order.Order;

import java.net.URI;
import java.util.Map;

@ApplicationScoped
Expand All @@ -47,5 +48,9 @@ public void onStart(@OnEvent @Order(Integer.MIN_VALUE + 100) final Start start,
default -> Map.of();
});
})));
if (configuration.header() != null && !configuration.header().isBlank()) {
final var uri = URI.create(configuration.base());
client.registerAuthentication(uri.getHost(), uri.getPort(), configuration.header());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
@RootConfiguration("github")
public record GithubConfiguration(
@Property(documentation = "Base repository URL.", defaultValue = "\"https://api.github.com\"") String base,
@Property(documentation = "Header to add to every request (authorization one for example).") String header,
@Property(documentation = "Local repository path.", defaultValue = "System.getProperty(\"user.home\", \"\") + \"/.yupiik/yem/github\"") String local) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public MinikubeGithubClient(final SingletonGithubConfiguration githubConfigurati
case "macos" -> "darwin";
default -> "linux";
} + '-' + (os.isArm() ? "arm64" : "amd64") + ".tar.gz";

if (githubConfiguration.configuration().header() != null && !githubConfiguration.configuration().header().isBlank()) {
client.registerAuthentication(base.getHost(), base.getPort(), githubConfiguration.configuration().header());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Optional<Path> resolve(final String tool, final String version) { // don'
}

@Override // warn: zip for windows often and tar.gz for linux
public CompletionStage<Archive> download(final String tool, final String version, final Path target, final ProgressListener progressListener) { // todo: checksum (x-sdkman headers) etc
public CompletionStage<Archive> download(final String tool, final String version, final Path target, final ProgressListener progressListener) { // todo: checksum (x-sdkman header) etc
if (!enabled) {
throw new IllegalStateException("SDKMan support not enabled (by configuration)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@

@RootConfiguration("http")
public record HttpConfiguration(
@Property(documentation = "Should SSL errors be ignored.", defaultValue = "false") boolean ignoreSSLErrors,
@Property(defaultValue = "false", documentation = "Force offline mode.") boolean offlineMode,
@Property(defaultValue = "10_000", documentation = "Check offline timeout. Per uri a test is done to verify the system is offline.") int offlineTimeout,
@Property(defaultValue = "4", documentation = "Number of NIO threads.") int threads,
@Property(defaultValue = "false", documentation = "Should HTTP calls be logged.") boolean log,
@Property(defaultValue = "60_000L", documentation = "Connection timeout in milliseconds.") long connectTimeout,
@Property(defaultValue = "900_000L", documentation = "Request timeout in milliseconds.") long requestTimeout,
@Property(defaultValue = "86_400_000L", documentation = "Cache validity of requests (1 day by default) in milliseconds. A negative or zero value will disable cache.") long cacheValidity,
@Property(defaultValue = "System.getProperty(\"user.home\", \"\") + \"/.yupiik/yem/cache/http\"", documentation = "Where to cache slow updates (version fetching). `none` will disable cache.") String cache
@Property(defaultValue = "System.getProperty(\"user.home\", \"\") + \"/.yupiik/yem/cache/http\"", documentation = "Where to cache slow updates (version fetching). `none` will disable cache.") String cache,
@Property(defaultValue = "new ProxyConfiguration()", documentation = "Proxy configuration if needed.") ProxyConfiguration proxy
) {
public boolean isCacheEnabled() {
return "none".equals(cache()) || cacheValidity() <= 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2020 - 2023 - Yupiik SAS - https://www.yupiik.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.yupiik.dev.shared.http;

import io.yupiik.fusion.framework.build.api.configuration.Property;

import java.util.List;

public record ProxyConfiguration(
@Property(documentation = "Proxy host. `none` means ignore.", defaultValue = "\"none\"") String host,
@Property(documentation = "Proxy port.", defaultValue = "3128") int port,
@Property(documentation = "Proxy username. `none` means ignore.", defaultValue = "\"none\"") String username,
@Property(documentation = "Proxy password. `none` means ignore.", defaultValue = "\"none\"") String password,
@Property(documentation = "Hosts to connect directly to (ignoring the proxy).", defaultValue = "java.util.List.of()") List<String> ignoredHosts) {
}

0 comments on commit e1c810f

Please sign in to comment.