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();
}
}
}
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();
}
}));
}
}
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);
}
}
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);
}
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();
}
}
}
Aggregations