use of ch.cyberduck.core.features.Lifecycle 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.features.Lifecycle in project cyberduck by iterate-ch.
the class WriteLifecycleWorker method run.
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final Lifecycle feature = session.getFeature(Lifecycle.class);
if (log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", feature));
}
final PathContainerService container = session.getFeature(PathContainerService.class);
for (Path file : this.getContainers(container, files)) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
this.write(feature, file);
}
return true;
}
use of ch.cyberduck.core.features.Lifecycle in project cyberduck by iterate-ch.
the class InfoController method initS3.
/**
*/
private void initS3() {
bucketLocationField.setStringValue(LocaleFactory.localizedString("Unknown"));
bucketLoggingPopup.removeAllItems();
bucketLoggingPopup.addItemWithTitle(LocaleFactory.localizedString("None"));
bucketLoggingPopup.lastItem().setEnabled(false);
storageClassPopup.removeAllItems();
storageClassPopup.addItemWithTitle(LocaleFactory.localizedString("Unknown"));
storageClassPopup.lastItem().setEnabled(false);
storageClassPopup.selectItem(storageClassPopup.lastItem());
encryptionPopup.removeAllItems();
encryptionPopup.addItemWithTitle(LocaleFactory.localizedString("Unknown"));
encryptionPopup.lastItem().setEnabled(false);
encryptionPopup.selectItem(encryptionPopup.lastItem());
if (this.toggleS3Settings(false)) {
final Path file = this.getSelected();
if (session.getFeature(Redundancy.class) != null) {
for (String redundancy : session.getFeature(Redundancy.class).getClasses()) {
storageClassPopup.addItemWithTitle(LocaleFactory.localizedString(redundancy, "S3"));
storageClassPopup.lastItem().setRepresentedObject(redundancy);
}
}
this.background(new RegistryBackgroundAction<Void>(controller, session) {
Location.Name location;
LoggingConfiguration logging;
VersioningConfiguration versioning;
// Available encryption keys in KMS
Set<Encryption.Algorithm> managedEncryptionKeys = new HashSet<>();
final Set<Encryption.Algorithm> selectedEncryptionKeys = new HashSet<>();
final Set<String> selectedStorageClasses = new HashSet<>();
LifecycleConfiguration lifecycle;
Boolean transferAcceleration;
@Override
public Void run(final Session<?> session) throws BackgroundException {
if (session.getFeature(Location.class) != null) {
location = session.getFeature(Location.class).getLocation(file);
}
if (session.getFeature(Logging.class) != null) {
logging = session.getFeature(Logging.class).getConfiguration(file);
}
if (session.getFeature(Versioning.class) != null) {
versioning = session.getFeature(Versioning.class).getConfiguration(file);
}
if (session.getFeature(Lifecycle.class) != null) {
lifecycle = session.getFeature(Lifecycle.class).getConfiguration(file);
}
if (session.getFeature(Redundancy.class) != null) {
for (final Path f : files) {
selectedStorageClasses.add(session.getFeature(Redundancy.class).getClass(f));
}
}
if (session.getFeature(Encryption.class) != null) {
// Add additional keys stored in KMS
managedEncryptionKeys = session.getFeature(Encryption.class).getKeys(file, prompt);
for (final Path f : files) {
selectedEncryptionKeys.add(session.getFeature(Encryption.class).getEncryption(f));
}
managedEncryptionKeys.addAll(selectedEncryptionKeys);
}
if (session.getFeature(TransferAcceleration.class) != null) {
try {
transferAcceleration = session.getFeature(TransferAcceleration.class).getStatus(file);
} catch (InteroperabilityException e) {
log.warn(String.format("Ignore failure %s reading transfer acceleration", e));
// 405 The specified method is not allowed against this resource
}
}
return null;
}
@Override
public void cleanup() {
super.cleanup();
if (logging != null) {
bucketLoggingButton.setState(logging.isEnabled() ? NSCell.NSOnState : NSCell.NSOffState);
if (!logging.getContainers().isEmpty()) {
bucketLoggingPopup.removeAllItems();
}
for (Path c : logging.getContainers()) {
bucketLoggingPopup.addItemWithTitle(c.getName());
bucketLoggingPopup.lastItem().setRepresentedObject(c.getName());
}
if (logging.isEnabled()) {
bucketLoggingPopup.selectItemWithTitle(logging.getLoggingTarget());
} else {
if (!logging.getContainers().isEmpty()) {
// Default to write log files to origin bucket
bucketLoggingPopup.selectItemAtIndex(bucketLoggingPopup.indexOfItemWithRepresentedObject(containerService.getContainer(file).getName()));
}
}
}
if (location != null) {
bucketLocationField.setStringValue(location.toString());
}
if (versioning != null) {
bucketVersioningButton.setState(versioning.isEnabled() ? NSCell.NSOnState : NSCell.NSOffState);
bucketMfaButton.setState(versioning.isMultifactor() ? NSCell.NSOnState : NSCell.NSOffState);
}
for (Encryption.Algorithm algorithm : managedEncryptionKeys) {
encryptionPopup.addItemWithTitle(LocaleFactory.localizedString(algorithm.getDescription(), "S3"));
encryptionPopup.lastItem().setRepresentedObject(algorithm.toString());
}
if (!selectedEncryptionKeys.isEmpty()) {
encryptionPopup.selectItemAtIndex(new NSInteger(-1));
if (-1 != encryptionPopup.indexOfItemWithTitle(LocaleFactory.localizedString("Unknown")).intValue()) {
encryptionPopup.removeItemWithTitle(LocaleFactory.localizedString("Unknown"));
}
}
for (Encryption.Algorithm algorithm : selectedEncryptionKeys) {
encryptionPopup.selectItemAtIndex(encryptionPopup.indexOfItemWithRepresentedObject(algorithm.toString()));
}
for (Encryption.Algorithm algorithm : selectedEncryptionKeys) {
encryptionPopup.itemAtIndex(encryptionPopup.indexOfItemWithRepresentedObject(algorithm.toString())).setState(selectedEncryptionKeys.size() == 1 ? NSCell.NSOnState : NSCell.NSMixedState);
}
if (!selectedStorageClasses.isEmpty()) {
storageClassPopup.selectItemAtIndex(new NSInteger(-1));
if (-1 != storageClassPopup.indexOfItemWithTitle(LocaleFactory.localizedString("Unknown")).intValue()) {
storageClassPopup.removeItemWithTitle(LocaleFactory.localizedString("Unknown"));
}
}
for (String storageClass : selectedStorageClasses) {
if (-1 != storageClassPopup.indexOfItemWithRepresentedObject(storageClass).intValue()) {
storageClassPopup.selectItemAtIndex(storageClassPopup.indexOfItemWithRepresentedObject(storageClass));
}
}
for (String storageClass : selectedStorageClasses) {
if (-1 != storageClassPopup.indexOfItemWithRepresentedObject(storageClass).intValue()) {
storageClassPopup.itemAtIndex(storageClassPopup.indexOfItemWithRepresentedObject(storageClass)).setState(selectedStorageClasses.size() == 1 ? NSCell.NSOnState : NSCell.NSMixedState);
}
}
if (lifecycle != null) {
lifecycleDeleteCheckbox.setState(lifecycle.getExpiration() != null ? NSCell.NSOnState : NSCell.NSOffState);
if (lifecycle.getExpiration() != null) {
final NSInteger index = lifecycleDeletePopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getExpiration()));
if (-1 == index.intValue()) {
lifecycleDeletePopup.addItemWithTitle(MessageFormat.format(LocaleFactory.localizedString("after {0} Days", "S3"), String.valueOf(lifecycle.getExpiration())));
lifecycleDeletePopup.lastItem().setAction(Foundation.selector("lifecyclePopupClicked:"));
lifecycleDeletePopup.lastItem().setTarget(id());
lifecycleDeletePopup.lastItem().setRepresentedObject(String.valueOf(lifecycle.getExpiration()));
}
lifecycleDeletePopup.selectItemAtIndex(lifecycleDeletePopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getExpiration())));
}
lifecycleTransitionCheckbox.setState(lifecycle.getTransition() != null ? NSCell.NSOnState : NSCell.NSOffState);
if (lifecycle.getTransition() != null) {
final NSInteger index = lifecycleTransitionPopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getTransition()));
if (-1 == index.intValue()) {
lifecycleTransitionPopup.addItemWithTitle(MessageFormat.format(LocaleFactory.localizedString("after {0} Days", "S3"), String.valueOf(lifecycle.getTransition())));
lifecycleTransitionPopup.lastItem().setAction(Foundation.selector("lifecyclePopupClicked:"));
lifecycleTransitionPopup.lastItem().setTarget(id());
lifecycleTransitionPopup.lastItem().setRepresentedObject(String.valueOf(lifecycle.getTransition()));
}
lifecycleTransitionPopup.selectItemAtIndex(lifecycleTransitionPopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getTransition())));
}
}
if (transferAcceleration != null) {
bucketTransferAccelerationButton.setState(transferAcceleration ? NSCell.NSOnState : NSCell.NSOffState);
}
toggleS3Settings(true);
}
@Override
public String getActivity() {
return MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), this.toString(files));
}
});
}
}
use of ch.cyberduck.core.features.Lifecycle in project cyberduck by iterate-ch.
the class GoogleStorageLifecycleFeature method setConfiguration.
@Override
public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException {
final Path container = containerService.getContainer(file);
try {
if (configuration.getTransition() != null || configuration.getExpiration() != null) {
final Bucket.Lifecycle config = new Bucket.Lifecycle();
// 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 List<Bucket.Lifecycle.Rule> rules = new ArrayList<>();
if (configuration.getTransition() != null) {
rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setAge(configuration.getTransition())).setAction(new Bucket.Lifecycle.Rule.Action().setType("SetStorageClass").setStorageClass(new HostPreferences(session.getHost()).getProperty("googlestorage.lifecycle.transition.class"))));
}
if (configuration.getExpiration() != null) {
rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setAge(configuration.getExpiration())).setAction(new Bucket.Lifecycle.Rule.Action().setType("Delete")));
}
session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle(config.setRule(rules))).execute();
} else {
// Empty lifecycle configuration
session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle(new Bucket.Lifecycle().setRule(Collections.emptyList()))).execute();
}
} catch (IOException e) {
throw new GoogleStorageExceptionMappingService().map("Failure to write attributes of {0}", e, container);
}
}
Aggregations