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 method isVersioningEnabled() #955

Merged
merged 5 commits into from
May 30, 2020
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
27 changes: 27 additions & 0 deletions api/src/main/java/io/minio/IsVersioningEnabledArgs.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.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<Builder, IsVersioningEnabledArgs> {}
}
59 changes: 49 additions & 10 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import io.minio.messages.SseConfiguration;
import io.minio.messages.Tags;
import io.minio.messages.Upload;
import io.minio.messages.VersioningConfiguration;
import io.minio.org.apache.commons.validator.routines.InetAddressValidator;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
Expand Down Expand Up @@ -2119,10 +2120,7 @@ public void getObject(
* .build());
* }</pre>
*
* @param args Object of {@link GetObjectArgs}
* @param objectName Object name in the bucket.
* @param ssec SSE-C type server-side encryption.
* @param fileName Name of the file.
* @param args Object of {@link DownloadObjectArgs}
* @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 Down Expand Up @@ -3733,6 +3731,7 @@ 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)
Expand Down Expand Up @@ -3770,9 +3769,8 @@ public void enableVersioning(EnableVersioningArgs args)

Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("versioning", "");
String config =
"<VersioningConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
+ "<Status>Enabled</Status></VersioningConfiguration>";
VersioningConfiguration config = new VersioningConfiguration(true);

Response response = executePut(args.bucket(), null, null, queryParamMap, config, 0);
response.body().close();
}
Expand All @@ -3796,6 +3794,7 @@ 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)
Expand Down Expand Up @@ -3834,13 +3833,53 @@ public void disableVersioning(DisableVersioningArgs args)

Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("versioning", "");
String config =
"<VersioningConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
+ "<Status>Suspended</Status></VersioningConfiguration>";
VersioningConfiguration config = new VersioningConfiguration(false);
Response response = executePut(args.bucket(), null, null, queryParamMap, config, 0);
response.body().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)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException {
checkArgs(args);

Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("versioning", "");
try (Response response = executeGet(args.bucket(), null, null, queryParamMap)) {
VersioningConfiguration result =
Xml.unmarshal(VersioningConfiguration.class, response.body().charStream());
return result.status();
}
}

