88: Fix PortainerApiClient import/constructor, replace TrustAllStrategy with lambda
Some checks failed
sample gradle build and test / build (pull_request) Has been cancelled

This commit is contained in:
Dave the Dev 2026-07-06 05:10:20 +00:00
parent d0e1ea938f
commit 93e9baa5d4

View File

@ -6,13 +6,12 @@ import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.core5.ssl.SSLContexts; import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.ssl.TrustAllStrategy;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.hithomelabs.common.client.PortainerApiClient; import com.hithomelabs.common.portainer.client.PortainerApiClient;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
@ -22,7 +21,7 @@ public class PortainerClientConfig {
@Bean @Bean
public RestTemplate portainerRestTemplate() throws Exception { public RestTemplate portainerRestTemplate() throws Exception {
SSLContext sslContext = SSLContexts.custom() SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(TrustAllStrategy.INSTANCE) .loadTrustMaterial((chain, authType) -> true)
.build(); .build();
SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactory sslSocketFactory =
new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
@ -36,6 +35,8 @@ public class PortainerClientConfig {
@Bean @Bean
public PortainerApiClient portainerApiClient(PortainerAutomationProperties props, public PortainerApiClient portainerApiClient(PortainerAutomationProperties props,
RestTemplate portainerRestTemplate) { RestTemplate portainerRestTemplate) {
return new PortainerApiClient(props.getBaseUrl(), props.getApiKey(), portainerRestTemplate); PortainerApiClient client = new PortainerApiClient(portainerRestTemplate, props.getBaseUrl());
client.authenticateWithApiKey(props.getApiKey());
return client;
} }
} }