use of ch.cyberduck.core.preferences.PreferencesReader in project cyberduck by iterate-ch.
the class StoregateSession method connect.
@Override
protected StoregateApiClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt, final CancelCallback cancel) {
final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
final PreferencesReader preferences = new HostPreferences(host);
authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).addInterceptorLast(new HttpRequestInterceptor() {
@Override
public void process(final HttpRequest request, final HttpContext context) {
request.addHeader(HttpHeaders.AUTHORIZATION, String.format("Basic %s", Base64.encodeToString(String.format("%s:%s", host.getProtocol().getOAuthClientId(), host.getProtocol().getOAuthClientSecret()).getBytes(StandardCharsets.UTF_8), false)));
}
}).build(), host).withRedirectUri(CYBERDUCK_REDIRECT_URI.equals(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : Scheme.isURL(host.getProtocol().getOAuthRedirectUrl()) ? host.getProtocol().getOAuthRedirectUrl() : new HostUrlProvider().withUsername(false).withPath(true).get(host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getOAuthRedirectUrl())).withParameter("login_hint", preferences.getProperty("storegate.login.hint"));
// Force login even if browser session already exists
authorizationService.withParameter("prompt", "login");
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
configuration.addInterceptorLast(authorizationService);
final CloseableHttpClient apache = configuration.build();
final StoregateApiClient client = new StoregateApiClient(apache);
client.setBasePath(new HostUrlProvider().withUsername(false).withPath(true).get(host.getProtocol().getScheme(), host.getPort(), null, host.getHostname(), host.getProtocol().getContext()));
client.setHttpClient(ClientBuilder.newClient(new ClientConfig().register(new InputStreamProvider()).register(MultiPartFeature.class).register(new JSON()).register(JacksonFeature.class).connectorProvider(new HttpComponentsProvider(apache))));
final int timeout = preferences.getInteger("connection.timeout.seconds") * 1000;
client.setConnectTimeout(timeout);
client.setReadTimeout(timeout);
client.setUserAgent(new PreferencesUseragentProvider().get());
return client;
}
use of ch.cyberduck.core.preferences.PreferencesReader in project cyberduck by iterate-ch.
the class RequestEntityRestStorageService method setupConnection.
@Override
protected HttpUriRequest setupConnection(final HTTP_METHOD method, final String bucketName, final String objectKey, final Map<String, String> requestParameters) throws S3ServiceException {
final Host host = session.getHost();
// Apply default configuration
final PreferencesReader preferences = new HostPreferences(session.getHost());
if (S3Session.isAwsHostname(host.getHostname(), false)) {
// Check if not already set to accelerated endpoint
if (properties.getStringProperty("s3service.s3-endpoint", preferences.getProperty("s3.hostname.default")).matches("s3-accelerate(\\.dualstack)?\\.amazonaws\\.com")) {
log.debug("Skip adjusting endpoint with transfer acceleration");
} else {
// Only for AWS set endpoint to region specific
if (StringUtils.isNotBlank(bucketName) && (requestParameters == null || !requestParameters.containsKey("location"))) {
try {
// Determine region for bucket using cache
final Location.Name region = new S3LocationFeature(session, regionEndpointCache).getLocation(bucketName);
if (Location.unknown == region) {
log.warn(String.format("Failure determining bucket location for %s", bucketName));
} else {
final String endpoint;
if (preferences.getBoolean("s3.endpoint.dualstack.enable")) {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv6"), region.getIdentifier());
} else {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv4"), region.getIdentifier());
}
if (log.isDebugEnabled()) {
log.debug(String.format("Set endpoint to %s", endpoint));
}
properties.setProperty("s3service.s3-endpoint", endpoint);
}
} catch (BackgroundException e) {
// Ignore failure reading location for bucket
log.error(String.format("Failure %s determining bucket location for %s", e, bucketName));
}
} else {
if (StringUtils.isNotBlank(host.getRegion())) {
// Use default region
final String endpoint;
if (preferences.getBoolean("s3.endpoint.dualstack.enable")) {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv6"), host.getRegion());
} else {
endpoint = String.format(preferences.getProperty("s3.endpoint.format.ipv4"), host.getRegion());
}
if (log.isDebugEnabled()) {
log.debug(String.format("Set endpoint to %s", endpoint));
}
properties.setProperty("s3service.s3-endpoint", endpoint);
}
if (StringUtils.isBlank(bucketName)) {
if (log.isDebugEnabled()) {
log.debug(String.format("Determine bucket from hostname %s", host.getHostname()));
}
final String bucketNameInHostname = RequestEntityRestStorageService.findBucketInHostname(host);
if (bucketNameInHostname != null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Determined bucket %s from hostname %s", bucketNameInHostname, host.getHostname()));
}
if (!StringUtils.startsWith(properties.getStringProperty("s3service.s3-endpoint", host.getProtocol().getDefaultHostname()), bucketNameInHostname)) {
final String endpoint = String.format("%s.%s", bucketNameInHostname, properties.getStringProperty("s3service.s3-endpoint", host.getProtocol().getDefaultHostname()));
if (log.isDebugEnabled()) {
log.debug(String.format("Set endpoint to %s", endpoint));
}
properties.setProperty("s3service.s3-endpoint", endpoint);
}
}
}
}
}
}
final HttpUriRequest request = super.setupConnection(method, bucketName, objectKey, requestParameters);
if (preferences.getBoolean("s3.upload.expect-continue")) {
if ("PUT".equals(request.getMethod())) {
// #7621
if (!properties.getBoolProperty("s3service.disable-expect-continue", false)) {
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
}
}
}
if (preferences.getBoolean("s3.bucket.requesterpays")) {
// Only for AWS
if (S3Session.isAwsHostname(host.getHostname())) {
// Downloading Objects in Requester Pays Buckets
if ("GET".equals(request.getMethod()) || "POST".equals(request.getMethod())) {
if (!properties.getBoolProperty("s3service.disable-request-payer", false)) {
// For GET and POST requests, include x-amz-request-payer : requester in the header
request.addHeader("x-amz-request-payer", "requester");
}
}
}
}
return request;
}
use of ch.cyberduck.core.preferences.PreferencesReader in project cyberduck by iterate-ch.
the class RequestEntityRestStorageService method toProperties.
private static Jets3tProperties toProperties(final Host bookmark, final S3Protocol.AuthenticationHeaderSignatureVersion signatureVersion) {
final Jets3tProperties properties = new Jets3tProperties();
final PreferencesReader preferences = new HostPreferences(bookmark);
if (log.isDebugEnabled()) {
log.debug(String.format("Configure for endpoint %s", bookmark));
}
// Use default endpoint for region lookup
properties.setProperty("s3service.s3-endpoint", bookmark.getHostname());
if (InetAddressUtils.isIPv4Address(bookmark.getHostname()) || InetAddressUtils.isIPv6Address(bookmark.getHostname())) {
properties.setProperty("s3service.disable-dns-buckets", String.valueOf(true));
} else {
properties.setProperty("s3service.disable-dns-buckets", String.valueOf(preferences.getBoolean("s3.bucket.virtualhost.disable")));
}
properties.setProperty("s3service.enable-storage-classes", String.valueOf(true));
if (StringUtils.isNotBlank(bookmark.getProtocol().getContext())) {
if (!Scheme.isURL(bookmark.getProtocol().getContext())) {
properties.setProperty("s3service.s3-endpoint-virtual-path", PathNormalizer.normalize(bookmark.getProtocol().getContext()));
}
}
properties.setProperty("s3service.https-only", String.valueOf(bookmark.getProtocol().isSecure()));
if (bookmark.getProtocol().isSecure()) {
properties.setProperty("s3service.s3-endpoint-https-port", String.valueOf(bookmark.getPort()));
} else {
properties.setProperty("s3service.s3-endpoint-http-port", String.valueOf(bookmark.getPort()));
}
// The maximum number of retries that will be attempted when an S3 connection fails
// with an InternalServer error. To disable retries of InternalError failures, set this to 0.
properties.setProperty("s3service.internal-error-retry-max", String.valueOf(0));
// The maximum number of concurrent communication threads that will be started by
// the multi-threaded service for upload and download operations.
properties.setProperty("s3service.max-thread-count", String.valueOf(1));
properties.setProperty("httpclient.proxy-autodetect", String.valueOf(false));
properties.setProperty("httpclient.retry-max", String.valueOf(0));
properties.setProperty("storage-service.internal-error-retry-max", String.valueOf(0));
properties.setProperty("storage-service.request-signature-version", signatureVersion.toString());
properties.setProperty("storage-service.disable-live-md5", String.valueOf(true));
properties.setProperty("storage-service.default-region", bookmark.getRegion());
properties.setProperty("xmlparser.sanitize-listings", String.valueOf(false));
for (Map.Entry<String, String> property : bookmark.getProtocol().getProperties().entrySet()) {
properties.setProperty(property.getKey(), property.getValue());
}
return properties;
}
use of ch.cyberduck.core.preferences.PreferencesReader in project cyberduck by iterate-ch.
the class IRODSSession method configure.
protected IRODSFileSystem configure(final IRODSFileSystem client) {
final SettableJargonProperties properties = new SettableJargonProperties(client.getJargonProperties());
properties.setEncoding(host.getEncoding());
final PreferencesReader preferences = new HostPreferences(host);
final int timeout = preferences.getInteger("connection.timeout.seconds") * 1000;
properties.setIrodsSocketTimeout(timeout);
properties.setIrodsParallelSocketTimeout(timeout);
properties.setGetBufferSize(preferences.getInteger("connection.chunksize"));
properties.setPutBufferSize(preferences.getInteger("connection.chunksize"));
if (log.isDebugEnabled()) {
log.debug(String.format("Configure client %s with properties %s", client, properties));
}
client.getIrodsSession().setJargonProperties(properties);
client.getIrodsSession().setX509TrustManager(trust);
return client;
}
Aggregations