
com.sap.cloudfoundry.client.facade.rest.CloudControllerRestClientFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudfoundry-client-facade Show documentation
Show all versions of cloudfoundry-client-facade Show documentation
A facade of the official Cloud Foundry Java client
package com.sap.cloudfoundry.client.facade.rest;
import com.sap.cloudfoundry.client.facade.CloudCredentials;
import com.sap.cloudfoundry.client.facade.adapters.CloudFoundryClientFactory;
import com.sap.cloudfoundry.client.facade.adapters.ImmutableCloudFoundryClientFactory;
import com.sap.cloudfoundry.client.facade.domain.CloudSpace;
import com.sap.cloudfoundry.client.facade.oauth2.OAuthClient;
import com.sap.cloudfoundry.client.facade.util.RestUtil;
import org.cloudfoundry.client.CloudFoundryClient;
import org.cloudfoundry.reactor.ConnectionContext;
import org.immutables.value.Value;
import org.springframework.util.StringUtils;
import java.net.URL;
import java.time.Duration;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
@Value.Immutable
public abstract class CloudControllerRestClientFactory {
private final RestUtil restUtil = new RestUtil();
public abstract Optional getSslHandshakeTimeout();
public abstract Optional getConnectTimeout();
public abstract Optional getConnectionPoolSize();
public abstract Optional getThreadPoolSize();
public abstract Optional getResponseTimeout();
@Value.Default
public boolean shouldTrustSelfSignedCertificates() {
return false;
}
@Value.Derived
public CloudFoundryClientFactory getCloudFoundryClientFactory() {
ImmutableCloudFoundryClientFactory.Builder builder = ImmutableCloudFoundryClientFactory.builder();
getSslHandshakeTimeout().ifPresent(builder::sslHandshakeTimeout);
getConnectTimeout().ifPresent(builder::connectTimeout);
getConnectionPoolSize().ifPresent(builder::connectionPoolSize);
getThreadPoolSize().ifPresent(builder::threadPoolSize);
getResponseTimeout().ifPresent(builder::responseTimeout);
return builder.build();
}
public CloudControllerRestClient createClient(URL controllerUrl, CloudCredentials credentials, String organizationName,
String spaceName, OAuthClient oAuthClient, Map requestTags) {
oAuthClient.init(credentials);
CloudSpaceClient spaceGetter = getCloudFoundryClientFactory().createSpaceClient(controllerUrl, oAuthClient, requestTags);
CloudSpace target = spaceGetter.getSpace(organizationName, spaceName);
return createClient(controllerUrl, credentials, target, oAuthClient, requestTags);
}
public CloudControllerRestClient createClient(URL controllerUrl, CloudCredentials credentials, CloudSpace target) {
return createClient(controllerUrl, credentials, target, createOAuthClient(controllerUrl, credentials.getOrigin()),
Collections.emptyMap());
}
public CloudControllerRestClient createClient(URL controllerUrl, CloudCredentials credentials, CloudSpace target,
OAuthClient oAuthClient, Map requestTags) {
oAuthClient.init(credentials);
CloudFoundryClient delegate = getCloudFoundryClientFactory().createClient(controllerUrl, oAuthClient, requestTags);
return new CloudControllerRestClientImpl(delegate, target);
}
private OAuthClient createOAuthClient(URL controllerUrl, String origin) {
return restUtil.createOAuthClientByControllerUrl(controllerUrl, shouldTrustSelfSignedCertificates());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy