diff --git a/api/src/main/java/io/minio/EnableVersioningArgs.java b/api/src/main/java/io/minio/EnableVersioningArgs.java deleted file mode 100644 index 24df37d2e..000000000 --- a/api/src/main/java/io/minio/EnableVersioningArgs.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.enableVersioning(). */ -public class EnableVersioningArgs extends BucketArgs { - public static Builder builder() { - return new Builder(); - } - - /** Argument builder of {@link EnableVersioningArgs}. */ - public static final class Builder extends BucketArgs.Builder {} -} diff --git a/api/src/main/java/io/minio/DisableVersioningArgs.java b/api/src/main/java/io/minio/GetBucketVersioningArgs.java similarity index 78% rename from api/src/main/java/io/minio/DisableVersioningArgs.java rename to api/src/main/java/io/minio/GetBucketVersioningArgs.java index e3ae4125c..d1fce29de 100644 --- a/api/src/main/java/io/minio/DisableVersioningArgs.java +++ b/api/src/main/java/io/minio/GetBucketVersioningArgs.java @@ -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 {} + /** Argument builder of {@link GetBucketVersioningArgs}. */ + public static final class Builder extends BucketArgs.Builder {} } diff --git a/api/src/main/java/io/minio/IsVersioningEnabledArgs.java b/api/src/main/java/io/minio/IsVersioningEnabledArgs.java deleted file mode 100644 index a0693ef6d..000000000 --- a/api/src/main/java/io/minio/IsVersioningEnabledArgs.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.isVersioningEnabled(). */ -public class IsVersioningEnabledArgs extends BucketArgs { - public static Builder builder() { - return new Builder(); - } - - /** Argument builder of {@link IsVersioningEnabledArgs}. */ - 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 d2e8db636..acf85a751 100644 --- a/api/src/main/java/io/minio/MinioClient.java +++ b/api/src/main/java/io/minio/MinioClient.java @@ -3984,13 +3984,14 @@ public void makeBucket(MakeBucketArgs args) } /** - * Enables object versioning feature in a bucket. + * Sets versioning configuration of a bucket. * *
Example:{@code
-   * minioClient.enableVersioning("my-bucketname");
+   * minioClient.setBucketVersioning(
+   *     SetBucketVersioningArgs.builder().bucket("my-bucketname").config(config).build());
    * }
* - * @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. @@ -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. - * - *
Example:{@code
-   * minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucketname").build());
-   * }
- * - * @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. * *
Example:{@code
-   * minioClient.disableVersioning("my-bucketname");
+   * VersioningConfiguration config =
+   *     minioClient.getBucketVersioning(
+   *         GetBucketVersioningArgs.builder().bucket("my-bucketname").build());
    * }
* - * @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. @@ -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. - * - *
Example:{@code
-   * minioClient.disableVersioning(
-   *     DisableVersioningArgs.builder().bucket("my-bucketname").build());
-   * }
- * - * @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. - * - *
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");
-   * }
-   * }
- * - * @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()); } } diff --git a/api/src/main/java/io/minio/SetBucketVersioningArgs.java b/api/src/main/java/io/minio/SetBucketVersioningArgs.java new file mode 100644 index 000000000..1802039f6 --- /dev/null +++ b/api/src/main/java/io/minio/SetBucketVersioningArgs.java @@ -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 { + private void validateConfig(VersioningConfiguration config) { + validateNotNull(config, "versioning configuration"); + } + + 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; + } + } +} diff --git a/api/src/main/java/io/minio/messages/VersioningConfiguration.java b/api/src/main/java/io/minio/messages/VersioningConfiguration.java index 08a146acb..7a1e87d2c 100644 --- a/api/src/main/java/io/minio/messages/VersioningConfiguration.java +++ b/api/src/main/java/io/minio/messages/VersioningConfiguration.java @@ -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; @@ -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; + } + + 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; + } } } diff --git a/docs/API.md b/docs/API.md index 25c10fb2f..86bc4b193 100644 --- a/docs/API.md +++ b/docs/API.md @@ -32,28 +32,27 @@ MinioClient minioClient = | [`deleteBucketReplication`](#deleteBucketReplication) | [`enableObjectLegalHold`](#enableObjectLegalHold) | | [`deleteBucketTags`](#deleteBucketTags) | [`getObject`](#getObject) | | [`deleteObjectLockConfiguration`](#deleteObjectLockConfiguration) | [`getObjectRetention`](#getObjectRetention) | -| [`disableVersioning`](#disableVersioning) | [`getObjectTags`](#getObjectTags) | -| [`enableVersioning`](#enableVersioning) | [`getObjectUrl`](#getObjectUrl) | -| [`getBucketEncryption`](#getBucketEncryption) | [`getPresignedObjectUrl`](#getPresignedObjectUrl) | -| [`getBucketLifeCycle`](#getBucketLifeCycle) | [`getPresignedPostFormData`](#getPresignedPostFormData) | -| [`getBucketNotification`](#getBucketNotification) | [`isObjectLegalHoldEnabled`](#isObjectLegalHoldEnabled) | -| [`getBucketPolicy`](#getBucketPolicy) | [`listObjects`](#listObjects) | -| [`getBucketReplication`](#getBucketReplication) | [`putObject`](#putObject) | -| [`getBucketTags`](#getBucketTags) | [`removeObject`](#removeObject) | -| [`getObjectLockConfiguration`](#getObjectLockConfiguration) | [`removeObjects`](#removeObjects) | -| [`isVersioningEnabled`](#isVersioningEnabled) | [`selectObjectContent`](#selectObjectContent) | -| [`listBuckets`](#listBuckets) | [`setObjectRetention`](#setObjectRetention) | -| [`listenBucketNotification`](#listenBucketNotification) | [`setObjectTags`](#setObjectTags) | -| [`listIncompleteUploads`](#listIncompleteUploads) | [`statObject`](#statObject) | -| [`makeBucket`](#makeBucket) | [`uploadObject`](#uploadObject) | -| [`removeBucket`](#removeBucket) | | -| [`removeIncompleteUpload`](#removeIncompleteUpload) | | +| [`getBucketEncryption`](#getBucketEncryption) | [`getObjectTags`](#getObjectTags) | +| [`getBucketLifeCycle`](#getBucketLifeCycle) | [`getObjectUrl`](#getObjectUrl) | +| [`getBucketNotification`](#getBucketNotification) | [`getPresignedObjectUrl`](#getPresignedObjectUrl) | +| [`getBucketPolicy`](#getBucketPolicy) | [`getPresignedPostFormData`](#getPresignedPostFormData) | +| [`getBucketReplication`](#getBucketReplication) | [`isObjectLegalHoldEnabled`](#isObjectLegalHoldEnabled) | +| [`getBucketTags`](#getBucketTags) | [`listObjects`](#listObjects) | +| [`getBucketVersioning`](#getBucketVersioning) | [`putObject`](#putObject) | +| [`getObjectLockConfiguration`](#getObjectLockConfiguration) | [`removeObject`](#removeObject) | +| [`listBuckets`](#listBuckets) | [`removeObjects`](#removeObjects) | +| [`listenBucketNotification`](#listenBucketNotification) | [`selectObjectContent`](#selectObjectContent) | +| [`listIncompleteUploads`](#listIncompleteUploads) | [`setObjectRetention`](#setObjectRetention) | +| [`makeBucket`](#makeBucket) | [`setObjectTags`](#setObjectTags) | +| [`removeBucket`](#removeBucket) | [`statObject`](#statObject) | +| [`removeIncompleteUpload`](#removeIncompleteUpload) | [`uploadObject`](#uploadObject) | | [`setBucketEncryption`](#setBucketEncryption) | | | [`setBucketLifeCycle`](#setBucketLifeCycle) | | | [`setBucketNotification`](#setBucketNotification) | | | [`setBucketPolicy`](#setBucketPolicy) | | | [`setBucketReplication`](#setBucketReplication) | | | [`setBucketTags`](#setBucketTags) | | +| [`setBucketVersioning`](#setBucketVersioning) | | | [`setObjectLockConfiguration`](#setObjectLockConfiguration) | | ## 1. MinIO Client Builder @@ -373,68 +372,6 @@ minioClient.deleteObjectLockConfiguration( DeleteObjectLockConfigurationArgs.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-)_ - -Disables object versioning feature in a bucket. - -__Parameters__ - -| Parameter | Type | Description | -|:-----------|:---------------------------|:-----------------| -| ``args`` | _[DisableVersioningArgs]_ | Arguments. | - -__Example__ -```java -minioClient.disableVersioning(DisableVersioningArgs.builder().bucket("my-bucket").build()); -``` - - -### enableVersioning(EnableVersioningArgs args) -`public void enableVersioning(EnableVersioningArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#enableVersioning-io.minio.EnableVersioningArgs-)_ - -Enables object versioning feature in a bucket. - -__Parameters__ - -| Parameter | Type | Description | -|:-----------|:--------------------------|:-----------------| -| ``args`` | _[EnableVersioningArgs]_ | Arguments. | - -__Example__ -```java -minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucket").build()); -``` - - -### isVersioningEnabled(IsVersioningEnabledArgs args) -`public boolean isVersioningEnabled(IsVersioningEnabledArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#isVersioningEnabled-io.minio.IsVersioningEnabledArgs-)_ - -Get bucket version status. - -__Parameters__ - -| Parameter | Type | Description | -|:-----------|:-----------------------------|:-----------------| -| ``args`` | _[IsVersioningEnabledArgs]_ | Arguments. | - -| Returns | -|:--------------------------------------------------| -| _boolean_ - True if bucket versioning is enabled. | - -__Example__ -```java -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"); -} -``` - ### getBucketEncryption(GetBucketEncryptionArgs args) `public SseConfiguration getBucketEncryption(GetBucketEncryptionArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#getBucketEncryption-io.minio.GetBucketEncryptionArgs-)_ @@ -568,6 +505,28 @@ __Example__ Tags tags = minioClient.getBucketTags(GetBucketTagsArgs.builder().bucket("my-bucketname").build()); ``` + +### getBucketVersioning(GetBucketVersioningArgs args) +`public VersioningConfiguration getBucketVersioning(GetBucketVersioningArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#getBucketVersioning-io.minio.GetBucketVersioningArgs-)_ + +Gets versioning configuration of a bucket. + +__Parameters__ +| Parameter | Type | Description | +|:----------|:----------------------------|:------------| +| ``args`` | _[GetBucketVersioningArgs]_ | Arguments. | + +| Returns | +|:--------------------------------------------------------| +| _[VersioningConfiguration]_ - Versioning configuration. | + +__Example__ +```java +VersioningConfiguration config = + minioClient.getBucketVersioning( + GetBucketVersioningArgs.builder().bucket("my-bucketname").build()); +``` + ### getObjectLockConfiguration(GetObjectLockConfigurationArgs args) `public ObjectLockConfiguration getObjectLockConfiguration(GetObjectLockConfigurationArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#getObjectLockConfiguration-io.minio.GetObjectLockConfigurationArgs-)_ @@ -1039,6 +998,23 @@ map.put("User", "jsmith"); minioClient.setBucketTags(SetBucketTagsArgs.builder().bucket("my-bucketname").tags(map).build()); ``` + +### setBucketVersioning(SetBucketVersioningArgs args) +`public void setBucketVersioning(SetBucketVersioningArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#setBucketVersioning-io.minio.SetBucketVersioningArgs-)_ + +Sets versioning configuration of a bucket. + +__Parameters__ +| Parameter | Type | Description | +|:----------|:----------------------------|:------------| +| ``args`` | _[SetBucketVersioningArgs]_ | Arguments. | + +__Example__ +```java +minioClient.setBucketVersioning( + SetBucketVersioningArgs.builder().bucket("my-bucketname").config(config).build()); + ``` + ### setObjectLockConfiguration(SetObjectLockConfigurationArgs args) `public void setObjectLockConfiguration(SetObjectLockConfigurationArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#setObjectLockConfiguration-io.minio.SetObjectLockConfigurationArgs-)_ @@ -1901,8 +1877,6 @@ ObjectStat objectStat = [MakeBucketArgs]: http://minio.github.io/minio-java/io/minio/MakeBucketArgs.html [ListObjectsArgs]: http://minio.github.io/minio-java/io/minio/ListObjectsArgs.html [RemoveBucketArgs]: http://minio.github.io/minio-java/io/minio/RemoveBucketArgs.html -[EnableVersioningArgs]: http://minio.github.io/minio-java/io/minio/EnableVersioningArgs.html -[DisableVersioningArgs]: http://minio.github.io/minio-java/io/minio/DisableVersioningArgs.html [SetObjectRetentionArgs]: http://minio.github.io/minio-java/io/minio/SetObjectRetentionArgs.html [GetObjectRetentionArgs]: http://minio.github.io/minio-java/io/minio/GetObjectRetentionArgs.html [Method]: http://minio.github.io/minio-java/io/minio/http/Method.html @@ -1927,7 +1901,6 @@ ObjectStat objectStat = [DeleteBucketPolicyArgs]: http://minio.github.io/minio-java/io/minio/DeleteBucketPolicyArgs.html [GetObjectArgs]: http://minio.github.io/minio-java/io/minio/GetObjectArgs.html [DownloadObjectArgs]: http://minio.github.io/minio-java/io/minio/DownloadObjectArgs.html -[IsVersioningEnabledArgs]: http://minio.github.io/minio-java/io/minio/IsVersioningEnabledArgs.html [BucketExistsArgs]: http://minio.github.io/minio-java/io/minio/BucketExistsArgs.html [EnableObjectLegalHoldArgs]: http://minio.github.io/minio-java/io/minio/EnableObjectLegalHoldArgs.html [DisableObjectLegalHoldArgs]: http://minio.github.io/minio-java/io/minio/DisableObjectLegalHoldArgs.html @@ -1954,3 +1927,6 @@ ObjectStat objectStat = [GetBucketReplicationArgs]: http://minio.github.io/minio-java/io/minio/GetBucketReplicationArgs.html [SetBucketReplicationArgs]: http://minio.github.io/minio-java/io/minio/SetBucketReplicationArgs.html [ReplicationConfiguration]: http://minio.github.io/minio-java/io/minio/messages/ReplicationConfiguration.html +[VersioningConfiguration]: http://minio.github.io/minio-java/io/minio/messages/VersioningConfiguration.html +[GetBucketVersioningArgs]: http://minio.github.io/minio-java/io/minio/GetBucketVersioningArgs.html +[SetBucketVersioningArgs]: http://minio.github.io/minio-java/io/minio/SetBucketVersioningArgs.html diff --git a/examples/EnableVersioning.java b/examples/GetBucketVersioning.java similarity index 78% rename from examples/EnableVersioning.java rename to examples/GetBucketVersioning.java index 8268c90be..e34682957 100644 --- a/examples/EnableVersioning.java +++ b/examples/GetBucketVersioning.java @@ -14,15 +14,16 @@ * limitations under the License. */ -import io.minio.EnableVersioningArgs; +import io.minio.GetBucketVersioningArgs; import io.minio.MinioClient; import io.minio.errors.MinioException; +import io.minio.messages.VersioningConfiguration; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -public class EnableVersioning { - /** MinioClient.enableVersioning() example. */ +public class GetBucketVersioning { + /** MinioClient.getBucketVersioning() example. */ public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException { try { @@ -40,11 +41,10 @@ public static void main(String[] args) // .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY") // .build(); - // Enable versioning on 'my-bucketname'. - minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucketname").build()); - - System.out.println("Bucket versioning is enabled successfully"); - + VersioningConfiguration config = + minioClient.getBucketVersioning( + GetBucketVersioningArgs.builder().bucket("my-bucketname").build()); + System.out.println("Versioning on bucket 'my-bucketname' is " + config.status()); } catch (MinioException e) { System.out.println("Error occurred: " + e); } diff --git a/examples/IsVersioningEnabled.java b/examples/IsVersioningEnabled.java deleted file mode 100644 index 5050d176a..000000000 --- a/examples/IsVersioningEnabled.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 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.BucketExistsArgs; -import io.minio.EnableVersioningArgs; -import io.minio.IsVersioningEnabledArgs; -import io.minio.MakeBucketArgs; -import io.minio.MinioClient; -import io.minio.errors.MinioException; -import java.io.IOException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -public class IsVersioningEnabled { - /** MinioClient.isVersioningEnabled() example. */ - public static void main(String[] args) - throws IOException, NoSuchAlgorithmException, InvalidKeyException { - try { - /* play.min.io for test and development. */ - MinioClient minioClient = - MinioClient.builder() - .endpoint("https://play.min.io") - .credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG") - .build(); - - /* Amazon S3: */ - // MinioClient minioClient = - // MinioClient.builder() - // .endpoint("https://s3.amazonaws.com") - // .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY") - // .build(); - - // Create bucket 'my-bucketname' if it doesn`t exist. - if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket("my-bucketname").build())) { - minioClient.makeBucket(MakeBucketArgs.builder().bucket("my-bucketname").build()); - System.out.println("my-bucketname is created successfully"); - } - - 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"); - } - // Enable versioning on 'my-bucketname'. - minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucketname").build()); - System.out.println("Bucket versioning is enabled successfully"); - - 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"); - } - - } catch (MinioException e) { - System.out.println("Error occurred: " + e); - } - } -} diff --git a/examples/DisableVersioning.java b/examples/SetBucketVersioning.java similarity index 63% rename from examples/DisableVersioning.java rename to examples/SetBucketVersioning.java index fe00d6dbb..94298543b 100644 --- a/examples/DisableVersioning.java +++ b/examples/SetBucketVersioning.java @@ -14,15 +14,16 @@ * limitations under the License. */ -import io.minio.DisableVersioningArgs; import io.minio.MinioClient; +import io.minio.SetBucketVersioningArgs; import io.minio.errors.MinioException; +import io.minio.messages.VersioningConfiguration; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -public class DisableVersioning { - /** MinioClient.disableVersioning() example. */ +public class SetBucketVersioning { + /** MinioClient.setBucketVersioning() example. */ public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException { try { @@ -40,12 +41,21 @@ public static void main(String[] args) // .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY") // .build(); - // Disable versioning on 'my-bucketname'. - minioClient.disableVersioning( - DisableVersioningArgs.builder().bucket("my-bucketname").build()); - - System.out.println("Bucket versioning is disabled successfully"); + // Enable versioning on 'my-bucketname'. + minioClient.setBucketVersioning( + SetBucketVersioningArgs.builder() + .bucket("my-bucketname") + .config(new VersioningConfiguration(VersioningConfiguration.Status.ENABLED, null)) + .build()); + System.out.println("Bucket versioning is enabled successfully"); + // Suspend versioning on 'my-bucketname'. + minioClient.setBucketVersioning( + SetBucketVersioningArgs.builder() + .bucket("my-bucketname") + .config(new VersioningConfiguration(VersioningConfiguration.Status.SUSPENDED, null)) + .build()); + System.out.println("Bucket versioning is suspended successfully"); } catch (MinioException e) { System.out.println("Error occurred: " + e); } diff --git a/functional/FunctionalTest.java b/functional/FunctionalTest.java index a9c51c934..b31b499de 100644 --- a/functional/FunctionalTest.java +++ b/functional/FunctionalTest.java @@ -36,23 +36,21 @@ import io.minio.DeleteObjectTagsArgs; import io.minio.Directive; import io.minio.DisableObjectLegalHoldArgs; -import io.minio.DisableVersioningArgs; import io.minio.DownloadObjectArgs; import io.minio.EnableObjectLegalHoldArgs; -import io.minio.EnableVersioningArgs; import io.minio.GetBucketEncryptionArgs; import io.minio.GetBucketLifeCycleArgs; import io.minio.GetBucketNotificationArgs; import io.minio.GetBucketPolicyArgs; import io.minio.GetBucketReplicationArgs; import io.minio.GetBucketTagsArgs; +import io.minio.GetBucketVersioningArgs; import io.minio.GetObjectArgs; import io.minio.GetObjectLockConfigurationArgs; import io.minio.GetObjectRetentionArgs; import io.minio.GetObjectTagsArgs; import io.minio.GetPresignedObjectUrlArgs; import io.minio.IsObjectLegalHoldEnabledArgs; -import io.minio.IsVersioningEnabledArgs; import io.minio.ListObjectsArgs; import io.minio.ListenBucketNotificationArgs; import io.minio.MakeBucketArgs; @@ -76,6 +74,7 @@ import io.minio.SetBucketPolicyArgs; import io.minio.SetBucketReplicationArgs; import io.minio.SetBucketTagsArgs; +import io.minio.SetBucketVersioningArgs; import io.minio.SetObjectLockConfigurationArgs; import io.minio.SetObjectRetentionArgs; import io.minio.SetObjectTagsArgs; @@ -116,6 +115,7 @@ import io.minio.messages.Stats; import io.minio.messages.Status; import io.minio.messages.Tags; +import io.minio.messages.VersioningConfiguration; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -591,8 +591,8 @@ public static void removeBucket() throws Exception { testBucketApiCases(methodName, false, true); } - public static void enableVersioning() throws Exception { - String methodName = "enableVersioning()"; + public static void setBucketVersioning() throws Exception { + String methodName = "setBucketVersioning()"; if (!mintEnv) { System.out.println(methodName); } @@ -602,34 +602,16 @@ public static void enableVersioning() throws Exception { try { client.makeBucket(MakeBucketArgs.builder().bucket(name).build()); try { - client.enableVersioning(EnableVersioningArgs.builder().bucket(name).build()); - mintSuccessLog(methodName, null, startTime); - } finally { - client.removeBucket(RemoveBucketArgs.builder().bucket(name).build()); - } - } catch (Exception e) { - handleException(methodName, null, startTime, e); - } - } - - public static void disableVersioning() throws Exception { - String methodName = "disableVersioning()"; - if (!mintEnv) { - System.out.println(methodName); - } - - long startTime = System.currentTimeMillis(); - String name = getRandomName(); - try { - client.makeBucket(MakeBucketArgs.builder().bucket(name).build()); - try { - // disableVersioning() should succeed on fresh bucket. - client.disableVersioning(DisableVersioningArgs.builder().bucket(name).build()); - - // disableVersioning() should succeed on version enabled bucket. - client.enableVersioning(EnableVersioningArgs.builder().bucket(name).build()); - client.disableVersioning(DisableVersioningArgs.builder().bucket(name).build()); - + client.setBucketVersioning( + SetBucketVersioningArgs.builder() + .bucket(name) + .config(new VersioningConfiguration(VersioningConfiguration.Status.ENABLED, null)) + .build()); + client.setBucketVersioning( + SetBucketVersioningArgs.builder() + .bucket(name) + .config(new VersioningConfiguration(VersioningConfiguration.Status.SUSPENDED, null)) + .build()); mintSuccessLog(methodName, null, startTime); } finally { client.removeBucket(RemoveBucketArgs.builder().bucket(name).build()); @@ -639,8 +621,8 @@ public static void disableVersioning() throws Exception { } } - public static void isVersioningEnabled() throws Exception { - String methodName = "isVersioningEnabled()"; + public static void getBucketVersioning() throws Exception { + String methodName = "getBucketVersioning()"; if (!mintEnv) { System.out.println(methodName); } @@ -650,19 +632,38 @@ public static void isVersioningEnabled() throws Exception { try { client.makeBucket(MakeBucketArgs.builder().bucket(name).build()); try { - if (client.isVersioningEnabled(IsVersioningEnabledArgs.builder().bucket(name).build())) { - throw new Exception("isVersioningEnabled() should return false on fresh bucket"); + VersioningConfiguration config = + client.getBucketVersioning(GetBucketVersioningArgs.builder().bucket(name).build()); + if (config.status() != VersioningConfiguration.Status.OFF) { + throw new Exception("getBucketVersioning(); expected = \"\", got = " + config.status()); } - client.enableVersioning(EnableVersioningArgs.builder().bucket(name).build()); - if (!client.isVersioningEnabled(IsVersioningEnabledArgs.builder().bucket(name).build())) { - throw new Exception("isVersioningEnabled() should return true on versioned bucket"); + client.setBucketVersioning( + SetBucketVersioningArgs.builder() + .bucket(name) + .config(new VersioningConfiguration(VersioningConfiguration.Status.ENABLED, null)) + .build()); + config = client.getBucketVersioning(GetBucketVersioningArgs.builder().bucket(name).build()); + if (config.status() != VersioningConfiguration.Status.ENABLED) { + throw new Exception( + "getBucketVersioning(); expected = " + + VersioningConfiguration.Status.ENABLED + + ", got = " + + config.status()); } - client.disableVersioning(DisableVersioningArgs.builder().bucket(name).build()); - if (client.isVersioningEnabled(IsVersioningEnabledArgs.builder().bucket(name).build())) { + client.setBucketVersioning( + SetBucketVersioningArgs.builder() + .bucket(name) + .config(new VersioningConfiguration(VersioningConfiguration.Status.SUSPENDED, null)) + .build()); + config = client.getBucketVersioning(GetBucketVersioningArgs.builder().bucket(name).build()); + if (config.status() != VersioningConfiguration.Status.SUSPENDED) { throw new Exception( - "isVersioningEnabled() should return false on version disabled bucket"); + "getBucketVersioning(); expected = " + + VersioningConfiguration.Status.SUSPENDED + + ", got = " + + config.status()); } mintSuccessLog(methodName, null, startTime); @@ -1349,7 +1350,11 @@ public static void testListObjects( client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); try { if (versions > 0) { - client.enableVersioning(EnableVersioningArgs.builder().bucket(bucketName).build()); + client.setBucketVersioning( + SetBucketVersioningArgs.builder() + .bucket(bucketName) + .config(new VersioningConfiguration(VersioningConfiguration.Status.ENABLED, null)) + .build()); } results = createObjects(bucketName, objCount, versions); @@ -3578,9 +3583,8 @@ public static void runBucketTests() throws Exception { removeBucket(); listBuckets(); - enableVersioning(); - disableVersioning(); - isVersioningEnabled(); + setBucketVersioning(); + getBucketVersioning(); setObjectLockConfiguration(); getObjectLockConfiguration();