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

remove legacy joda time #855

Merged
merged 2 commits into from
Mar 5, 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
15 changes: 7 additions & 8 deletions api/src/main/java/io/minio/ChunkedInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@

package io.minio;

import io.minio.errors.InternalException;
import io.minio.errors.InsufficientDataException;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import org.joda.time.DateTime;

import io.minio.errors.InternalException;
import io.minio.errors.InsufficientDataException;
import java.time.ZonedDateTime;


class ChunkedInputStream extends InputStream {
Expand All @@ -54,7 +53,7 @@ class ChunkedInputStream extends InputStream {
private InputStream inputStream;
private int streamSize;
private int length;
private DateTime date;
private ZonedDateTime date;
private String region;
private String secretKey;
private String prevSignature;
Expand All @@ -72,8 +71,8 @@ class ChunkedInputStream extends InputStream {
/**
* Create new ChunkedInputStream for given input stream.
*/
public ChunkedInputStream(InputStream inputStream, int streamSize, DateTime date, String region, String secretKey,
String seedSignature) throws IOException {
public ChunkedInputStream(InputStream inputStream, int streamSize, ZonedDateTime date, String region,
String secretKey, String seedSignature) throws IOException {
this.inputStream = inputStream;
this.streamSize = streamSize;
this.date = date;
Expand Down
25 changes: 13 additions & 12 deletions api/src/main/java/io/minio/CopyConditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

package io.minio;

import io.minio.errors.InvalidArgumentException;
import io.minio.Time;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.joda.time.DateTime;

import io.minio.errors.InvalidArgumentException;

/**
* A container class to hold all the Conditions to be checked
* before copying an object.
Expand All @@ -42,11 +41,12 @@ public class CopyConditions {
* @throws InvalidArgumentException
* When date is null
*/
public void setModified(DateTime date) throws InvalidArgumentException {
if (date == null) {
throw new InvalidArgumentException("Date cannot be empty");
public void setModified(ZonedDateTime time) throws InvalidArgumentException {
if (time == null) {
throw new InvalidArgumentException("modified time cannot be empty");
}
copyConditions.put("x-amz-copy-source-if-modified-since", date.toString(DateFormat.HTTP_HEADER_DATE_FORMAT));
copyConditions.put("x-amz-copy-source-if-modified-since",
time.format(Time.HTTP_HEADER_DATE_FORMAT));
}

/**
Expand All @@ -55,12 +55,13 @@ public void setModified(DateTime date) throws InvalidArgumentException {
* @throws InvalidArgumentException
* When date is null
*/
public void setUnmodified(DateTime date) throws InvalidArgumentException {
if (date == null) {
throw new InvalidArgumentException("Date can not be null");
public void setUnmodified(ZonedDateTime time) throws InvalidArgumentException {
if (time == null) {
throw new InvalidArgumentException("unmodified time can not be null");
}

copyConditions.put("x-amz-copy-source-if-unmodified-since", date.toString(DateFormat.HTTP_HEADER_DATE_FORMAT));
copyConditions.put("x-amz-copy-source-if-unmodified-since",
time.format(Time.HTTP_HEADER_DATE_FORMAT));
}

/**
Expand Down
44 changes: 0 additions & 44 deletions api/src/main/java/io/minio/DateFormat.java

This file was deleted.

41 changes: 18 additions & 23 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.io.ByteStreams;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import io.minio.errors.BucketPolicyTooLargeException;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InsufficientDataException;
Expand Down Expand Up @@ -60,31 +61,15 @@
import io.minio.messages.ListPartsResult;
import io.minio.messages.ObjectLockConfiguration;
import io.minio.messages.ObjectLockLegalHold;
import io.minio.messages.ObjectRetentionConfiguration;
import io.minio.messages.OutputSerialization;
import io.minio.messages.Part;
import io.minio.messages.Prefix;
import io.minio.messages.Upload;
import io.minio.messages.NotificationConfiguration;
import io.minio.messages.SelectObjectContentRequest;
import io.minio.org.apache.commons.validator.routines.InetAddressValidator;

import io.minio.messages.ObjectRetentionConfiguration;
import io.minio.notification.NotificationInfo;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.Protocol;

import org.joda.time.DateTime;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.minio.org.apache.commons.validator.routines.InetAddressValidator;

import java.io.BufferedInputStream;
import java.io.IOException;
Expand All @@ -101,13 +86,12 @@
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.KeyManagementException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -129,6 +113,17 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.Protocol;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

/**
* <p>
* This class implements a simple cloud storage client. This client consists
Expand Down Expand Up @@ -994,8 +989,8 @@ private Request createRequest(Method method, String bucketName, String objectNam
if (sha256Hash != null) {
requestBuilder.header("x-amz-content-sha256", sha256Hash);
}
DateTime date = new DateTime();
requestBuilder.header("x-amz-date", date.toString(DateFormat.AMZ_DATE_FORMAT));
ZonedDateTime date = ZonedDateTime.now();
requestBuilder.header("x-amz-date", date.format(Time.AMZ_DATE_FORMAT));

if (chunkedUpload) {
// Add empty request body for calculating seed signature.
Expand Down
15 changes: 8 additions & 7 deletions api/src/main/java/io/minio/ObjectStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.minio;

import java.util.Date;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;

Expand All @@ -27,7 +27,7 @@
public class ObjectStat {
private final String bucketName;
private final String name;
private final Date createdTime;
private final ZonedDateTime createdTime;
private final long length;
private final String etag;
private final String contentType;
Expand All @@ -48,7 +48,7 @@ public ObjectStat(String bucketName, String name, ResponseHeader header, Map<Str
this.bucketName = bucketName;
this.name = name;
this.contentType = header.contentType();
this.createdTime = (Date) header.lastModified().clone();
this.createdTime = header.lastModified();
this.length = header.contentLength();

if (header.etag() != null) {
Expand All @@ -64,11 +64,12 @@ public ObjectStat(String bucketName, String name, ResponseHeader header, Map<Str
/**
* Creates ObjectStat with given bucket name, object name, created time, object length, Etag and content type.
*/
public ObjectStat(String bucketName, String name, Date createdTime, long length, String etag, String contentType) {
public ObjectStat(String bucketName, String name, ZonedDateTime createdTime, long length, String etag,
String contentType) {
this.bucketName = bucketName;
this.name = name;
this.contentType = contentType;
this.createdTime = (Date) createdTime.clone();
this.createdTime = createdTime;
this.length = length;
if (etag != null) {
this.etag = etag.replaceAll("\"", "");
Expand Down Expand Up @@ -146,8 +147,8 @@ public String name() {
/**
* Returns created time.
*/
public Date createdTime() {
return (Date) createdTime.clone();
public ZonedDateTime createdTime() {
return createdTime;
}


Expand Down
32 changes: 15 additions & 17 deletions api/src/main/java/io/minio/PostPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@

package io.minio;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.io.BaseEncoding;
import io.minio.errors.InvalidArgumentException;
import io.minio.SuccessActionStatus;
import io.minio.Time;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Map;

import org.joda.time.DateTime;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.io.BaseEncoding;

import io.minio.errors.InvalidArgumentException;
import io.minio.SuccessActionStatus;


/**
* Post policy information to be used to generate presigned post policy form-data.
Expand All @@ -43,15 +41,15 @@ public class PostPolicy {
private final String bucketName;
private final String objectName;
private final boolean startsWith;
private final DateTime expirationDate;
private final ZonedDateTime expirationDate;
private String contentType;
private int successActionStatus;
private String contentEncoding;
private long contentRangeStart;
private long contentRangeEnd;


public PostPolicy(String bucketName, String objectName, DateTime expirationDate)
public PostPolicy(String bucketName, String objectName, ZonedDateTime expirationDate)
throws InvalidArgumentException {
this(bucketName, objectName, false, expirationDate);
}
Expand All @@ -61,7 +59,7 @@ public PostPolicy(String bucketName, String objectName, DateTime expirationDate)
* Creates PostPolicy for given bucket name, object name, string to match object name starting with
* and expiration time.
*/
public PostPolicy(String bucketName, String objectName, boolean startsWith, DateTime expirationDate)
public PostPolicy(String bucketName, String objectName, boolean startsWith, ZonedDateTime expirationDate)
throws InvalidArgumentException {
if (bucketName == null) {
throw new InvalidArgumentException("null bucket name");
Expand Down Expand Up @@ -162,7 +160,7 @@ private byte[] marshalJson(ArrayList<String[]> conditions) {
sb.append("{");

if (expirationDate != null) {
sb.append("\"expiration\":" + "\"" + expirationDate.toString(DateFormat.EXPIRATION_DATE_FORMAT) + "\"");
sb.append("\"expiration\":" + "\"" + expirationDate.format(Time.EXPIRATION_DATE_FORMAT) + "\"");
}

if (!conditions.isEmpty()) {
Expand Down Expand Up @@ -238,17 +236,17 @@ protected Map<String,String> makeFormData(String accessKey, String secretKey, St
conditions.add(new String[]{"eq", "$x-amz-algorithm", ALGORITHM});
formData.put("x-amz-algorithm", ALGORITHM);

DateTime date = new DateTime();
String credential = Signer.credential(accessKey, date, region);
ZonedDateTime utcNow = ZonedDateTime.now(Time.UTC);
String credential = Signer.credential(accessKey, utcNow, region);
conditions.add(new String[]{"eq", "$x-amz-credential", credential});
formData.put("x-amz-credential", credential);

String amzDate = date.toString(DateFormat.AMZ_DATE_FORMAT);
String amzDate = utcNow.format(Time.AMZ_DATE_FORMAT);
conditions.add(new String[]{"eq","$x-amz-date", amzDate});
formData.put("x-amz-date", amzDate);

String policybase64 = BaseEncoding.base64().encode(this.marshalJson(conditions));
String signature = Signer.postPresignV4(policybase64, secretKey, date, region);
String signature = Signer.postPresignV4(policybase64, secretKey, utcNow, region);

formData.put("policy", policybase64);
formData.put("x-amz-signature", signature);
Expand Down
Loading