@Test public void testGetConfigurationAccessDenied() throws Exception { assertEquals(LifecycleConfiguration.empty(), new S3LifecycleConfiguration(session).getConfiguration( new Path("bucket", EnumSet.of(Path.Type.directory)) )); }
@Override public LifecycleConfiguration getConfiguration(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return LifecycleConfiguration.empty(); } if(file.getType().contains(Path.Type.upload)) { return LifecycleConfiguration.empty(); } try { final LifecycleConfig status = session.getClient().getLifecycleConfig(container.getName()); if(null != status) { Integer transition = null; Integer expiration = null; String storageClass = null; for(LifecycleConfig.Rule rule : status.getRules()) { if(rule.getTransition() != null) { storageClass = rule.getTransition().getStorageClass(); transition = rule.getTransition().getDays(); } if(rule.getExpiration() != null) { expiration = rule.getExpiration().getDays(); } } return new LifecycleConfiguration(transition, storageClass, expiration); } return LifecycleConfiguration.empty(); } catch(ServiceException e) { try { throw new S3ExceptionMappingService().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(); } } }
S3LifecycleConfiguration implements Lifecycle { @Override public LifecycleConfiguration getConfiguration(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return LifecycleConfiguration.empty(); } if(file.getType().contains(Path.Type.upload)) { return LifecycleConfiguration.empty(); } try { final LifecycleConfig status = session.getClient().getLifecycleConfig(container.getName()); if(null != status) { Integer transition = null; Integer expiration = null; String storageClass = null; for(LifecycleConfig.Rule rule : status.getRules()) { if(rule.getTransition() != null) { storageClass = rule.getTransition().getStorageClass(); transition = rule.getTransition().getDays(); } if(rule.getExpiration() != null) { expiration = rule.getExpiration().getDays(); } } return new LifecycleConfiguration(transition, storageClass, expiration); } return LifecycleConfiguration.empty(); } catch(ServiceException e) { try { throw new S3ExceptionMappingService().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(); } } } }
S3LifecycleConfiguration implements Lifecycle { @Override public LifecycleConfiguration getConfiguration(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return LifecycleConfiguration.empty(); } if(file.getType().contains(Path.Type.upload)) { return LifecycleConfiguration.empty(); } try { final LifecycleConfig status = session.getClient().getLifecycleConfig(container.getName()); if(null != status) { Integer transition = null; Integer expiration = null; String storageClass = null; for(LifecycleConfig.Rule rule : status.getRules()) { if(rule.getTransition() != null) { storageClass = rule.getTransition().getStorageClass(); transition = rule.getTransition().getDays(); } if(rule.getExpiration() != null) { expiration = rule.getExpiration().getDays(); } } return new LifecycleConfiguration(transition, storageClass, expiration); } return LifecycleConfiguration.empty(); } catch(ServiceException e) { try { throw new S3ExceptionMappingService().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(); } } } S3LifecycleConfiguration(final S3Session session); }
S3LifecycleConfiguration implements Lifecycle { @Override public LifecycleConfiguration getConfiguration(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return LifecycleConfiguration.empty(); } if(file.getType().contains(Path.Type.upload)) { return LifecycleConfiguration.empty(); } try { final LifecycleConfig status = session.getClient().getLifecycleConfig(container.getName()); if(null != status) { Integer transition = null; Integer expiration = null; String storageClass = null; for(LifecycleConfig.Rule rule : status.getRules()) { if(rule.getTransition() != null) { storageClass = rule.getTransition().getStorageClass(); transition = rule.getTransition().getDays(); } if(rule.getExpiration() != null) { expiration = rule.getExpiration().getDays(); } } return new LifecycleConfiguration(transition, storageClass, expiration); } return LifecycleConfiguration.empty(); } catch(ServiceException e) { try { throw new S3ExceptionMappingService().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(); } } } S3LifecycleConfiguration(final S3Session session); @Override void setConfiguration(final Path file, final LifecycleConfiguration configuration); @Override LifecycleConfiguration getConfiguration(final Path file); }
S3LifecycleConfiguration implements Lifecycle { @Override public LifecycleConfiguration getConfiguration(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return LifecycleConfiguration.empty(); } if(file.getType().contains(Path.Type.upload)) { return LifecycleConfiguration.empty(); } try { final LifecycleConfig status = session.getClient().getLifecycleConfig(container.getName()); if(null != status) { Integer transition = null; Integer expiration = null; String storageClass = null; for(LifecycleConfig.Rule rule : status.getRules()) { if(rule.getTransition() != null) { storageClass = rule.getTransition().getStorageClass(); transition = rule.getTransition().getDays(); } if(rule.getExpiration() != null) { expiration = rule.getExpiration().getDays(); } } return new LifecycleConfiguration(transition, storageClass, expiration); } return LifecycleConfiguration.empty(); } catch(ServiceException e) { try { throw new S3ExceptionMappingService().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(); } } } S3LifecycleConfiguration(final S3Session session); @Override void setConfiguration(final Path file, final LifecycleConfiguration configuration); @Override LifecycleConfiguration getConfiguration(final Path file);  }