Search in sources :

Example 1 with PreferencesReader

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;
}
Also used : HttpRequest(org.apache.http.HttpRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HostUrlProvider(ch.cyberduck.core.HostUrlProvider) InputStreamProvider(org.glassfish.jersey.message.internal.InputStreamProvider) HttpContext(org.apache.http.protocol.HttpContext) OAuth2ErrorResponseInterceptor(ch.cyberduck.core.oauth.OAuth2ErrorResponseInterceptor) JSON(ch.cyberduck.core.storegate.io.swagger.client.JSON) PreferencesUseragentProvider(ch.cyberduck.core.PreferencesUseragentProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) PreferencesReader(ch.cyberduck.core.preferences.PreferencesReader) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) JacksonFeature(org.glassfish.jersey.jackson.JacksonFeature) OAuth2RequestInterceptor(ch.cyberduck.core.oauth.OAuth2RequestInterceptor) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) ClientConfig(org.glassfish.jersey.client.ClientConfig) HttpComponentsProvider(ch.cyberduck.core.jersey.HttpComponentsProvider)

Example 2 with PreferencesReader

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;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Host(ch.cyberduck.core.Host) BackgroundException(ch.cyberduck.core.exception.BackgroundException) PreferencesReader(ch.cyberduck.core.preferences.PreferencesReader) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) Location(ch.cyberduck.core.features.Location)

Example 3 with PreferencesReader

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;
}
Also used : Jets3tProperties(org.jets3t.service.Jets3tProperties) Map(java.util.Map) PreferencesReader(ch.cyberduck.core.preferences.PreferencesReader) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 4 with PreferencesReader

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;
}
Also used : SettableJargonProperties(org.irods.jargon.core.connection.SettableJargonProperties) PreferencesReader(ch.cyberduck.core.preferences.PreferencesReader) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Aggregations

HostPreferences (ch.cyberduck.core.preferences.HostPreferences)4 PreferencesReader (ch.cyberduck.core.preferences.PreferencesReader)4 Host (ch.cyberduck.core.Host)1 HostUrlProvider (ch.cyberduck.core.HostUrlProvider)1 PreferencesUseragentProvider (ch.cyberduck.core.PreferencesUseragentProvider)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 Location (ch.cyberduck.core.features.Location)1 HttpComponentsProvider (ch.cyberduck.core.jersey.HttpComponentsProvider)1 OAuth2ErrorResponseInterceptor (ch.cyberduck.core.oauth.OAuth2ErrorResponseInterceptor)1 OAuth2RequestInterceptor (ch.cyberduck.core.oauth.OAuth2RequestInterceptor)1 JSON (ch.cyberduck.core.storegate.io.swagger.client.JSON)1 Map (java.util.Map)1 HttpRequest (org.apache.http.HttpRequest)1 HttpRequestInterceptor (org.apache.http.HttpRequestInterceptor)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1 HttpContext (org.apache.http.protocol.HttpContext)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1 JacksonFeature (org.glassfish.jersey.jackson.JacksonFeature)1