@Test public void testEmptyWithVersions() throws Exception { // enable versioning on the bucket SetBucketVersioningConfigurationRequest req = new SetBucketVersioningConfigurationRequest( bucketName, new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED)); s3.setBucketVersioningConfiguration(req); // create some versions createVersionedObjects(); // empty the bucket of it's contents but leave the bucket itself S3Cleaner.emptyBucket(s3, bucketName, false, offlineContext); // check the bucket is still present but empty assertTrue("Bucket '" + bucketName + "' should still be present", s3.doesBucketExistV2(bucketName)); ObjectListing objects = s3.listObjects(bucketName); assertTrue("Bucket '" + bucketName + "' should be empty", objects.getObjectSummaries().isEmpty()); }
/** * Converts the specified versioning configuration into an XML byte array. * * @param versioningConfiguration * The configuration to convert. * * @return The XML byte array representation. */ public byte[] convertToXmlByteArray(BucketVersioningConfiguration versioningConfiguration) { XmlWriter xml = new XmlWriter(); xml.start("VersioningConfiguration", "xmlns", Constants.XML_NAMESPACE); xml.start("Status").value(versioningConfiguration.getStatus()).end(); Boolean mfaDeleteEnabled = versioningConfiguration.isMfaDeleteEnabled(); if (mfaDeleteEnabled != null) { if (mfaDeleteEnabled) { xml.start("MfaDelete").value("Enabled").end(); } else { xml.start("MfaDelete").value("Disabled").end(); } } xml.end(); return xml.getBytes(); }
@Override public void setBucketVersioningConfiguration(SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest) throws SdkClientException, AmazonServiceException { setBucketVersioningConfigurationRequest = beforeClientExecution(setBucketVersioningConfigurationRequest); rejectNull(setBucketVersioningConfigurationRequest, "The SetBucketVersioningConfigurationRequest object must be specified when setting versioning configuration"); String bucketName = setBucketVersioningConfigurationRequest.getBucketName(); BucketVersioningConfiguration versioningConfiguration = setBucketVersioningConfigurationRequest.getVersioningConfiguration(); rejectNull(bucketName, "The bucket name parameter must be specified when setting versioning configuration"); rejectNull(versioningConfiguration, "The bucket versioning parameter must be specified when setting versioning configuration"); if (versioningConfiguration.isMfaDeleteEnabled() != null) { rejectNull(setBucketVersioningConfigurationRequest.getMfa(), "The MFA parameter must be specified when changing MFA Delete status in the versioning configuration"); } Request<SetBucketVersioningConfigurationRequest> request = createRequest(bucketName, null, setBucketVersioningConfigurationRequest, HttpMethodName.PUT); request.addParameter("versioning", null); if (versioningConfiguration.isMfaDeleteEnabled() != null) { if (setBucketVersioningConfigurationRequest.getMfa() != null) { populateRequestWithMfaDetails(request, setBucketVersioningConfigurationRequest.getMfa()); } } byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(versioningConfiguration); request.setContent(new ByteArrayInputStream(bytes)); invoke(request, voidResponseHandler, bucketName, null); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(GetBucketVersioningConfigurationRequest getBucketVersioningConfigurationRequest) throws SdkClientException, AmazonServiceException { getBucketVersioningConfigurationRequest = beforeClientExecution(getBucketVersioningConfigurationRequest); rejectNull(getBucketVersioningConfigurationRequest, "The request object parameter getBucketVersioningConfigurationRequest must be specified."); String bucketName = getBucketVersioningConfigurationRequest.getBucketName(); rejectNull(bucketName, "The bucket name parameter must be specified when querying versioning configuration"); Request<GetBucketVersioningConfigurationRequest> request = createRequest(bucketName, null, getBucketVersioningConfigurationRequest, HttpMethodName.GET); request.addParameter("versioning", null); return invoke(request, new Unmarshallers.BucketVersioningConfigurationUnmarshaller(), bucketName, null); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName) throws AmazonClientException, AmazonServiceException { return delegate.getBucketVersioningConfiguration(bucketName); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(GetBucketVersioningConfigurationRequest getBucketVersioningConfigurationRequest) throws AmazonClientException, AmazonServiceException { return delegate.getBucketVersioningConfiguration(getBucketVersioningConfigurationRequest); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName) throws AmazonClientException, AmazonServiceException { throw new UnsupportedOperationException(); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName) throws SdkClientException, AmazonServiceException { return getBucketVersioningConfiguration(new GetBucketVersioningConfigurationRequest(bucketName)); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().getBucketVersioningConfiguration(bucketName)); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(GetBucketVersioningConfigurationRequest getBucketVersioningConfigurationRequest) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().getBucketVersioningConfiguration(getBucketVersioningConfigurationRequest)); }
public static boolean checkBucketIsVersioned(String bucketName, AWSClientFactory awsClientFactory) { final BucketVersioningConfiguration bucketVersioningConfig = awsClientFactory.getS3Client().getBucketVersioningConfiguration(bucketName); return bucketVersioningConfig.getStatus().equals(BucketVersioningConfiguration.ENABLED); }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName) throws AmazonClientException { return null; }
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName) throws AmazonClientException, AmazonServiceException { // TODO Auto-generated method stub return null; }