@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")));
                }
                final Storage.Buckets.Patch request = session.getClient().buckets().patch(container.getName(),
                        new Bucket().setLifecycle(config.setRule(rules)));
                if(containerService.getContainer(file).attributes().getCustom().containsKey(GoogleStorageAttributesFinderFeature.KEY_REQUESTER_PAYS)) {
                    request.setUserProject(session.getHost().getCredentials().getUsername());
                }
                request.execute();
            }
            else {
                // Empty lifecycle configuration
                final Storage.Buckets.Patch request = session.getClient().buckets().patch(container.getName(), new Bucket()
                        .setLifecycle(new Bucket.Lifecycle().setRule(Collections.emptyList())));
                if(containerService.getContainer(file).attributes().getCustom().containsKey(GoogleStorageAttributesFinderFeature.KEY_REQUESTER_PAYS)) {
                    request.setUserProject(session.getHost().getCredentials().getUsername());
                }
                request.execute();
            }
        }
        catch(IOException e) {
            throw new GoogleStorageExceptionMappingService().map("Failure to write attributes of {0}", e, container);
        }
    }
@Test
    public void testSetConfiguration() throws Exception {
        final Path test = new Path(new DefaultHomeFinderService(session).find(),
                new AsciiRandomStringService().random().toLowerCase(Locale.ROOT), EnumSet.of(Path.Type.directory, Path.Type.volume));
        new GoogleStorageDirectoryFeature(session).mkdir(test, new TransferStatus());
        final GoogleStorageLifecycleFeature feature = new GoogleStorageLifecycleFeature(session);
        assertEquals(LifecycleConfiguration.empty(), feature.getConfiguration(test));
        feature.setConfiguration(test, new LifecycleConfiguration(1, 2));
        final LifecycleConfiguration read = feature.getConfiguration(test);
        assertEquals(1, read.getTransition(), 0L);
        assertEquals(2, read.getExpiration(), 0L);
        feature.setConfiguration(test, LifecycleConfiguration.empty());
        assertEquals(LifecycleConfiguration.empty(), feature.getConfiguration(test));
        new GoogleStorageDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }