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

Addresses Issue #1 Remove dependency on commons validator #449

Merged
merged 1 commit into from
Aug 17, 2016
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
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ ext.okHttpClientVersion = '2.7.2'
ext.okioVersion = '1.6.0'
ext.jodaTimeVersion = '2.7'
ext.gsonVersion = '2.7'
ext.apacheCommonsValidatorVersion = '1.5.0'
ext.apacheCommonsCollections4Version = '4.0'
ext.apacheCommonsLang3Version = '3.4'

Expand Down Expand Up @@ -72,7 +71,6 @@ dependencies {
compile group: 'com.squareup.okhttp', name: 'mockwebserver', version: okHttpClientVersion
compile group: 'com.squareup.okio', name: 'okio', version: okioVersion
compile group: 'joda-time', name: 'joda-time', version: jodaTimeVersion
compile group: 'commons-validator', name: 'commons-validator', version: apacheCommonsValidatorVersion
compile group: 'com.google.code.gson', name: 'gson', version: gsonVersion
compile group: 'org.apache.commons', name: 'commons-collections4', version: apacheCommonsCollections4Version
compile group: 'org.apache.commons', name: 'commons-lang3', version: apacheCommonsLang3Version
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Aug 09 22:19:57 PDT 2015
#Tue Aug 16 09:00:55 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
4 changes: 2 additions & 2 deletions src/main/java/io/minio/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package io.minio;

class Constants {
static final String AWS_RESOURCE_PREFIX = "arn:aws:s3:::";
public class Constants {
public static final String AWS_RESOURCE_PREFIX = "arn:aws:s3:::";
}
126 changes: 79 additions & 47 deletions src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,82 @@

package io.minio;

import io.minio.errors.*;
import io.minio.messages.*;
import io.minio.http.*;

import com.squareup.okhttp.OkHttpClient;
import com.google.common.io.ByteStreams;
import com.google.gson.Gson;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.MediaType;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.InvalidArgumentException;
import io.minio.errors.InvalidBucketNameException;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidExpiresRangeException;
import io.minio.errors.InvalidObjectPrefixException;
import io.minio.errors.InvalidPortException;
import io.minio.errors.NoResponseException;
import io.minio.errors.NoSuchBucketPolicyException;
import io.minio.http.HeaderParser;
import io.minio.http.Method;
import io.minio.http.Scheme;
import io.minio.messages.Bucket;
import io.minio.messages.CompleteMultipartUpload;
import io.minio.messages.CreateBucketConfiguration;
import io.minio.messages.ErrorResponse;
import io.minio.messages.InitiateMultipartUploadResult;
import io.minio.messages.Item;
import io.minio.messages.ListAllMyBucketsResult;
import io.minio.messages.ListBucketResult;
import io.minio.messages.ListMultipartUploadsResult;
import io.minio.messages.ListPartsResult;
import io.minio.messages.Part;
import io.minio.messages.Prefix;
import io.minio.messages.Upload;
import io.minio.org.apache.commons.validator.routines.InetAddressValidator;
import io.minio.policy.BucketAccessPolicy;
import io.minio.policy.BucketPolicy;
import io.minio.policy.Statement;
import okio.BufferedSink;
import okio.Okio;
import org.apache.commons.collections4.CollectionUtils;
import org.joda.time.DateTime;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParserException;
import org.apache.commons.validator.routines.InetAddressValidator;
import org.joda.time.DateTime;
import com.google.gson.Gson;
import org.xmlpull.v1.XmlPullParserFactory;

import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.io.BufferedInputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.io.StringReader;
import java.io.EOFException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.nio.charset.StandardCharsets;
import java.nio.channels.Channels;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import com.google.common.io.ByteStreams;
import java.nio.file.StandardCopyOption;
import org.apache.commons.collections4.CollectionUtils;
import java.nio.file.StandardOpenOption;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* <p>
Expand Down Expand Up @@ -290,8 +322,8 @@ public MinioClient(HttpUrl url, String accessKey, String secretKey)
* Creates Minio client object with given endpoint, port, access key and secret key using secure (HTTPS) connection.
*
* </p><b>Example:</b><br>
* <pre>{@code MinioClient minioClient =
* new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
* <pre>{@code MinioClient minioClient =
* new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");
* }</pre>
*
* @param endpoint Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.<pre>
Expand Down Expand Up @@ -327,8 +359,8 @@ public MinioClient(String endpoint, int port, String accessKey, String secretKey
* Creates Minio client object with given endpoint, access key and secret key using secure (HTTPS) connection.
*
* </p><b>Example:</b><br>
* <pre>{@code MinioClient minioClient =
* new MinioClient("play.minio.io:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true);
* <pre>{@code MinioClient minioClient =
* new MinioClient("play.minio.io:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true);
* }</pre>
*
* @param endpoint Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.<pre>
Expand Down Expand Up @@ -365,8 +397,8 @@ public MinioClient(String endpoint, String accessKey, String secretKey, boolean
* Creates Minio client object using given endpoint, port, access key, secret key and secure option.
*
* </p><b>Example:</b><br>
* <pre>{@code MinioClient minioClient =
* new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false);
* <pre>{@code MinioClient minioClient =
* new MinioClient("play.minio.io", 9000, "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", false);
* }</pre>
*
* @param endpoint Request endpoint. Endpoint is an URL, domain name, IPv4 or IPv6 address.<pre>
Expand Down Expand Up @@ -545,7 +577,7 @@ private void checkBucketName(String name) throws InvalidBucketNameException {
* Integer.MAX_VALUE when converted to milliseconds.
*
* </p><b>Example:</b><br>
* <pre>{@code minioClient.setTimeout(TimeUnit.SECONDS.toMillis(10), TimeUnit.SECONDS.toMillis(10),
* <pre>{@code minioClient.setTimeout(TimeUnit.SECONDS.toMillis(10), TimeUnit.SECONDS.toMillis(10),
* TimeUnit.SECONDS.toMillis(30)); }</pre>
*
* @param connectTimeout HTTP connect timeout in milliseconds.
Expand Down Expand Up @@ -828,7 +860,7 @@ private HttpResponse execute(Method method, String region, String bucketName, St
}

ErrorResponse errorResponse = null;

// HEAD returns no body, and fails on parseXml
if (!method.equals(Method.HEAD)) {
try {
Expand Down Expand Up @@ -2131,8 +2163,8 @@ private void putObject(String bucketName, String objectName, String contentType,
* System.out.println(policy); }</pre>
*/
public BucketPolicy getBucketPolicy(String bucketName, String objectPrefix)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
checkObjectPrefix(objectPrefix);

Expand All @@ -2144,25 +2176,25 @@ public BucketPolicy getBucketPolicy(String bucketName, String objectPrefix)
return BucketPolicy.None;
}
throw e;
}
}
}

/**
* Set policy on bucket and object prefix.
*
* @param bucketName Bucket name.
* @param objectPrefix name of the object prefix
* @param bucketPolicy policy can be BucketPolicy.None, BucketPolicy.ReadOnly,
* @param bucketPolicy policy can be BucketPolicy.None, BucketPolicy.ReadOnly,
* BucketPolicy.ReadWrite, BucketPolicy.WriteOnly
*
* </p><b>Example:</b><br>
* <pre>{@code setBucketPolicy("my-bucketname", "my-objectname", BucketPolicy.ReadOnly);
* }</pre>
*/
public void setBucketPolicy(String bucketName, String objectPrefix, BucketPolicy bucketPolicy)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException,
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException,
NoSuchBucketPolicyException {
checkObjectPrefix(objectPrefix);

Expand All @@ -2187,7 +2219,7 @@ public void setBucketPolicy(String bucketName, String objectPrefix, BucketPolicy
statements.addAll(BucketAccessPolicy.commonBucketStatement(bucketName));
}

List<Statement> generatedStatements = BucketAccessPolicy.generatePolicyStatements(bucketPolicy,
List<Statement> generatedStatements = BucketAccessPolicy.generatePolicyStatements(bucketPolicy,
bucketName, objectPrefix);
statements.addAll(generatedStatements);

Expand All @@ -2211,15 +2243,15 @@ public void setBucketPolicy(String bucketName, String objectPrefix, BucketPolicy
* Returns the parsed current bucket access policy.
*/
private BucketAccessPolicy getBucketAccessPolicy(String bucketName, String objectPrefix)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("policy", "");

HttpResponse response = executeGet(bucketName, null, null, queryParamMap);

BucketAccessPolicy policy = gson.fromJson(response.body().charStream(), BucketAccessPolicy.class);
BucketAccessPolicy policy = gson.fromJson(response.body().charStream(), BucketAccessPolicy.class);
response.body().close();

if (policy == null) {
Expand All @@ -2233,8 +2265,8 @@ private BucketAccessPolicy getBucketAccessPolicy(String bucketName, String objec
* Deletes the bucket access policy.
*/
private void delBucketAccessPolicy(String bucketName)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("policy", "");
Expand All @@ -2247,8 +2279,8 @@ private void delBucketAccessPolicy(String bucketName)
* Sets the bucket access policy.
*/
private void putBucketAccessPolicy(String bucketName, BucketAccessPolicy policy)
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
XmlPullParserException, ErrorResponseException, InternalException {
Map<String,String> queryParamMap = new HashMap<>();
queryParamMap.put("policy", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.minio.errors;

import io.minio.BucketPolicy;
import io.minio.policy.BucketPolicy;

/**
* Thrown to indicate that given bucket name is not valid.
Expand Down
Loading