Skip to content

Commit

Permalink
Add arg builder to legal hold APIs (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaashish authored May 31, 2020
1 parent 8799208 commit ad41b8f
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 202 deletions.
28 changes: 28 additions & 0 deletions api/src/main/java/io/minio/DisableObjectLegalHoldArgs.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.disableObjectLegalHold(). */
public class DisableObjectLegalHoldArgs extends ObjectArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link DisableObjectLegalHoldArgs}. */
public static final class Builder
extends ObjectArgs.Builder<Builder, DisableObjectLegalHoldArgs> {}
}
28 changes: 28 additions & 0 deletions api/src/main/java/io/minio/EnableObjectLegalHoldArgs.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.enableObjectLegalHold(). */
public class EnableObjectLegalHoldArgs extends ObjectArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link EnableObjectLegalHoldArgs}. */
public static final class Builder
extends ObjectArgs.Builder<Builder, EnableObjectLegalHoldArgs> {}
}
28 changes: 28 additions & 0 deletions api/src/main/java/io/minio/IsObjectLegalHoldEnabledArgs.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.isObjectLegalHoldEnabled(). */
public class IsObjectLegalHoldEnabledArgs extends ObjectArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link IsObjectLegalHoldEnabledArgs}. */
public static final class Builder
extends ObjectArgs.Builder<Builder, IsObjectLegalHoldEnabledArgs> {}
}
149 changes: 139 additions & 10 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4201,20 +4201,60 @@ public Retention getObjectRetention(GetObjectRetentionArgs 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 #enableObjectLegalHold(EnableObjectLegalHoldArgs)}
*/
@Deprecated
public void enableObjectLegalHold(String bucketName, String objectName, String versionId)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException {
enableObjectLegalHold(
EnableObjectLegalHoldArgs.builder()
.bucket(bucketName)
.object(objectName)
.versionId(versionId)
.build());
}

/**
* Enables legal hold on an object.
*
* <pre>Example:{@code
* minioClient.enableObjectLegalHold(
* EnableObjectLegalHoldArgs.builder()
* .bucket("my-bucketname")
* .object("my-objectname")
* .versionId("object-versionId")
* .build());
* }</pre>
*
* @param args {@link EnableObjectLegalHoldArgs} 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 enableObjectLegalHold(EnableObjectLegalHoldArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException {
checkArgs(args);
Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("legal-hold", "");

if (versionId != null && !versionId.isEmpty()) {
queryParamMap.put("versionId", versionId);
if (args.versionId() != null) {
queryParamMap.put("versionId", args.versionId());
}

LegalHold legalHold = new LegalHold(true);
Response response = executePut(bucketName, objectName, null, queryParamMap, legalHold, 0);
Response response = executePut(args.bucket(), args.object(), null, queryParamMap, legalHold, 0);
response.body().close();
}

Expand All @@ -4239,21 +4279,61 @@ public void enableObjectLegalHold(String bucketName, String objectName, String v
* @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 #disableObjectLegalHold(DisableObjectLegalHoldArgs)}
*/
@Deprecated
public void disableObjectLegalHold(String bucketName, String objectName, String versionId)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException {
disableObjectLegalHold(
DisableObjectLegalHoldArgs.builder()
.bucket(bucketName)
.object(objectName)
.versionId(versionId)
.build());
}

/**
* Disables legal hold on an object.
*
* <pre>Example:{@code
* minioClient.disableObjectLegalHold(
* DisableObjectLegalHoldArgs.builder()
* .bucket("my-bucketname")
* .object("my-objectname")
* .versionId("object-versionId")
* .build());
* }</pre>
*
* @param args {@link DisableObjectLegalHoldArgs} 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 disableObjectLegalHold(DisableObjectLegalHoldArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException {
checkArgs(args);

Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("legal-hold", "");

if (versionId != null && !versionId.isEmpty()) {
queryParamMap.put("versionId", versionId);
if (args.versionId() != null) {
queryParamMap.put("versionId", args.versionId());
}

LegalHold legalHold = new LegalHold(false);

Response response = executePut(bucketName, objectName, null, queryParamMap, legalHold, 0);
Response response = executePut(args.bucket(), args.object(), null, queryParamMap, legalHold, 0);
response.body().close();
}

Expand Down Expand Up @@ -4285,19 +4365,68 @@ public void disableObjectLegalHold(String bucketName, String objectName, String
* @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 #isObjectLegalHoldEnabled(IsObjectLegalHoldEnabledArgs)}
*/
@Deprecated
public boolean isObjectLegalHoldEnabled(String bucketName, String objectName, String versionId)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException {
return isObjectLegalHoldEnabled(
IsObjectLegalHoldEnabledArgs.builder()
.bucket(bucketName)
.object(objectName)
.versionId(versionId)
.build());
}

/**
* Returns true if legal hold is enabled on an object.
*
* <pre>Example:{@code
* boolean status =
* s3Client.isObjectLegalHoldEnabled(
* IsObjectLegalHoldEnabledArgs.builder()
* .bucket("my-bucketname")
* .object("my-objectname")
* .versionId("object-versionId")
* .build());
* if (status) {
* System.out.println("Legal hold is on");
* } else {
* System.out.println("Legal hold is off");
* }
* }</pre>
*
* args {@link IsObjectLegalHoldEnabledArgs} object.
*
* @return boolean - True if legal hold is enabled.
* @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 boolean isObjectLegalHoldEnabled(IsObjectLegalHoldEnabledArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException {
checkArgs(args);

Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("legal-hold", "");

if (versionId != null && !versionId.isEmpty()) {
queryParamMap.put("versionId", versionId);
if (args.versionId() != null) {
queryParamMap.put("versionId", args.versionId());
}

try (Response response = executeGet(bucketName, objectName, null, queryParamMap)) {
try (Response response = executeGet(args.bucket(), args.object(), null, queryParamMap)) {
LegalHold result = Xml.unmarshal(LegalHold.class, response.body().charStream());
return result.status();
} catch (ErrorResponseException e) {
Expand Down
Loading

0 comments on commit ad41b8f

Please sign in to comment.