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 {set,get}BucketVersioning APIs #1053

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 0 additions & 27 deletions api/src/main/java/io/minio/EnableVersioningArgs.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package io.minio;

/** Argument class of MinioClient.disableVersioning(). */
public class DisableVersioningArgs extends BucketArgs {
/** Argument class of MinioClient.getBucketVersioning(). */
public class GetBucketVersioningArgs extends BucketArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link DisableVersioningArgs}. */
public static final class Builder extends BucketArgs.Builder<Builder, DisableVersioningArgs> {}
/** Argument builder of {@link GetBucketVersioningArgs}. */
public static final class Builder extends BucketArgs.Builder<Builder, GetBucketVersioningArgs> {}
}
27 changes: 0 additions & 27 deletions api/src/main/java/io/minio/IsVersioningEnabledArgs.java

This file was deleted.

127 changes: 14 additions & 113 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3984,13 +3984,14 @@ public void makeBucket(MakeBucketArgs args)
}

/**
* Enables object versioning feature in a bucket.
* Sets versioning configuration of a bucket.
*
* <pre>Example:{@code
* minioClient.enableVersioning("my-bucketname");
* minioClient.setBucketVersioning(
* SetBucketVersioningArgs.builder().bucket("my-bucketname").config(config).build());
* }</pre>
*
* @param bucketName Name of the bucket.
* @param args {@link SetBucketVersioningArgs} 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.
Expand All @@ -4002,56 +4003,28 @@ public void makeBucket(MakeBucketArgs 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 #enableVersioning(EnableVersioningArgs)}
*/
@Deprecated
public void enableVersioning(String bucketName)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
this.enableVersioning(EnableVersioningArgs.builder().bucket(bucketName).build());
}

/**
* Enables object versioning feature in a bucket.
*
* <pre>Example:{@code
* minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucketname").build());
* }</pre>
*
* @param args {@link EnableVersioningArgs} 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 enableVersioning(EnableVersioningArgs args)
public void setBucketVersioning(SetBucketVersioningArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
checkArgs(args);
Response response =
executePut(args, null, newMultimap("versioning", ""), new VersioningConfiguration(true), 0);
Response response = executePut(args, null, newMultimap("versioning", ""), args.config(), 0);
response.close();
}

/**
* Disables object versioning feature in a bucket.
* Gets versioning configuration of a bucket.
*
* <pre>Example:{@code
* minioClient.disableVersioning("my-bucketname");
* VersioningConfiguration config =
* minioClient.getBucketVersioning(
* GetBucketVersioningArgs.builder().bucket("my-bucketname").build());
* }</pre>
*
* @param bucketName Name of the bucket.
* @param args {@link GetBucketVersioningArgs} object.
* @return {@link VersioningConfiguration} - Versioning 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.
Expand All @@ -4063,87 +4036,15 @@ public void enableVersioning(EnableVersioningArgs 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 #disableVersioning(DisableVersioningArgs)}
*/
@Deprecated
public void disableVersioning(String bucketName)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
this.disableVersioning(DisableVersioningArgs.builder().bucket(bucketName).build());
}

/**
* Disables object versioning feature in a bucket.
*
* <pre>Example:{@code
* minioClient.disableVersioning(
* DisableVersioningArgs.builder().bucket("my-bucketname").build());
* }</pre>
*
* @param args {@link DisableVersioningArgs} 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 disableVersioning(DisableVersioningArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
checkArgs(args);
Response response =
executePut(
args, null, newMultimap("versioning", ""), new VersioningConfiguration(false), 0);
response.close();
}

/**
* Returns true if versioning is enabled on the bucket.
*
* <pre>Example:{@code
* boolean isVersioningEnabled =
* minioClient.isVersioningEnabled(
* IsVersioningEnabledArgs.builder().bucket("my-bucketname").build());
* if (isVersioningEnabled) {
* System.out.println("Bucket versioning is enabled");
* } else {
* System.out.println("Bucket versioning is disabled");
* }
* }</pre>
*
* @param args {@link IsVersioningEnabledArgs} 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 boolean isVersioningEnabled(IsVersioningEnabledArgs args)
public VersioningConfiguration getBucketVersioning(GetBucketVersioningArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
checkArgs(args);
try (Response response = executeGet(args, null, newMultimap("versioning", ""))) {
VersioningConfiguration result =
Xml.unmarshal(VersioningConfiguration.class, response.body().charStream());
return result.status();
return Xml.unmarshal(VersioningConfiguration.class, response.body().charStream());
}
}

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

/** Argument class of MinioClient.setBucketVersioning(). */
public class SetBucketVersioningArgs extends BucketArgs {
private VersioningConfiguration config;

public VersioningConfiguration config() {
return config;
}

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

/** Argument builder of {@link SetBucketVersioningArgs}. */
public static final class Builder extends BucketArgs.Builder<Builder, SetBucketVersioningArgs> {
private void validateConfig(VersioningConfiguration config) {
validateNotNull(config, "versioning configuration");
anjalshireesh marked this conversation as resolved.
Show resolved Hide resolved
}

protected void validate(SetBucketVersioningArgs args) {
super.validate(args);
validateConfig(args.config);
}

public Builder config(VersioningConfiguration config) {
validateConfig(config);
operations.add(args -> args.config = config);
return this;
}
}
}
58 changes: 50 additions & 8 deletions api/src/main/java/io/minio/messages/VersioningConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.minio.messages;

import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
Expand All @@ -33,19 +36,58 @@ public class VersioningConfiguration {
@Element(name = "Status", required = false)
private String status;

@Element(name = "MFADelete", required = false)
private String mfaDelete;

public VersioningConfiguration() {}

/** Constructs a new VersioningConfiguration object with given status. */
public VersioningConfiguration(boolean status) {
if (status) {
this.status = "Enabled";
} else {
this.status = "Suspended";
public VersioningConfiguration(@Nonnull Status status, @Nullable Boolean mfaDelete) {
Objects.requireNonNull(status, "Status must not be null");
if (status == Status.OFF) {
throw new IllegalArgumentException("Status must be ENABLED or SUSPENDED");
}
this.status = status.toString();

if (mfaDelete != null) {
this.mfaDelete = mfaDelete ? "Enabled" : "Disabled";
}
}

/** Indicates whether the bucket is version enabled or not. */
public boolean status() {
return ("Enabled").equals(status);
public Status status() {
return Status.fromString(status);
}

public Boolean isMfaDeleteEnabled() {
Boolean flag = (mfaDelete != null) ? Boolean.valueOf("Enabled".equals(mfaDelete)) : null;
return flag;
kannappanr marked this conversation as resolved.
Show resolved Hide resolved
}

public static enum Status {
OFF(""),
ENABLED("Enabled"),
SUSPENDED("Suspended");

private final String value;

private Status(String value) {
this.value = value;
}

public String toString() {
return this.value;
}

public static Status fromString(String statusString) {
if ("Enabled".equals(statusString)) {
return ENABLED;
}

if ("Suspended".equals(statusString)) {
return SUSPENDED;
}

return OFF;
}
}
}
Loading