Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add arg builder to {set,get,delete}DefaultRetention APIs #935

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> {}
}
27 changes: 27 additions & 0 deletions api/src/main/java/io/minio/GetDefaultRetentionArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.getDefaultRetention(). */
public class GetDefaultRetentionArgs extends BucketArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link GetDefaultRetentionArgs}. */
public static final class Builder extends BucketArgs.Builder<Builder, GetDefaultRetentionArgs> {}
}
122 changes: 114 additions & 8 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3990,25 +3990,95 @@ public boolean isVersioningEnabled(IsVersioningEnabledArgs args)
* @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.
* @deprecated use {@link #setDefaultRetention(SetDefaultRetentionArgs)}
*/
@Deprecated
public void setDefaultRetention(String bucketName, ObjectLockConfiguration config)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
setDefaultRetention(
SetDefaultRetentionArgs.builder().bucket(bucketName).config(config).build());
}

/**
* Sets default object retention in a bucket.
*
* <pre>Example:{@code
* ObjectLockConfiguration config = new ObjectLockConfiguration(
* RetentionMode.COMPLIANCE, new RetentionDurationDays(100));
* minioClient.setDefaultRetention(
* SetDefaultRetentionArgs.builder().bucket("my-bucketname").config(config).build());
* }</pre>
*
* @param args {@link SetDefaultRetentionArgs} 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 setDefaultRetention(SetDefaultRetentionArgs 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(bucketName, null, null, queryParamMap, config, 0);
response.body().close();
Response response = executePut(args.bucket(), null, null, queryParamMap, args.config(), 0);
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.
*
* <pre>Example:{@code
* // bucket must be created with object lock enabled.
* minioClient.makeBucket("my-bucketname", null, true);
* ObjectLockConfiguration config = minioClient.getDefaultRetention("my-bucketname");
kannappanr marked this conversation as resolved.
Show resolved Hide resolved
* System.out.println("Mode: " + config.mode());
* System.out.println(
Expand All @@ -4028,19 +4098,55 @@ public void setDefaultRetention(String bucketName, ObjectLockConfiguration confi
* @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.
* @deprecated use {@link #getDefaultRetention(GetDefaultRetentionArgs)}
*/
@Deprecated
public ObjectLockConfiguration getDefaultRetention(String bucketName)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
return getDefaultRetention(GetDefaultRetentionArgs.builder().bucket(bucketName).build());
}

/**
* Gets default object retention in a bucket.
*
* <pre>Example:{@code
* ObjectLockConfiguration config =
kannappanr marked this conversation as resolved.
Show resolved Hide resolved
* minioClient.getDefaultRetention(
* GetDefaultRetentionArgs.builder().bucket("my-bucketname").build());
* System.out.println("Mode: " + config.mode());
* System.out.println(
* "Duration: " + config.duration().duration() + " " + config.duration().unit());
* }</pre>
*
* @param args {@link GetDefaultRetentionArgs} object.
* @return {@link ObjectLockConfiguration} - Default retention configuration.
* @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 ObjectLockConfiguration getDefaultRetention(GetDefaultRetentionArgs 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 = executeGet(bucketName, null, null, queryParamMap);

try (ResponseBody body = response.body()) {
return Xml.unmarshal(ObjectLockConfiguration.class, body.charStream());
try (Response response = executeGet(args.bucket(), null, null, queryParamMap)) {
return Xml.unmarshal(ObjectLockConfiguration.class, response.body().charStream());
}
}

Expand Down
53 changes: 53 additions & 0 deletions api/src/main/java/io/minio/SetDefaultRetentionArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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;

import io.minio.messages.ObjectLockConfiguration;

/** Argument class of MinioClient.setDefaultRetention(). */
public class SetDefaultRetentionArgs extends BucketArgs {
private ObjectLockConfiguration config;

public ObjectLockConfiguration config() {
return config;
}

public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link SetDefaultRetentionArgs}. */
public static final class Builder extends BucketArgs.Builder<Builder, SetDefaultRetentionArgs> {
private void validateConfig(ObjectLockConfiguration config) {
if (config == null) {
throw new IllegalArgumentException("null object-lock configuration");
}
}

@Override
protected void validate(SetDefaultRetentionArgs args) {
anjalshireesh marked this conversation as resolved.
Show resolved Hide resolved
super.validate(args);
validateConfig(args.config);
}

public Builder config(ObjectLockConfiguration config) {
validateConfig(config);
operations.add(args -> args.config = config);
return this;
}
}
}
Loading