/**
* Sets default object retention in a bucket.
*
Expand Down
51 changes: 51 additions & 0 deletions api/src/main/java/io/minio/messages/VersioningConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.messages;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;

/**
* Object representation of request XML of <a
* href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketVersioning.html">PutBucketVersioning
sinhaashish marked this conversation as resolved.
Show resolved Hide resolved
* API</a> and response XML of <a
* href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketVersioning.html">GetBucketVersioning
* API</a>.
*/
@Root(name = "VersioningConfiguration", strict = false)
@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/")
public class VersioningConfiguration {
@Element(name = "Status", required = false)
private String status;

public VersioningConfiguration() {}

/** Constructs a new VersioningConfiguration object with given status. */
public VersioningConfiguration(boolean status) {
if (status) {
this.status = "Enabled";
} else {
this.status = "Suspended";
}
}

/** Indicates whether the bucket is version enabled or not. */
public boolean status() {
return ("Enabled").equals(status);
}
}
50 changes: 40 additions & 10 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ MinioClient s3Client = new MinioClient("https://s3.amazonaws.com",
| [`getBucketPolicy`](#getBucketPolicy) | [`getPresignedObjectUrl`](#getPresignedObjectUrl) |
| [`getBucketTags`](#getBucketTags) | [`isObjectLegalHoldEnabled`](#isObjectLegalHoldEnabled) |
| [`getDefaultRetention`](#getDefaultRetention) | [`listObjects`](#listObjects) |
| [`listBuckets`](#listBuckets) | [`presignedGetObject`](#presignedGetObject) |
| [`listenBucketNotification`](#listenBucketNotification) | [`presignedPostPolicy`](#presignedPostPolicy) |
| [`listIncompleteUploads`](#listIncompleteUploads) | [`presignedPutObject`](#presignedPutObject) |
| [`makeBucket`](#makeBucket) | [`putObject`](#putObject) |
| [`removeAllBucketNotification`](#removeAllBucketNotification) | [`removeObject`](#removeObject) |
| [`removeBucket`](#removeBucket) | [`removeObjects`](#removeObjects) |
| [`removeIncompleteUpload`](#removeIncompleteUpload) | [`selectObjectContent`](#selectObjectContent) |
| [`setBucketEncryption`](#setBucketEncryption) | [`setObjectRetention`](#setObjectRetention) |
| [`setBucketLifeCycle`](#setBucketLifeCycle) | [`setObjectTags`](#setObjectTags) |
| [`setBucketNotification`](#setBucketNotification) | [`statObject`](#statObject) |
| [`isVersioningEnabled`](#isVersioningEnabled) | [`presignedGetObject`](#presignedGetObject) |
| [`listBuckets`](#listBuckets) | [`presignedPostPolicy`](#presignedPostPolicy) |
| [`listenBucketNotification`](#listenBucketNotification) | [`presignedPutObject`](#presignedPutObject) |
| [`listIncompleteUploads`](#listIncompleteUploads) | [`putObject`](#putObject) |
| [`makeBucket`](#makeBucket) | [`removeObject`](#removeObject) |
| [`removeAllBucketNotification`](#removeAllBucketNotification) | [`removeObjects`](#removeObjects) |
| [`removeBucket`](#removeBucket) | [`selectObjectContent`](#selectObjectContent) |
| [`removeIncompleteUpload`](#removeIncompleteUpload) | [`setObjectRetention`](#setObjectRetention) |
| [`setBucketEncryption`](#setBucketEncryption) | [`setObjectTags`](#setObjectTags) |
| [`setBucketLifeCycle`](#setBucketLifeCycle) | [`statObject`](#statObject) |
| [`setBucketNotification`](#setBucketNotification) | |
| [`setBucketPolicy`](#setBucketPolicy) | |
| [`setBucketTags`](#setBucketTags) | |
| [`setDefaultRetention`](#setDefaultRetention) | |
Expand Down Expand Up @@ -388,6 +389,34 @@ __Example__
minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucket").build());
```

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

<a name="getBucketEncryption"></a>
### getBucketEncryption(GetBucketEncryptionArgs args)
`public SseConfiguration getBucketEncryption(GetBucketEncryptionArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#getBucketEncryption-io.minio.GetBucketEncryptionArgs-)_
Expand Down Expand Up @@ -1737,3 +1766,4 @@ 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
50 changes: 50 additions & 0 deletions examples/DisableVersioning.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) 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.DisableVersioningArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class DisableVersioning {
/** MinioClient.disableVersioning() example. */
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException {
try {
/* play.min.io for test and development. */
MinioClient minioClient =
new MinioClient(
"https://play.min.io",
"Q3AM3UQ867SPQQA43P2F",
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

/* Amazon S3: */
// MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
// "YOUR-SECRETACCESSKEY");

// Disable versioning on 'my-bucketname'.
minioClient.disableVersioning(
DisableVersioningArgs.builder().bucket("my-bucketname").build());

System.out.println("Bucket versioning is disabled successfully");

} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
}
}
49 changes: 49 additions & 0 deletions examples/EnableVersioning.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.EnableVersioningArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class EnableVersioning {
/** MinioClient.enableVersioning() example. */
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException {
try {
/* play.min.io for test and development. */
MinioClient minioClient =
new MinioClient(
"https://play.min.io",
"Q3AM3UQ867SPQQA43P2F",
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

/* Amazon S3: */
// MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
// "YOUR-SECRETACCESSKEY");

// Enable versioning on 'my-bucketname'.
minioClient.enableVersioning(EnableVersioningArgs.builder().bucket("my-bucketname").build());

System.out.println("Bucket versioning is enabled successfully");

} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
}
}
Loading