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}BucketNotification APIs #932

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/DeleteBucketNotificationArgs.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.deleteBucketNotification(). */
public class DeleteBucketNotificationArgs extends BucketArgs {
public static Builder builder() {
return new Builder();
}

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

/** Argument builder of {@link GetBucketNotificationArgs}. */
public static final class Builder
extends BucketArgs.Builder<Builder, GetBucketNotificationArgs> {}
}
138 changes: 130 additions & 8 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5239,18 +5239,52 @@ public String getBucketLifeCycle(GetBucketLifeCycleArgs 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 #getBucketNotification(GetBucketNotificationArgs)}
*/
@Deprecated
anjalshireesh marked this conversation as resolved.
Show resolved Hide resolved
public NotificationConfiguration getBucketNotification(String bucketName)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
return getBucketNotification(GetBucketNotificationArgs.builder().bucket(bucketName).build());
}

/**
* Gets notification configuration of a bucket.
*
* <pre>Example:{@code
* NotificationConfiguration config =
* minioClient.getBucketNotification(
* GetBucketNotificationArgs.builder().bucket("my-bucketname").build());
* }</pre>
*
* @param args {@link GetBucketNotificationArgs} object.
* @return {@link NotificationConfiguration} - Notification 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 NotificationConfiguration getBucketNotification(GetBucketNotificationArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
checkArgs(args);

Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("notification", "");

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

Expand Down Expand Up @@ -5290,18 +5324,70 @@ public NotificationConfiguration getBucketNotification(String bucketName)
* @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 #setBucketNotification(SetBucketNotificationArgs)}
*/
@Deprecated
public void setBucketNotification(
String bucketName, NotificationConfiguration notificationConfiguration)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
setBucketNotification(
SetBucketNotificationArgs.builder()
.bucket(bucketName)
.config(notificationConfiguration)
.build());
}

/**
* Sets notification configuration to a bucket.
*
* <pre>Example:{@code
* List<EventType> eventList = new LinkedList<>();
* eventList.add(EventType.OBJECT_CREATED_PUT);
* eventList.add(EventType.OBJECT_CREATED_COPY);
*
* QueueConfiguration queueConfiguration = new QueueConfiguration();
* queueConfiguration.setQueue("arn:minio:sqs::1:webhook");
* queueConfiguration.setEvents(eventList);
* queueConfiguration.setPrefixRule("images");
* queueConfiguration.setSuffixRule("pg");
*
* List<QueueConfiguration> queueConfigurationList = new LinkedList<>();
* queueConfigurationList.add(queueConfiguration);
*
* NotificationConfiguration config = new NotificationConfiguration();
* config.setQueueConfigurationList(queueConfigurationList);
*
* minioClient.setBucketNotification(
* SetBucketNotificationArgs.builder().bucket("my-bucketname").config(config).build());
* }</pre>
*
* @param args {@link SetBucketNotificationArgs} 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 setBucketNotification(SetBucketNotificationArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
checkArgs(args);

Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("notification", "");
Response response =
executePut(bucketName, null, null, queryParamMap, notificationConfiguration, 0);
response.body().close();
Response response = executePut(args.bucket(), null, null, queryParamMap, args.config(), 0);
response.close();
}

/**
Expand All @@ -5323,14 +5409,50 @@ public void setBucketNotification(
* @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 #deleteBucketNotification(DeleteBucketNotificationArgs)}
*/
@Deprecated
public void removeAllBucketNotification(String bucketName)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
NotificationConfiguration notificationConfiguration = new NotificationConfiguration();
setBucketNotification(bucketName, notificationConfiguration);
deleteBucketNotification(DeleteBucketNotificationArgs.builder().bucket(bucketName).build());
}

/**
* Deletes notification configuration of a bucket.
*
* <pre>Example:{@code
* minioClient.deleteBucketNotification(
* DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build());
* }</pre>
*
* @param args {@link DeleteBucketNotificationArgs} 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 deleteBucketNotification(DeleteBucketNotificationArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
XmlParserException {
checkArgs(args);

setBucketNotification(
SetBucketNotificationArgs.builder()
.bucket(args.bucket())
.config(new NotificationConfiguration())
.build());
}

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

/** Argument class of MinioClient.setBucketNotification(). */
public class SetBucketNotificationArgs extends BucketArgs {
private NotificationConfiguration config;

public NotificationConfiguration config() {
return config;
}

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

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

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

public Builder config(NotificationConfiguration config) {
validateConfig(config);
operations.add(args -> args.config = config);
return this;
}
}
}
7 changes: 2 additions & 5 deletions api/src/main/java/io/minio/messages/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ public void setSuffixRule(String value) throws IllegalArgumentException {
}

public List<FilterRule> filterRuleList() {
if (filterRuleList == null) {
return null;
}

return Collections.unmodifiableList(filterRuleList);
return Collections.unmodifiableList(
filterRuleList == null ? new LinkedList<>() : filterRuleList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.minio.messages;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
Expand All @@ -25,14 +26,14 @@
* Helper class to denote common fields of {@link CloudFunctionConfiguration}, {@link
* QueueConfiguration} and {@link TopicConfiguration}.
*/
public class NotificationCommonConfiguration {
public abstract class NotificationCommonConfiguration {
@Element(name = "Id", required = false)
private String id;

@ElementList(name = "Event", inline = true, required = false)
@ElementList(name = "Event", inline = true)
private List<EventType> events;

@Element(name = "Filter")
@Element(name = "Filter", required = false)
private Filter filter;

public NotificationCommonConfiguration() {}
Expand All @@ -49,11 +50,7 @@ public void setId(String id) {

/** Returns events. */
public List<EventType> events() {
if (events == null) {
return null;
}

return Collections.unmodifiableList(events);
return Collections.unmodifiableList(events == null ? new LinkedList<>() : events);
}

/** Sets event. */
Expand Down Expand Up @@ -81,10 +78,7 @@ public void setSuffixRule(String value) throws IllegalArgumentException {

/** returns filter rule list. */
public List<FilterRule> filterRuleList() {
if (filter == null) {
return null;
}

return filter.filterRuleList();
return Collections.unmodifiableList(
filter == null ? new LinkedList<>() : filter.filterRuleList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.minio.messages;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Namespace;
Expand Down Expand Up @@ -45,7 +46,10 @@ public NotificationConfiguration() {}

/** Returns cloud function configuration. */
public List<CloudFunctionConfiguration> cloudFunctionConfigurationList() {
return cloudFunctionConfigurationList;
return Collections.unmodifiableList(
cloudFunctionConfigurationList == null
? new LinkedList<>()
: cloudFunctionConfigurationList);
}

/** Sets cloud function configuration list. */
Expand All @@ -57,7 +61,8 @@ public void setCloudFunctionConfigurationList(

/** Returns queue configuration list. */
public List<QueueConfiguration> queueConfigurationList() {
return queueConfigurationList;
return Collections.unmodifiableList(
queueConfigurationList == null ? new LinkedList<>() : queueConfigurationList);
}

/** Sets queue configuration list. */
Expand All @@ -67,7 +72,8 @@ public void setQueueConfigurationList(List<QueueConfiguration> queueConfiguratio

/** Returns topic configuration list. */
public List<TopicConfiguration> topicConfigurationList() {
return topicConfigurationList;
return Collections.unmodifiableList(
topicConfigurationList == null ? new LinkedList<>() : topicConfigurationList);
}

/** Sets topic configuration list. */
Expand Down
Loading