Search in sources :

Example 1 with LoggingConfiguration

use of ch.cyberduck.core.logging.LoggingConfiguration in project cyberduck by iterate-ch.

the class GoogleStorageLoggingFeatureTest method testGetConfiguration.

@Test
public void testGetConfiguration() throws Exception {
    final GoogleStorageLoggingFeature feature = new GoogleStorageLoggingFeature(session);
    final Path bucket = new Path("cyberduck-test-eu", EnumSet.of(Path.Type.directory, Path.Type.volume));
    feature.setConfiguration(bucket, new LoggingConfiguration(true, "cyberduck-test-eu"));
    final LoggingConfiguration configuration = feature.getConfiguration(bucket);
    assertNotNull(configuration);
    assertEquals("cyberduck-test-eu", configuration.getLoggingTarget());
    assertTrue(configuration.isEnabled());
}
Also used : Path(ch.cyberduck.core.Path) LoggingConfiguration(ch.cyberduck.core.logging.LoggingConfiguration) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with LoggingConfiguration

use of ch.cyberduck.core.logging.LoggingConfiguration in project cyberduck by iterate-ch.

the class InfoController method bucketLoggingButtonClicked.

@Action
public void bucketLoggingButtonClicked(final NSButton sender) {
    if (this.toggleS3Settings(false)) {
        final LoggingConfiguration configuration = new LoggingConfiguration(bucketLoggingButton.state() == NSCell.NSOnState, null == bucketLoggingPopup.selectedItem() ? null : bucketLoggingPopup.selectedItem().representedObject());
        this.background(new WorkerBackgroundAction<>(controller, session, new WriteLoggingWorker(files, configuration) {

            @Override
            public void cleanup(final Boolean result) {
                toggleS3Settings(true);
                initS3();
            }
        }));
    }
}
Also used : LoggingConfiguration(ch.cyberduck.core.logging.LoggingConfiguration) 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 LoggingConfiguration

use of ch.cyberduck.core.logging.LoggingConfiguration in project cyberduck by iterate-ch.

the class S3LoggingFeature method getConfiguration.

@Override
public LoggingConfiguration getConfiguration(final Path file) throws BackgroundException {
    final Path bucket = containerService.getContainer(file);
    if (file.getType().contains(Path.Type.upload)) {
        return LoggingConfiguration.empty();
    }
    try {
        final StorageBucketLoggingStatus status = session.getClient().getBucketLoggingStatusImpl(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName());
        if (null == status) {
            log.warn(String.format("Failure parsing logging status for %s", bucket));
            return LoggingConfiguration.empty();
        }
        final LoggingConfiguration configuration = new LoggingConfiguration(status.isLoggingEnabled(), status.getTargetBucketName());
        try {
            configuration.setContainers(new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list(new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()).toList());
        } catch (AccessDeniedException | InteroperabilityException e) {
            log.warn(String.format("Failure listing buckets. %s", e.getMessage()));
            configuration.setContainers(Collections.singletonList(bucket));
        }
        return configuration;
    } catch (ServiceException e) {
        try {
            throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file);
        } catch (AccessDeniedException | InteroperabilityException l) {
            log.warn(String.format("Missing permission to read logging configuration for %s %s", bucket.getName(), e.getMessage()));
            return LoggingConfiguration.empty();
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ServiceException(org.jets3t.service.ServiceException) LoggingConfiguration(ch.cyberduck.core.logging.LoggingConfiguration) StorageBucketLoggingStatus(org.jets3t.service.model.StorageBucketLoggingStatus)

Example 4 with LoggingConfiguration

use of ch.cyberduck.core.logging.LoggingConfiguration in project cyberduck by iterate-ch.

the class AzureLoggingFeature method getConfiguration.

@Override
public LoggingConfiguration getConfiguration(final Path container) throws BackgroundException {
    try {
        final ServiceProperties properties = session.getClient().downloadServiceProperties(null, context);
        final LoggingConfiguration configuration = new LoggingConfiguration(!properties.getLogging().getLogOperationTypes().isEmpty(), "$logs");
        // When you have configured Storage Logging to log request data from your storage account, it saves the log data
        // to blobs in a container named $logs in your storage account.
        configuration.setContainers(Collections.singletonList(new Path("/$logs", EnumSet.of(Path.Type.volume, Path.Type.directory))));
        return configuration;
    } catch (StorageException e) {
        throw new AzureExceptionMappingService().map("Cannot read container configuration", e);
    }
}
Also used : Path(ch.cyberduck.core.Path) ServiceProperties(com.microsoft.azure.storage.ServiceProperties) LoggingConfiguration(ch.cyberduck.core.logging.LoggingConfiguration) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with LoggingConfiguration

use of ch.cyberduck.core.logging.LoggingConfiguration 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));
            }
        });
    }
}
Also used : NSMutableAttributedString(ch.cyberduck.binding.foundation.NSMutableAttributedString) NSString(ch.cyberduck.binding.foundation.NSString) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) Encryption(ch.cyberduck.core.features.Encryption) TransferAcceleration(ch.cyberduck.core.features.TransferAcceleration) LoggingConfiguration(ch.cyberduck.core.logging.LoggingConfiguration) HashSet(java.util.HashSet) DistributionLogging(ch.cyberduck.core.cdn.features.DistributionLogging) Logging(ch.cyberduck.core.features.Logging) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) Redundancy(ch.cyberduck.core.features.Redundancy) Lifecycle(ch.cyberduck.core.features.Lifecycle) LifecycleConfiguration(ch.cyberduck.core.lifecycle.LifecycleConfiguration) NSInteger(org.rococoa.cocoa.foundation.NSInteger) Versioning(ch.cyberduck.core.features.Versioning) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Location(ch.cyberduck.core.features.Location)

Aggregations

LoggingConfiguration (ch.cyberduck.core.logging.LoggingConfiguration)8 Path (ch.cyberduck.core.Path)6 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)3 IntegrationTest (ch.cyberduck.test.IntegrationTest)3 Test (org.junit.Test)3 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)2 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)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 DistributionLogging (ch.cyberduck.core.cdn.features.DistributionLogging)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 Encryption (ch.cyberduck.core.features.Encryption)1 Lifecycle (ch.cyberduck.core.features.Lifecycle)1 Location (ch.cyberduck.core.features.Location)1 Logging (ch.cyberduck.core.features.Logging)1 Redundancy (ch.cyberduck.core.features.Redundancy)1 TransferAcceleration (ch.cyberduck.core.features.TransferAcceleration)1 Versioning (ch.cyberduck.core.features.Versioning)1