Skip to content

Commit

Permalink
Merge pull request #2450 from yma96/master
Browse files Browse the repository at this point in the history
Support global http proxy config when during http jobs
  • Loading branch information
yma96 authored Aug 12, 2024
2 parents 2d9cca2 + 348b3ba commit 05ebfee
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private void initKojiClient( String exchangeName, boolean verifyArtifacts )
GalleyCore galley = new GalleyCoreBuilder(
new FileCacheProviderFactory( temp.newFolder( "cache" ) ) ).withEnabledTransports(
new HttpClientTransport( new HttpImpl( new org.commonjava.maven.galley.auth.MemoryPasswordManager() ),
new IndyObjectMapper( true ), new GlobalHttpConfiguration(), null, null ) ).build();
new IndyObjectMapper( true ), new GlobalHttpConfiguration().getGlobalProxyConfig(), null, null ) ).build();

WeftExecutorService rescanService =
new PoolWeftExecutorService( "test-rescan-executor", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false,null, null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ protected void initBaseTestConfig( CoreServerFixture fixture )

writeConfigFile( "conf.d/folo.conf", "[folo]\nfolo.cassandra=true" + "\nfolo.cassandra.keyspace=folo"
+ "\ntrack.group.content=True" );
writeConfigFile( "conf.d/http.conf", "[http]\nproxy.host=proxy.com" + "\nproxy.port=3128" );

if ( isSchedulerEnabled() )
{
Expand Down
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,17 +38,19 @@
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.commonjava.maven.galley.transport.htcli.conf.GlobalProxyConfig;
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;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.fail;

Expand Down
6 changes: 4 additions & 2 deletions subsys/http/src/main/conf/http.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[http]
enabled=true
##
## Below are for default site config
##
Expand All @@ -10,8 +11,9 @@
#user=

## Proxy settings
#proxy.host=http://myproxy.com
#proxy.port=8001
#proxy.host=myproxy.com
#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
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.commonjava.indy.subsys.http;

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

import javax.enterprise.context.ApplicationScoped;
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 IndyGlobalProxyConfigProducer
{
private final Logger logger = LoggerFactory.getLogger( getClass() );

@Inject
private IndySiteConfigLookup siteConfigLookup;

private GlobalProxyConfig globalProxyConfig;

private SiteConfig defaultSiteConfig;

@Produces
public GlobalProxyConfig getGlobalProxyConfig()
{
defaultSiteConfig = siteConfigLookup.lookup( DEFAULT_SITE );
if ( defaultSiteConfig != null && defaultSiteConfig.getProxyHost() != null )
{
setupGlobalProxyConfig();
}
return globalProxyConfig;
}

private void setupGlobalProxyConfig()
{
logger.debug( "Setup global proxy config, host: {}", defaultSiteConfig.getProxyHost() );
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 );
}
}
}
globalProxyConfig = new GlobalProxyConfig()
{
@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;
}
};
}
}
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
5 changes: 3 additions & 2 deletions subsys/http/src/main/resources/default-http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#user=

## Proxy settings
#proxy.host=http://myproxy.com
#proxy.port=8001
#proxy.host=myproxy.com
#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 05ebfee

Please sign in to comment.