Skip to content

Commit

Permalink
address review comments and add deleteDefaultRetention() API
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana committed Jun 3, 2020
1 parent 2250265 commit 7517d83
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 55 deletions.
28 changes: 28 additions & 0 deletions api/src/main/java/io/minio/DeleteDefaultRetentionArgs.java
Original file line number Diff line number Diff line change
@@ -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<Builder, DeleteDefaultRetentionArgs> {}
}
36 changes: 36 additions & 0 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4039,6 +4039,42 @@ public void setDefaultRetention(SetDefaultRetentionArgs args)
response.close();
}

/**
* Deletes default object retention in a bucket.
*
* <pre>Example:{@code
* minioClient.deleteDefaultRetention(
* DeleteDefaultRetentionArgs.builder().bucket("my-bucketname").build());
* }</pre>
*
* @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<String, String> 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.
*
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/io/minio/SetDefaultRetentionArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private void validateConfig(ObjectLockConfiguration config) {
}
}

@Override
protected void validate(SetDefaultRetentionArgs args) {
super.validate(args);
validateConfig(args.config);
Expand Down
53 changes: 36 additions & 17 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | |
Expand Down Expand Up @@ -373,6 +374,23 @@ minioClient.deleteBucketNotification(
DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build());
```

<a name="deleteDefaultRetention"></a>
### 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());
```

<a name="disableVersioning"></a>
### disableVersioning(DisableVersioningArgs args)
`public void disableVersioning(DisableVersioningArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#disableVersioning-io.minio.DisableVersioningArgs-)_
Expand Down Expand Up @@ -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
41 changes: 41 additions & 0 deletions examples/DeleteDefaultRetention.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
93 changes: 55 additions & 38 deletions functional/FunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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());
}
}

Expand All @@ -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);
Expand Down

0 comments on commit 7517d83

Please sign in to comment.