Search in sources :

Example 1 with SiteConfig

use of org.commonjava.util.jhttpc.model.SiteConfig in project galley by Commonjava.

the class HttpImpl method createClient.

@Override
public CloseableHttpClient createClient(final HttpLocation location) throws GalleyException {
    try {
        if (location != null) {
            locationLookup.register(location);
            int maxConnections = LocationUtils.getMaxConnections(location);
            SiteConfigBuilder configBuilder = new SiteConfigBuilder(location.getName(), location.getUri());
            configBuilder.withAttributes(location.getAttributes()).withKeyCertPem(location.getKeyCertPem()).withServerCertPem(location.getServerCertPem()).withProxyHost(location.getProxyHost()).withProxyPort(location.getProxyPort()).withProxyUser(location.getProxyUser()).withRequestTimeoutSeconds(LocationUtils.getTimeoutSeconds(location)).withUser(location.getUser()).withMaxConnections(maxConnections);
            if (location.getTrustType() != null) {
                configBuilder.withTrustType(SiteTrustType.getType(location.getTrustType().name()));
            }
            SiteConfig config = configBuilder.build();
            return httpFactory.createClient(config);
        } else {
            return httpFactory.createClient();
        }
    } catch (JHttpCException e) {
        throw new TransferLocationException(location, "Failed to initialize http client: %s", e, e.getMessage());
    }
}
Also used : SiteConfigBuilder(org.commonjava.util.jhttpc.model.SiteConfigBuilder) SiteConfig(org.commonjava.util.jhttpc.model.SiteConfig) JHttpCException(org.commonjava.util.jhttpc.JHttpCException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException)

Example 2 with SiteConfig

use of org.commonjava.util.jhttpc.model.SiteConfig in project indy by Commonjava.

the class IndySiteConfigLookup method toSiteConfig.

private SiteConfig toSiteConfig(RemoteRepository repository) {
    SiteConfigBuilder builder = new SiteConfigBuilder(repository.getName(), repository.getUrl());
    logger.debug("Adding server PEM to site config for: {}\n{}", repository.getKey(), repository.getServerCertPem());
    builder.withKeyCertPem(repository.getKeyCertPem()).withProxyHost(repository.getProxyHost()).withProxyPort(repository.getProxyPort()).withProxyUser(repository.getProxyUser()).withRequestTimeoutSeconds(repository.getTimeoutSeconds()).withServerCertPem(repository.getServerCertPem()).withTrustType(SiteTrustType.TRUST_SELF_SIGNED).withUser(repository.getUser());
    SiteConfig config = builder.build();
    logger.debug("Got server PEM in site config:\n{}", config.getServerCertPem());
    config.setAttribute(PASSWORD_PREFIX + KEY.name(), repository.getKeyPassword());
    config.setAttribute(PASSWORD_PREFIX + USER.name(), repository.getPassword());
    config.setAttribute(PASSWORD_PREFIX + PROXY.name(), repository.getProxyPassword());
    return config;
}
Also used : SiteConfigBuilder(org.commonjava.util.jhttpc.model.SiteConfigBuilder) SiteConfig(org.commonjava.util.jhttpc.model.SiteConfig)

Example 3 with SiteConfig

use of org.commonjava.util.jhttpc.model.SiteConfig in project indy by Commonjava.

the class IndySiteConfigLookupTest method checkHttpConfigLoad.

