Search in sources :

Example 1 with LifecycleConfiguration

use of ch.cyberduck.core.lifecycle.LifecycleConfiguration in project cyberduck by iterate-ch.

the class GoogleStorageLifecycleFeature method getConfiguration.

@Override
public LifecycleConfiguration getConfiguration(final Path file) throws BackgroundException {
    final Path container = containerService.getContainer(file);
    if (container.isRoot()) {
        return LifecycleConfiguration.empty();
    }
    try {
        final Bucket.Lifecycle status = session.getClient().buckets().get(container.getName()).execute().getLifecycle();
        if (null != status) {
            Integer transition = null;
            Integer expiration = null;
            for (Bucket.Lifecycle.Rule rule : status.getRule()) {
                if ("SetStorageClass".equals(rule.getAction().getType())) {
                    transition = rule.getCondition().getAge();
                }
                if ("Delete".equals(rule.getAction().getType())) {
                    expiration = rule.getCondition().getAge();
                }
            }
            return new LifecycleConfiguration(transition, expiration);
        }
        return LifecycleConfiguration.empty();
    } catch (IOException e) {
        try {
            throw new GoogleStorageExceptionMappingService().map("Failure to read attributes of {0}", e, container);
        } catch (AccessDeniedException | InteroperabilityException l) {
            log.warn(String.format("Missing permission to read lifecycle configuration for %s %s", container, e.getMessage()));
            return LifecycleConfiguration.empty();
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) Bucket(com.google.api.services.storage.model.Bucket) Lifecycle(ch.cyberduck.core.features.Lifecycle) LifecycleConfiguration(ch.cyberduck.core.lifecycle.LifecycleConfiguration) IOException(java.io.IOException)

Example 2 with LifecycleConfiguration

use of ch.cyberduck.core.lifecycle.LifecycleConfiguration in project cyberduck by iterate-ch.

the class InfoController method lifecyclePopupClicked.

@Action
public void lifecyclePopupClicked(final NSButton sender) {
    if (this.toggleS3Settings(false)) {
        final LifecycleConfiguration configuration = new LifecycleConfiguration(lifecycleTransitionCheckbox.state() == NSCell.NSOnState ? Integer.valueOf(lifecycleTransitionPopup.selectedItem().representedObject()) : null, lifecycleDeleteCheckbox.state() == NSCell.NSOnState ? Integer.valueOf(lifecycleDeletePopup.selectedItem().representedObject()) : null);
        this.background(new WorkerBackgroundAction<>(controller, session, new WriteLifecycleWorker(files, configuration) {

            @Override
            public void cleanup(final Boolean result) {
                toggleS3Settings(true);
                initS3();
            }
        }));
    }
}
Also used : LifecycleConfiguration(ch.cyberduck.core.lifecycle.LifecycleConfiguration) Action(ch.cyberduck.binding.Action) RegistryBackgroundAction(ch.cyberduck.core.threading.RegistryBackgroundAction) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction)

Example 3 with LifecycleConfiguration

use of ch.cyberduck.core.lifecycle.LifecycleConfiguration in project cyberduck by iterate-ch.

the class B2LifecycleFeature method getConfiguration.

@Override
public LifecycleConfiguration getConfiguration(final Path container) throws BackgroundException {
    try {
        final B2BucketResponse response = session.getClient().listBucket(containerService.getContainer(container).getName());
        final List<LifecycleRule> lifecycleRules = response.getLifecycleRules();
        for (LifecycleRule rule : lifecycleRules) {
            return new LifecycleConfiguration(null == rule.getDaysFromUploadingToHiding() ? null : rule.getDaysFromUploadingToHiding().intValue(), null == rule.getDaysFromHidingToDeleting() ? null : rule.getDaysFromHidingToDeleting().intValue());
        }
        return LifecycleConfiguration.empty();
    } catch (B2ApiException e) {
        throw new B2ExceptionMappingService(fileid).map("Failure to write attributes of {0}", e, container);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, container);
    }
}
Also used : B2BucketResponse(synapticloop.b2.response.B2BucketResponse) LifecycleConfiguration(ch.cyberduck.core.lifecycle.LifecycleConfiguration) B2ApiException(synapticloop.b2.exception.B2ApiException) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) LifecycleRule(synapticloop.b2.LifecycleRule)

Example 4 with LifecycleConfiguration

use of ch.cyberduck.core.lifecycle.LifecycleConfiguration in project cyberduck by iterate-ch.

the class S3LifecycleConfigurationTest method testGetConfiguration.

@Test
public void testGetConfiguration() throws Exception {
    final LifecycleConfiguration configuration = new S3LifecycleConfiguration(session).getConfiguration(new Path("test-lifecycle-us-east-1-cyberduck", EnumSet.of(Path.Type.directory)));
    assertEquals(30, configuration.getExpiration(), 0L);
    assertEquals(1, configuration.getTransition(), 0L);
}
Also used : Path(ch.cyberduck.core.Path) LifecycleConfiguration(ch.cyberduck.core.lifecycle.LifecycleConfiguration) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with LifecycleConfiguration

use of ch.cyberduck.core.lifecycle.LifecycleConfiguration in project cyberduck by iterate-ch.

the class S3LifecycleConfiguration method getConfiguration.

@Override
public LifecycleConfiguration getConfiguration(final Path file) throws BackgroundException {
    final Path bucket = containerService.getContainer(file);
    if (file.getType().contains(Path.Type.upload)) {
        return LifecycleConfiguration.empty();
    }
    try {
        final LifecycleConfig status = session.getClient().getLifecycleConfig(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName());
        if (null == status) {
            log.warn(String.format("Failure parsing lifecycle config for %s", bucket));
            return LifecycleConfiguration.empty();
        }
        Integer transition = null;
        Integer expiration = null;
        String storageClass = null;
        for (LifecycleConfig.Rule rule : status.getRules()) {
            if (StringUtils.isBlank(rule.getPrefix())) {
                if (rule.getTransition() != null) {
                    transition = rule.getTransition().getDays();
                }
                if (rule.getExpiration() != null) {
                    expiration = rule.getExpiration().getDays();
                }
            }
        }
        return new LifecycleConfiguration(transition, expiration);
    } catch (ServiceException e) {
        try {
            throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, bucket);
        } catch (AccessDeniedException | InteroperabilityException l) {
            log.warn(String.format("Missing permission to read lifecycle configuration for %s %s", bucket, e.getMessage()));
            return LifecycleConfiguration.empty();
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) LifecycleConfig(org.jets3t.service.model.LifecycleConfig) ServiceException(org.jets3t.service.ServiceException) LifecycleConfiguration(ch.cyberduck.core.lifecycle.LifecycleConfiguration)

Aggregations

LifecycleConfiguration (ch.cyberduck.core.lifecycle.LifecycleConfiguration)8 Path (ch.cyberduck.core.Path)5 IntegrationTest (ch.cyberduck.test.IntegrationTest)3 Test (org.junit.Test)3 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)2 Delete (ch.cyberduck.core.features.Delete)2 Lifecycle (ch.cyberduck.core.features.Lifecycle)2 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)2 IOException (java.io.IOException)2 Action (ch.cyberduck.binding.Action)1 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)1 NSMutableAttributedString (ch.cyberduck.binding.foundation.NSMutableAttributedString)1 NSString (ch.cyberduck.binding.foundation.NSString)1 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 AsciiRandomStringService (ch.cyberduck.core.AsciiRandomStringService)1 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)1 DistributionLogging (ch.cyberduck.core.cdn.features.DistributionLogging)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)1 Encryption (ch.cyberduck.core.features.Encryption)1