88: Add SSL-friendly Portainer API client config

This commit is contained in:
Dave the Dev 2026-07-06 05:02:15 +00:00
parent cf24922bb4
commit 5ea62d6baf

View File

@ -0,0 +1,41 @@
package com.hithomelabs.portainer.config;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
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.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import com.hithomelabs.common.client.PortainerApiClient;
import javax.net.ssl.SSLContext;
@Configuration
public class PortainerClientConfig {
@Bean
public RestTemplate portainerRestTemplate() throws Exception {
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(TrustAllStrategy.INSTANCE)
.build();
SSLConnectionSocketFactory sslSocketFactory =
new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(sslSocketFactory)
.build();
return new RestTemplate(new HttpComponentsClientHttpRequestFactory(
HttpClients.custom().setConnectionManager(cm).build()));
}
@Bean
public PortainerApiClient portainerApiClient(PortainerAutomationProperties props,
RestTemplate portainerRestTemplate) {
return new PortainerApiClient(props.getBaseUrl(), props.getApiKey(), portainerRestTemplate);
}
}