@Test
public void checkHttpConfigLoad() throws Exception {
    File pemFile = testFolder.newFile("keycloak.pem");
    final String _URI = "http://site.com";
    final String _PROXY_HOST = "http://proxy.com";
    final String _PROXY_PORT = "8001";
    final String _PEM = "AAAAFFFFFSDADFADSFASDFASDFASDFASDFASDF";
    final String _KEY_PASSWORD = "testme";
    final String _KEYCLOAK_URI = "http://keycloak.com";
    final String _KEYCLOAK_PEM_PATH = pemFile.getAbsolutePath();
    IOUtils.write(_PEM, new FileOutputStream(pemFile));
    final class TestIndyHttpConfig extends IndyHttpConfig {

        @Override
        public Map<String, String> getConfiguration() {
            Map<String, String> parameters = new HashMap<>();
            parameters.put("uri", _URI);
            parameters.put("proxy.host", _PROXY_HOST);
            parameters.put("proxy.port", _PROXY_PORT);
            parameters.put("key.cert.pem", _PEM);
            parameters.put("key.password", _KEY_PASSWORD);
            parameters.put("keycloak_yourdomain_com.uri", _KEYCLOAK_URI);
            parameters.put("keycloak_yourdomain_com.key.cert.pem.path", _KEYCLOAK_PEM_PATH);
            return parameters;
        }
    }
    IndyHttpConfig config = new TestIndyHttpConfig();
    config.sectionComplete("http");
    IndySiteConfigLookup lookup = new IndySiteConfigLookup(null, config);
    SiteConfig siteConfig = lookup.lookup(DEFAULT_SITE);
    assertThat(siteConfig.getUri(), equalTo(_URI));
    assertThat(siteConfig.getProxyHost(), equalTo(_PROXY_HOST));
    assertThat(siteConfig.getProxyPort(), equalTo(Integer.parseInt(_PROXY_PORT)));
    assertThat(siteConfig.getKeyCertPem(), equalTo(_PEM));
    assertThat(siteConfig.getAttribute(PASSWORD_PREFIX + PasswordType.KEY.name()), equalTo(_KEY_PASSWORD));
    SiteConfig keycloakConfig = lookup.lookup("keycloak.yourdomain.com");
    assertThat(keycloakConfig.getUri(), equalTo(_KEYCLOAK_URI));
    assertThat(keycloakConfig.getKeyCertPem(), equalTo(_PEM));
}
Also used : HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) SiteConfig(org.commonjava.util.jhttpc.model.SiteConfig) File(java.io.File) IndyHttpConfig(org.commonjava.indy.subsys.http.conf.IndyHttpConfig) Test(org.junit.Test)

Example 4 with SiteConfig

use of org.commonjava.util.jhttpc.model.SiteConfig in project indy by Commonjava.

the class HttpSiteConfigTest method run.

@Ignore
@Test
public void run() throws Exception {
    String siteId = DEFAULT_SITE;
    SiteConfig conf = siteConfigLookup.lookup(siteId);
    assertThat(conf.getKeyCertPem(), equalTo(PEM_CONTENT));
}
Also used : SiteConfig(org.commonjava.util.jhttpc.model.SiteConfig) Ignore(org.junit.Ignore) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 5 with SiteConfig

use of org.commonjava.util.jhttpc.model.SiteConfig in project indy by Commonjava.

the class DownloadDiagBundleTest method createIndyClient.

protected Indy createIndyClient() throws IndyClientException {
    SiteConfig config = new SiteConfigBuilder("indy", fixture.getUrl()).withRequestTimeoutSeconds(120).build();
    Collection<IndyClientModule> modules = getAdditionalClientModules();
    return new Indy(config, new MemoryPasswordManager(), new IndyObjectMapper(getAdditionalMapperModules()), modules.toArray(new IndyClientModule[modules.size()]));
}
Also used : IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) SiteConfigBuilder(org.commonjava.util.jhttpc.model.SiteConfigBuilder) Indy(org.commonjava.indy.client.core.Indy) SiteConfig(org.commonjava.util.jhttpc.model.SiteConfig) MemoryPasswordManager(org.commonjava.util.jhttpc.auth.MemoryPasswordManager) IndyClientModule(org.commonjava.indy.client.core.IndyClientModule)

Aggregations

SiteConfig (org.commonjava.util.jhttpc.model.SiteConfig)7 SiteConfigBuilder (org.commonjava.util.jhttpc.model.SiteConfigBuilder)4 Test (org.junit.Test)3 Indy (org.commonjava.indy.client.core.Indy)2 IndyClientModule (org.commonjava.indy.client.core.IndyClientModule)2 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)2 MemoryPasswordManager (org.commonjava.util.jhttpc.auth.MemoryPasswordManager)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)1 AbstractIndyFunctionalTest (org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest)1 MemoryStoreDataManager (org.commonjava.indy.mem.data.MemoryStoreDataManager)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 IndyHttpConfig (org.commonjava.indy.subsys.http.conf.IndyHttpConfig)1 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1 JHttpCException (org.commonjava.util.jhttpc.JHttpCException)1 Ignore (org.junit.Ignore)1