diff --git a/api/src/main/java/io/minio/DeleteDefaultRetentionArgs.java b/api/src/main/java/io/minio/DeleteDefaultRetentionArgs.java new file mode 100644 index 000000000..dde7d6c4d --- /dev/null +++ b/api/src/main/java/io/minio/DeleteDefaultRetentionArgs.java @@ -0,0 +1,28 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.minio; + +/** Argument class of MinioClient.deleteDefaultRetention(). */ +public class DeleteDefaultRetentionArgs extends BucketArgs { + public static Builder builder() { + return new Builder(); + } + + /** Argument builder of {@link DeleteDefaultRetentionArgs}. */ + public static final class Builder + extends BucketArgs.Builder {} +} diff --git a/api/src/main/java/io/minio/MinioClient.java b/api/src/main/java/io/minio/MinioClient.java index 58553d585..9a89d15c7 100755 --- a/api/src/main/java/io/minio/MinioClient.java +++ b/api/src/main/java/io/minio/MinioClient.java @@ -4039,6 +4039,42 @@ public void setDefaultRetention(SetDefaultRetentionArgs args) response.close(); } + /** + * Deletes default object retention in a bucket. + * + *
Example:{@code
+   * minioClient.deleteDefaultRetention(
+   *     DeleteDefaultRetentionArgs.builder().bucket("my-bucketname").build());
+   * }
+ * + * @param args {@link DeleteDefaultRetentionArgs} object. + * @throws ErrorResponseException thrown to indicate S3 service returned an error response. + * @throws IllegalArgumentException throws to indicate invalid argument passed. + * @throws InsufficientDataException thrown to indicate not enough data available in InputStream. + * @throws InternalException thrown to indicate internal library error. + * @throws InvalidBucketNameException thrown to indicate invalid bucket name passed. + * @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library. + * @throws InvalidResponseException thrown to indicate S3 service returned invalid or no error + * response. + * @throws IOException thrown to indicate I/O error on S3 operation. + * @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library. + * @throws XmlParserException thrown to indicate XML parsing error. + */ + public void deleteDefaultRetention(DeleteDefaultRetentionArgs args) + throws ErrorResponseException, IllegalArgumentException, InsufficientDataException, + InternalException, InvalidBucketNameException, InvalidKeyException, + InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException, + XmlParserException { + checkArgs(args); + + Map queryParamMap = new HashMap<>(); + queryParamMap.put("object-lock", ""); + + Response response = + executePut(args.bucket(), null, null, queryParamMap, new ObjectLockConfiguration(), 0); + response.close(); + } + /** * Gets default object retention in a bucket. * diff --git a/api/src/main/java/io/minio/SetDefaultRetentionArgs.java b/api/src/main/java/io/minio/SetDefaultRetentionArgs.java index 5f4ad39fa..dcf84e9e6 100644 --- a/api/src/main/java/io/minio/SetDefaultRetentionArgs.java +++ b/api/src/main/java/io/minio/SetDefaultRetentionArgs.java @@ -38,6 +38,7 @@ private void validateConfig(ObjectLockConfiguration config) { } } + @Override protected void validate(SetDefaultRetentionArgs args) { super.validate(args); validateConfig(args.config); diff --git a/docs/API.md b/docs/API.md index 095ed7ec5..516757aee 100644 --- a/docs/API.md +++ b/docs/API.md @@ -24,23 +24,24 @@ MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", | [`deleteBucketNotification`](#deleteBucketNotification) | [`disableObjectLegalHold`](#disableObjectLegalHold) | | [`deleteBucketPolicy`](#deleteBucketPolicy) | [`downloadObject`](#downloadObject) | | [`deleteBucketTags`](#deleteBucketTags) | [`enableObjectLegalHold`](#enableObjectLegalHold) | -| [`disableVersioning`](#disableVersioning) | [`getObject`](#getObject) | -| [`enableVersioning`](#enableVersioning) | [`getObjectRetention`](#getObjectRetention) | -| [`getBucketEncryption`](#getBucketEncryption) | [`getObjectTags`](#getObjectTags) | -| [`getBucketLifeCycle`](#getBucketLifeCycle) | [`getObjectUrl`](#getObjectUrl) | -| [`getBucketNotification`](#getBucketNotification) | [`getPresignedObjectUrl`](#getPresignedObjectUrl) | -| [`getBucketPolicy`](#getBucketPolicy) | [`isObjectLegalHoldEnabled`](#isObjectLegalHoldEnabled) | -| [`getBucketTags`](#getBucketTags) | [`listObjects`](#listObjects) | -| [`getDefaultRetention`](#getDefaultRetention) | [`presignedGetObject`](#presignedGetObject) | -| [`isVersioningEnabled`](#isVersioningEnabled) | [`presignedPostPolicy`](#presignedPostPolicy) | -| [`listBuckets`](#listBuckets) | [`presignedPutObject`](#presignedPutObject) | -| [`listenBucketNotification`](#listenBucketNotification) | [`putObject`](#putObject) | -| [`listIncompleteUploads`](#listIncompleteUploads) | [`removeObject`](#removeObject) | -| [`makeBucket`](#makeBucket) | [`removeObjects`](#removeObjects) | -| [`removeBucket`](#removeBucket) | [`selectObjectContent`](#selectObjectContent) | -| [`removeIncompleteUpload`](#removeIncompleteUpload) | [`setObjectRetention`](#setObjectRetention) | -| [`setBucketEncryption`](#setBucketEncryption) | [`setObjectTags`](#setObjectTags) | -| [`setBucketLifeCycle`](#setBucketLifeCycle) | [`statObject`](#statObject) | +| [`deleteDefaultRetention`](#deleteDefaultRetention) | [`getObject`](#getObject) | +| [`disableVersioning`](#disableVersioning) | [`getObjectRetention`](#getObjectRetention) | +| [`enableVersioning`](#enableVersioning) | [`getObjectTags`](#getObjectTags) | +| [`getBucketEncryption`](#getBucketEncryption) | [`getObjectUrl`](#getObjectUrl) | +| [`getBucketLifeCycle`](#getBucketLifeCycle) | [`getPresignedObjectUrl`](#getPresignedObjectUrl) | +| [`getBucketNotification`](#getBucketNotification) | [`isObjectLegalHoldEnabled`](#isObjectLegalHoldEnabled) | +| [`getBucketPolicy`](#getBucketPolicy) | [`listObjects`](#listObjects) | +| [`getBucketTags`](#getBucketTags) | [`presignedGetObject`](#presignedGetObject) | +| [`getDefaultRetention`](#getDefaultRetention) | [`presignedPostPolicy`](#presignedPostPolicy) | +| [`isVersioningEnabled`](#isVersioningEnabled) | [`presignedPutObject`](#presignedPutObject) | +| [`listBuckets`](#listBuckets) | [`putObject`](#putObject) | +| [`listenBucketNotification`](#listenBucketNotification) | [`removeObject`](#removeObject) | +| [`listIncompleteUploads`](#listIncompleteUploads) | [`removeObjects`](#removeObjects) | +| [`makeBucket`](#makeBucket) | [`selectObjectContent`](#selectObjectContent) | +| [`removeBucket`](#removeBucket) | [`setObjectRetention`](#setObjectRetention) | +| [`removeIncompleteUpload`](#removeIncompleteUpload) | [`setObjectTags`](#setObjectTags) | +| [`setBucketEncryption`](#setBucketEncryption) | [`statObject`](#statObject) | +| [`setBucketLifeCycle`](#setBucketLifeCycle) | | | [`setBucketNotification`](#setBucketNotification) | | | [`setBucketPolicy`](#setBucketPolicy) | | | [`setBucketTags`](#setBucketTags) | | @@ -373,6 +374,23 @@ minioClient.deleteBucketNotification( DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build()); ``` + +### deleteDefaultRetention(DeleteDefaultRetentionArgs args) +`public void deleteDefaultRetention(DeleteDefaultRetentionArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#deleteDefaultRetention-io.minio.DeleteDefaultRetentionArgs-)_ + +Deletes default object retention in a bucket. + +__Parameters__ +| Parameter | Type | Description | +|:----------|:-------------------------------|:------------| +| ``args`` | _[DeleteDefaultRetentionArgs]_ | Arguments. | + +__Example__ +```java +minioClient.deleteDefaultRetention( + DeleteDefaultRetentionArgs.builder().bucket("my-bucketname").build()); +``` + ### disableVersioning(DisableVersioningArgs args) `public void disableVersioning(DisableVersioningArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#disableVersioning-io.minio.DisableVersioningArgs-)_ @@ -1802,3 +1820,4 @@ ObjectStat objectStat = [SelectObjectContentArgs]: http://minio.github.io/minio-java/io/minio/SelectObjectContentArgs.html [GetDefaultRetentionArgs]: http://minio.github.io/minio-java/io/minio/GetDefaultRetentionArgs.html [SetDefaultRetentionArgs]: http://minio.github.io/minio-java/io/minio/SetDefaultRetentionArgs.html +[DeleteDefaultRetentionArgs]: http://minio.github.io/minio-java/io/minio/DeleteDefaultRetentionArgs.html diff --git a/examples/DeleteDefaultRetention.java b/examples/DeleteDefaultRetention.java new file mode 100644 index 000000000..7d0f6c688 --- /dev/null +++ b/examples/DeleteDefaultRetention.java @@ -0,0 +1,41 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import io.minio.DeleteDefaultRetentionArgs; +import io.minio.MinioClient; +import io.minio.errors.MinioException; +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +public class DeleteDefaultRetention { + /** MinioClient.deleteDefaultRetention() exanple. */ + public static void main(String[] args) + throws IOException, NoSuchAlgorithmException, InvalidKeyException { + try { + /* Amazon S3: */ + MinioClient s3Client = + new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY"); + + s3Client.deleteDefaultRetention( + DeleteDefaultRetentionArgs.builder().bucket("my-lock-enabled-bucketname").build()); + + System.out.println("Default retention configuration is deleted successfully"); + } catch (MinioException e) { + System.out.println("Error occurred: " + e); + } + } +} diff --git a/functional/FunctionalTest.java b/functional/FunctionalTest.java index ad72d0e2c..f0cc5d164 100644 --- a/functional/FunctionalTest.java +++ b/functional/FunctionalTest.java @@ -28,6 +28,7 @@ import io.minio.DeleteBucketNotificationArgs; import io.minio.DeleteBucketPolicyArgs; import io.minio.DeleteBucketTagsArgs; +import io.minio.DeleteDefaultRetentionArgs; import io.minio.DeleteObjectTagsArgs; import io.minio.DisableObjectLegalHoldArgs; import io.minio.DisableVersioningArgs; @@ -86,6 +87,7 @@ import io.minio.messages.QueueConfiguration; import io.minio.messages.QuoteFields; import io.minio.messages.Retention; +import io.minio.messages.RetentionDuration; import io.minio.messages.RetentionDurationDays; import io.minio.messages.RetentionDurationYears; import io.minio.messages.RetentionMode; @@ -3592,7 +3594,7 @@ public static void setDefaultRetention_test() throws Exception { long startTime = System.currentTimeMillis(); String bucketName = getRandomName(); - + String mintArgs = "config={COMPLIANCE, 10 days}"; try { client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).objectLock(true).build()); try { @@ -3603,9 +3605,29 @@ public static void setDefaultRetention_test() throws Exception { } finally { client.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); } - mintSuccessLog(methodName, null, startTime); + mintSuccessLog(methodName, mintArgs, startTime); } catch (Exception e) { - handleException(methodName, null, startTime, e); + handleException(methodName, mintArgs, startTime, e); + } + } + + public static void testGetDefaultRetention( + String bucketName, RetentionMode mode, RetentionDuration duration) throws Exception { + ObjectLockConfiguration expectedConfig = new ObjectLockConfiguration(mode, duration); + client.setDefaultRetention( + SetDefaultRetentionArgs.builder().bucket(bucketName).config(expectedConfig).build()); + ObjectLockConfiguration config = + client.getDefaultRetention(GetDefaultRetentionArgs.builder().bucket(bucketName).build()); + + if (config.mode() != expectedConfig.mode()) { + throw new Exception( + "[FAILED] mode: expected: " + expectedConfig.mode() + ", got: " + config.mode()); + } + + if (config.duration().unit() != expectedConfig.duration().unit() + || config.duration().duration() != expectedConfig.duration().duration()) { + throw new Exception( + "[FAILED] duration: " + expectedConfig.duration() + ", got: " + config.duration()); } } @@ -3621,48 +3643,43 @@ public static void getDefaultRetention_test() throws Exception { try { client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).objectLock(true).build()); try { - ObjectLockConfiguration expectedConfig = - new ObjectLockConfiguration(RetentionMode.COMPLIANCE, new RetentionDurationDays(10)); - client.setDefaultRetention( - SetDefaultRetentionArgs.builder().bucket(bucketName).config(expectedConfig).build()); - ObjectLockConfiguration config = - client.getDefaultRetention( - GetDefaultRetentionArgs.builder().bucket(bucketName).build()); + testGetDefaultRetention( + bucketName, RetentionMode.COMPLIANCE, new RetentionDurationDays(10)); + testGetDefaultRetention( + bucketName, RetentionMode.GOVERNANCE, new RetentionDurationYears(1)); + } finally { + client.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); + } - if (config.mode() != expectedConfig.mode()) { - throw new Exception( - "[FAILED] mode: expected: " + expectedConfig.mode() + ", got: " + config.mode()); - } + mintSuccessLog(methodName, null, startTime); + } catch (Exception e) { + handleException(methodName, null, startTime, e); + } + } - if (config.duration().unit() != expectedConfig.duration().unit() - || config.duration().duration() != expectedConfig.duration().duration()) { - throw new Exception( - "[FAILED] duration: " + expectedConfig.duration() + ", got: " + config.duration()); - } + /** Test: deleteDefaultRetention(DeleteDefaultRetentionArgs args). */ + public static void deleteDefaultRetention_test() throws Exception { + String methodName = "deleteDefaultRetention(DeleteDefaultRetentionArgs args)"; + if (!mintEnv) { + System.out.println("Test: " + methodName); + } - expectedConfig = - new ObjectLockConfiguration(RetentionMode.GOVERNANCE, new RetentionDurationYears(1)); + long startTime = System.currentTimeMillis(); + String bucketName = getRandomName(); + try { + client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).objectLock(true).build()); + try { + client.deleteDefaultRetention( + DeleteDefaultRetentionArgs.builder().bucket(bucketName).build()); + ObjectLockConfiguration config = + new ObjectLockConfiguration(RetentionMode.COMPLIANCE, new RetentionDurationDays(10)); client.setDefaultRetention( - SetDefaultRetentionArgs.builder().bucket(bucketName).config(expectedConfig).build()); - config = - client.getDefaultRetention( - GetDefaultRetentionArgs.builder().bucket(bucketName).build()); - - if (config.mode() != expectedConfig.mode()) { - throw new Exception( - "[FAILED] mode: expected: " + expectedConfig.mode() + ", got: " + config.mode()); - } - - if (config.duration().unit() != expectedConfig.duration().unit() - || config.duration().duration() != expectedConfig.duration().duration()) { - throw new Exception( - "[FAILED] duration: " + expectedConfig.duration() + ", got: " + config.duration()); - } - + SetDefaultRetentionArgs.builder().bucket(bucketName).config(config).build()); + client.deleteDefaultRetention( + DeleteDefaultRetentionArgs.builder().bucket(bucketName).build()); } finally { client.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); } - mintSuccessLog(methodName, null, startTime); } catch (Exception e) { handleException(methodName, null, startTime, e);