Search in sources :

Example 46 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class S3MultipartWriteFeature method write.

@Override
public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    final S3Object object = new S3WriteFeature(session).getDetails(file, status);
    // ID for the initiated multipart upload.
    final MultipartUpload multipart;
    try {
        final Path bucket = containerService.getContainer(file);
        multipart = session.getClient().multipartStartUpload(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), object);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Multipart upload started for %s with ID %s", multipart.getObjectKey(), multipart.getUploadId()));
        }
    } catch (ServiceException e) {
        throw new S3ExceptionMappingService().map("Upload {0} failed", e, file);
    }
    final MultipartOutputStream proxy = new MultipartOutputStream(multipart, file, status);
    return new HttpResponseOutputStream<StorageObject>(new MemorySegementingOutputStream(proxy, new HostPreferences(session.getHost()).getInteger("s3.upload.multipart.size")), new S3AttributesAdapter(), status) {

        @Override
        public StorageObject getStatus() {
            if (proxy.getResponse() != null) {
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Received response %s", proxy.getResponse()));
                }
                object.setETag(proxy.getResponse().getEtag());
                if (proxy.getResponse().getVersionId() != null) {
                    object.addMetadata(S3Object.S3_VERSION_ID, proxy.getResponse().getVersionId());
                }
            }
            return object;
        }
    };
}
Also used : Path(ch.cyberduck.core.Path) ServiceException(org.jets3t.service.ServiceException) MemorySegementingOutputStream(ch.cyberduck.core.io.MemorySegementingOutputStream) S3Object(org.jets3t.service.model.S3Object) HttpResponseOutputStream(ch.cyberduck.core.http.HttpResponseOutputStream) MultipartUpload(org.jets3t.service.model.MultipartUpload) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 47 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class S3EncryptionFeature method getDefault.

/**
 * @param file Default encryption setting for file
 * @return Return custom key for AWS-KMS if set for bucket in preferences. Otherwise default SSE algorithm.
 */
@Override
public Algorithm getDefault(final Path file) {
    final String key = String.format("s3.encryption.key.%s", containerService.getContainer(file).getName());
    if (StringUtils.isNotBlank(new HostPreferences(session.getHost()).getProperty(key))) {
        return Algorithm.fromString(new HostPreferences(session.getHost()).getProperty(key));
    }
    // Return default setting in preferences
    final String setting = new HostPreferences(session.getHost()).getProperty("s3.encryption.algorithm");
    if (StringUtils.equals(SSE_AES256.algorithm, setting)) {
        return SSE_AES256;
    }
    return Algorithm.NONE;
}
Also used : HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 48 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class S3LifecycleConfiguration method setConfiguration.

@Override
public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException {
    final Path bucket = containerService.getContainer(file);
    try {
        if (configuration.getTransition() != null || configuration.getExpiration() != null) {
            final LifecycleConfig config = new LifecycleConfig();
            // Unique identifier for the rule. The value cannot be longer than 255 characters. When you specify an empty prefix, the rule applies to all objects in the bucket
            final LifecycleConfig.Rule rule = config.newRule(String.format("%s-%s", PreferencesFactory.get().getProperty("application.name"), new AlphanumericRandomStringService().random()), StringUtils.EMPTY, true);
            if (configuration.getTransition() != null) {
                final LifecycleConfig.Transition transition = rule.newTransition();
                transition.setDays(configuration.getTransition());
                transition.setStorageClass(new HostPreferences(session.getHost()).getProperty("s3.lifecycle.transition.class"));
            }
            if (configuration.getExpiration() != null) {
                final LifecycleConfig.Expiration expiration = rule.newExpiration();
                expiration.setDays(configuration.getExpiration());
            }
            session.getClient().setLifecycleConfig(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), config);
        } else {
            session.getClient().deleteLifecycleConfig(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName());
        }
    } catch (ServiceException e) {
        throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, bucket);
    }
}
Also used : Path(ch.cyberduck.core.Path) LifecycleConfig(org.jets3t.service.model.LifecycleConfig) ServiceException(org.jets3t.service.ServiceException) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 49 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class BrowserController method createEncryptedVaultButtonClicked.

@Action
public void createEncryptedVaultButtonClicked(final ID sender) {
    final Location feature = pool.getFeature(Location.class);
    final VaultController sheet = new VaultController(this.getWorkdirFromSelection(), this.getSelectedPath(), cache, feature != null ? feature.getLocations() : Collections.emptySet(), feature != null ? feature.getDefault() : Location.unknown, new VaultController.Callback() {

        @Override
        public void callback(final Path folder, final String region, final VaultCredentials passphrase) {
            background(new WorkerBackgroundAction<>(BrowserController.this, pool, new CreateVaultWorker(region, passphrase, PasswordStoreFactory.get(), VaultFactory.get(folder, new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.masterkey.filename"), new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.config.filename"), new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8))) {

                @Override
                public void cleanup(final Path vault) {
                    reload(workdir, Collections.singletonList(folder), Collections.singletonList(folder));
                }
            }));
        }
    });
    sheet.beginSheet(this);
}
Also used : VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) CreateVaultWorker(ch.cyberduck.core.worker.CreateVaultWorker) NSString(ch.cyberduck.binding.foundation.NSString) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) Location(ch.cyberduck.core.features.Location) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DisconnectBackgroundAction(ch.cyberduck.core.threading.DisconnectBackgroundAction) TransferAction(ch.cyberduck.core.transfer.TransferAction) Action(ch.cyberduck.binding.Action) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) BrowserTransferBackgroundAction(ch.cyberduck.core.threading.BrowserTransferBackgroundAction)

Example 50 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method updateCustomDistribution.

protected UpdateDistributionResult updateCustomDistribution(final Path container, final Distribution distribution) throws BackgroundException {
    final URI origin = this.getOrigin(container, distribution.getMethod());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Update %s distribution with origin %s", distribution, origin));
    }
    final AmazonCloudFront client = this.client(container);
    final GetDistributionConfigResult response = client.getDistributionConfig(new GetDistributionConfigRequest(distribution.getId()));
    final DistributionConfig config = response.getDistributionConfig().withEnabled(distribution.isEnabled()).withDefaultRootObject(distribution.getIndexDocument() != null ? distribution.getIndexDocument() : StringUtils.EMPTY).withAliases(new Aliases().withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    // Make bucket name fully qualified
    final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
    }
    config.setLogging(new LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true).withBucket(loggingTarget).withPrefix(new HostPreferences(session.getHost()).getProperty("cloudfront.logging.prefix")));
    return client.updateDistribution(new UpdateDistributionRequest(config, distribution.getId(), response.getETag()));
}
Also used : AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront) URI(java.net.URI) S3Protocol(ch.cyberduck.core.s3.S3Protocol) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Aggregations

HostPreferences (ch.cyberduck.core.preferences.HostPreferences)81 IOException (java.io.IOException)33 Path (ch.cyberduck.core.Path)29 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)18 BackgroundException (ch.cyberduck.core.exception.BackgroundException)12 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)11 PathAttributes (ch.cyberduck.core.PathAttributes)11 NotfoundException (ch.cyberduck.core.exception.NotfoundException)11 File (com.google.api.services.drive.model.File)10 AttributedList (ch.cyberduck.core.AttributedList)8 URI (java.net.URI)8 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)6 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)6 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)6 MemorySegementingOutputStream (ch.cyberduck.core.io.MemorySegementingOutputStream)6 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)5 Credentials (ch.cyberduck.core.Credentials)4 Partition (ch.cyberduck.core.collections.Partition)4 S3Protocol (ch.cyberduck.core.s3.S3Protocol)4