Skip to content

Commit

Permalink
Support global http proxy config when during http jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Aug 8, 2024
1 parent 2d9cca2 commit 44b6a49
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
<indyModelVersion>1.5</indyModelVersion>
<indyClientVersion>3.4.0-SNAPSHOT</indyClientVersion>
<atlasVersion>1.1.1</atlasVersion>
<galleyVersion>1.16</galleyVersion>
<galleyVersion>1.17-SNAPSHOT</galleyVersion>
<weftVersion>1.24</weftVersion>
<webdavVersion>3.2.1</webdavVersion>
<!-- TODO: partyline is still needed for standalone mode, may be removed in future -->
<partylineVersion>1.16</partylineVersion>
<kojijiVersion>2.13</kojijiVersion>
<rwxVersion>2.3</rwxVersion>
<jhttpcVersion>1.12</jhttpcVersion>
<jhttpcVersion>1.14-SNAPSHOT</jhttpcVersion>
<httpTestserverVersion>1.5.1</httpTestserverVersion>
<propulsorVersion>1.5</propulsorVersion>
<auditQueryVersion>0.13.1</auditQueryVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
import org.commonjava.indy.action.UserLifecycleManager;
import org.commonjava.indy.action.fixture.AlternativeUserLifecycleManager;
import org.commonjava.indy.content.IndyPathGenerator;
import org.commonjava.indy.data.ArtifactStoreValidateData;
import org.commonjava.indy.data.NoOpStoreEventDispatcher;
import org.commonjava.indy.data.StoreDataManager;
import org.commonjava.indy.data.StoreEventDispatcher;
import org.commonjava.indy.data.StoreValidator;
import org.commonjava.indy.db.common.inject.Standalone;
import org.commonjava.indy.mem.data.MemoryStoreDataManager;
import org.commonjava.indy.model.core.ArtifactStore;
import org.commonjava.indy.model.core.io.IndyObjectMapper;
import org.commonjava.maven.galley.cache.FileCacheProvider;
import org.commonjava.maven.galley.config.TransportManagerConfig;
Expand All @@ -40,13 +38,12 @@
import org.commonjava.maven.galley.spi.event.FileEventManager;
import org.commonjava.maven.galley.spi.nfc.NotFoundCache;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
import org.commonjava.o11yphant.metrics.sli.GoldenSignalsMetricSet;
import org.commonjava.o11yphant.trace.TracerConfiguration;
import org.junit.rules.TemporaryFolder;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
Expand Down Expand Up @@ -190,6 +187,7 @@ public WeftConfig getWeftConfig()
}

@Produces
@Alternative
public GlobalHttpConfiguration getGlobalHttpConfiguration()
{
return globalHttpConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package org.commonjava.indy.subsys.http;

import org.commonjava.indy.subsys.http.conf.IndyHttpConfig;
import org.commonjava.indy.subsys.http.util.IndySiteConfigLookup;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
import org.commonjava.maven.galley.transport.htcli.conf.ProxyConfig;
import org.commonjava.util.jhttpc.model.SiteConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.commonjava.indy.subsys.http.conf.IndyHttpConfig.DEFAULT_SITE;

@ApplicationScoped
public class IndyGlobalHttpConfigurationProducer
{
private final Logger logger = LoggerFactory.getLogger( getClass() );

@Inject
private IndyHttpConfig config;

@Inject
private IndySiteConfigLookup siteConfigLookup;

private GlobalHttpConfiguration globalHttpConfiguration;

private SiteConfig defaultSiteConfig;

@Produces
@Default
public GlobalHttpConfiguration getGlobalHttpConfiguration()
{
defaultSiteConfig = siteConfigLookup.lookup( DEFAULT_SITE );
if ( defaultSiteConfig != null && defaultSiteConfig.getProxyHost() != null )
{
setUpGlobalHttpConfiguration();
}
return globalHttpConfiguration;
}

private void setUpGlobalHttpConfiguration()
{
logger.info( "Setup global http configuration" );
final String allowTypes = defaultSiteConfig.getProxyAllowHttpJobTypes();
final List<String> list = new ArrayList<>();
if ( isNotBlank( allowTypes ) )
{
String[] toks = allowTypes.split( "," );
for ( String s : toks )
{
s = s.trim();
if ( isNotBlank( s ) )
{
list.add( s );
}
}
}
ProxyConfig proxyConfig = new ProxyConfig()
{
@Override
public String getHost()
{
return defaultSiteConfig.getProxyHost();
}

@Override
public int getPort()
{
return defaultSiteConfig.getProxyPort();
}

@Override
public String getUser()
{
return defaultSiteConfig.getProxyUser();
}

@Override
public List<String> getAllowHttpJobTypes()
{
return list;
}
};
globalHttpConfiguration = new GlobalHttpConfiguration( proxyConfig );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class IndyHttpConfig

public static final String PROXY_USER = "proxy.user";

public static final String PROXY_ALLOW_HTTP_JOB_TYPES = "proxy.allow.http.job.types";

public static final String TRUST_TYPE = "trust.type";

public static final String KEY_CERT_PEM = "key.cert.pem";
Expand Down Expand Up @@ -102,6 +104,7 @@ public void sectionComplete( String name ) throws ConfigurationException
case PROXY_HOST:
case PROXY_PORT:
case PROXY_USER:
case PROXY_ALLOW_HTTP_JOB_TYPES:
case TRUST_TYPE:
case KEY_CERT_PEM:
case KEY_CERT_PEM_PATH:
Expand Down Expand Up @@ -221,6 +224,9 @@ private void withEntry( SiteConfigBuilder siteConfigBuilder, String realKey, Str
case PROXY_USER:
siteConfigBuilder.withProxyUser( value );
break;
case PROXY_ALLOW_HTTP_JOB_TYPES:
siteConfigBuilder.withProxyAllowHttpJobTypes( value );
break;
case TRUST_TYPE:
siteConfigBuilder.withTrustType( SiteTrustType.getType( value ) );
break;
Expand Down
3 changes: 2 additions & 1 deletion subsys/http/src/main/resources/default-http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

## Proxy settings
#proxy.host=http://myproxy.com
#proxy.port=8001
#proxy.port=3128
#proxy.allow.http.job.types=download,existence,listing
#proxy.user=proxy-user

## Trust type. Value could be either default or self-signed
Expand Down

0 comments on commit 44b6a49

Please sign in to comment.