@Test public void testSetConfiguration() throws Exception { final Path container = new Path(UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory, Path.Type.volume)); new S3DirectoryFeature(session, new S3WriteFeature(session, new S3DisabledMultipartService())).mkdir(container, null, new TransferStatus()); final Versioning feature = new S3VersioningFeature(session, new S3AccessControlListFeature(session)); feature.setConfiguration(container, new DisabledLoginCallback(), new VersioningConfiguration(true, false)); assertTrue(feature.getConfiguration(container).isEnabled()); new S3DefaultDeleteFeature(session).delete(Collections.<Path>singletonList(container), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(current.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } } else { log.debug(String.format("Suspend bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().suspendBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } if(configuration.isEnabled() && !configuration.isMultifactor()) { log.debug(String.format("Disable MFA %s for %s", factor.getUsername(), container)); final Credentials factor2 = this.getToken(StringUtils.EMPTY, prompt); session.getClient().disableMFAForVersionedBucket(container.getName(), factor2.getUsername(), factor2.getPassword()); } } else { if(configuration.isEnabled()) { if(configuration.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } else { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); session.getClient().enableBucketVersioning(container.getName()); } } } else { log.debug(String.format("Susped bucket versioning for %s", container)); session.getClient().suspendBucketVersioning(container.getName()); } } cache.remove(container); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, container); } }
S3VersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(current.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } } else { log.debug(String.format("Suspend bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().suspendBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } if(configuration.isEnabled() && !configuration.isMultifactor()) { log.debug(String.format("Disable MFA %s for %s", factor.getUsername(), container)); final Credentials factor2 = this.getToken(StringUtils.EMPTY, prompt); session.getClient().disableMFAForVersionedBucket(container.getName(), factor2.getUsername(), factor2.getPassword()); } } else { if(configuration.isEnabled()) { if(configuration.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } else { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); session.getClient().enableBucketVersioning(container.getName()); } } } else { log.debug(String.format("Susped bucket versioning for %s", container)); session.getClient().suspendBucketVersioning(container.getName()); } } cache.remove(container); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } }
S3VersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(current.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } } else { log.debug(String.format("Suspend bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().suspendBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } if(configuration.isEnabled() && !configuration.isMultifactor()) { log.debug(String.format("Disable MFA %s for %s", factor.getUsername(), container)); final Credentials factor2 = this.getToken(StringUtils.EMPTY, prompt); session.getClient().disableMFAForVersionedBucket(container.getName(), factor2.getUsername(), factor2.getPassword()); } } else { if(configuration.isEnabled()) { if(configuration.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } else { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); session.getClient().enableBucketVersioning(container.getName()); } } } else { log.debug(String.format("Susped bucket versioning for %s", container)); session.getClient().suspendBucketVersioning(container.getName()); } } cache.remove(container); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } S3VersioningFeature(final S3Session session, final S3AccessControlListFeature accessControlListFeature); }
S3VersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(current.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } } else { log.debug(String.format("Suspend bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().suspendBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } if(configuration.isEnabled() && !configuration.isMultifactor()) { log.debug(String.format("Disable MFA %s for %s", factor.getUsername(), container)); final Credentials factor2 = this.getToken(StringUtils.EMPTY, prompt); session.getClient().disableMFAForVersionedBucket(container.getName(), factor2.getUsername(), factor2.getPassword()); } } else { if(configuration.isEnabled()) { if(configuration.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } else { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); session.getClient().enableBucketVersioning(container.getName()); } } } else { log.debug(String.format("Susped bucket versioning for %s", container)); session.getClient().suspendBucketVersioning(container.getName()); } } cache.remove(container); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } S3VersioningFeature(final S3Session session, final S3AccessControlListFeature accessControlListFeature); @Override S3VersioningFeature withCache(final LRUCache<Path, VersioningConfiguration> cache); @Override void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration); @Override VersioningConfiguration getConfiguration(final Path file); @Override void revert(final Path file); @Override boolean isRevertable(final Path file); @Override Credentials getToken(final String mfaSerial, final PasswordCallback callback); }
S3VersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(current.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } } else { log.debug(String.format("Suspend bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().suspendBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } if(configuration.isEnabled() && !configuration.isMultifactor()) { log.debug(String.format("Disable MFA %s for %s", factor.getUsername(), container)); final Credentials factor2 = this.getToken(StringUtils.EMPTY, prompt); session.getClient().disableMFAForVersionedBucket(container.getName(), factor2.getUsername(), factor2.getPassword()); } } else { if(configuration.isEnabled()) { if(configuration.isMultifactor()) { final Credentials factor = this.getToken(StringUtils.EMPTY, prompt); log.debug(String.format("Enable bucket versioning with MFA %s for %s", factor.getUsername(), container)); session.getClient().enableBucketVersioningWithMFA(container.getName(), factor.getUsername(), factor.getPassword()); } else { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); session.getClient().enableBucketVersioning(container.getName()); } } } else { log.debug(String.format("Susped bucket versioning for %s", container)); session.getClient().suspendBucketVersioning(container.getName()); } } cache.remove(container); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } S3VersioningFeature(final S3Session session, final S3AccessControlListFeature accessControlListFeature); @Override S3VersioningFeature withCache(final LRUCache<Path, VersioningConfiguration> cache); @Override void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration); @Override VersioningConfiguration getConfiguration(final Path file); @Override void revert(final Path file); @Override boolean isRevertable(final Path file); @Override Credentials getToken(final String mfaSerial, final PasswordCallback callback);  }