summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/minio/minio-go/v7/utils.go
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2022-01-18 20:24:14 +0100
committerGitHub <noreply@github.com>2022-01-18 20:24:14 +0100
commitaad60c882e16cd2c8769a49e6d9f87a040590d62 (patch)
tree3bfe1f8953b40f9beb39c69db3a7647ea6de54d2 /vendor/github.com/minio/minio-go/v7/utils.go
parentfecca575078a21dedb0cab213dde7fd97161c0fa (diff)
downloadmatterbridge-msglm-aad60c882e16cd2c8769a49e6d9f87a040590d62.tar.gz
matterbridge-msglm-aad60c882e16cd2c8769a49e6d9f87a040590d62.tar.bz2
matterbridge-msglm-aad60c882e16cd2c8769a49e6d9f87a040590d62.zip
Bump github.com/mattermost/mattermost-server/v6 from 6.1.0 to 6.3.0 (#1686)
Bumps [github.com/mattermost/mattermost-server/v6](https://github.com/mattermost/mattermost-server) from 6.1.0 to 6.3.0. - [Release notes](https://github.com/mattermost/mattermost-server/releases) - [Changelog](https://github.com/mattermost/mattermost-server/blob/master/CHANGELOG.md) - [Commits](https://github.com/mattermost/mattermost-server/compare/v6.1.0...v6.3.0) --- updated-dependencies: - dependency-name: github.com/mattermost/mattermost-server/v6 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/minio/minio-go/v7/utils.go')
-rw-r--r--vendor/github.com/minio/minio-go/v7/utils.go53
1 files changed, 47 insertions, 6 deletions
diff --git a/vendor/github.com/minio/minio-go/v7/utils.go b/vendor/github.com/minio/minio-go/v7/utils.go
index e7f90a3b..297df7bf 100644
--- a/vendor/github.com/minio/minio-go/v7/utils.go
+++ b/vendor/github.com/minio/minio-go/v7/utils.go
@@ -52,7 +52,7 @@ var expirationRegex = regexp.MustCompile(`expiry-date="(.*?)", rule-id="(.*?)"`)
func amzExpirationToExpiryDateRuleID(expiration string) (time.Time, string) {
if matches := expirationRegex.FindStringSubmatch(expiration); len(matches) == 3 {
- expTime, err := time.Parse(http.TimeFormat, matches[1])
+ expTime, err := parseRFC7231Time(matches[1])
if err != nil {
return time.Time{}, ""
}
@@ -73,7 +73,7 @@ func amzRestoreToStruct(restore string) (ongoing bool, expTime time.Time, err er
return false, time.Time{}, err
}
if matches[3] != "" {
- expTime, err = time.Parse(http.TimeFormat, matches[3])
+ expTime, err = parseRFC7231Time(matches[3])
if err != nil {
return false, time.Time{}, err
}
@@ -240,6 +240,27 @@ func extractObjMetadata(header http.Header) http.Header {
return filteredHeader
}
+const (
+ // RFC 7231#section-7.1.1.1 timetamp format. e.g Tue, 29 Apr 2014 18:30:38 GMT
+ rfc822TimeFormat = "Mon, 2 Jan 2006 15:04:05 GMT"
+ rfc822TimeFormatSingleDigitDay = "Mon, _2 Jan 2006 15:04:05 GMT"
+ rfc822TimeFormatSingleDigitDayTwoDigitYear = "Mon, _2 Jan 06 15:04:05 GMT"
+)
+
+func parseTime(t string, formats ...string) (time.Time, error) {
+ for _, format := range formats {
+ tt, err := time.Parse(format, t)
+ if err == nil {
+ return tt, nil
+ }
+ }
+ return time.Time{}, fmt.Errorf("unable to parse %s in any of the input formats: %s", t, formats)
+}
+
+func parseRFC7231Time(lastModified string) (time.Time, error) {
+ return parseTime(lastModified, rfc822TimeFormat, rfc822TimeFormatSingleDigitDay, rfc822TimeFormatSingleDigitDayTwoDigitYear)
+}
+
// ToObjectInfo converts http header values into ObjectInfo type,
// extracts metadata and fills in all the necessary fields in ObjectInfo.
func ToObjectInfo(bucketName string, objectName string, h http.Header) (ObjectInfo, error) {
@@ -267,7 +288,7 @@ func ToObjectInfo(bucketName string, objectName string, h http.Header) (ObjectIn
}
// Parse Last-Modified has http time format.
- date, err := time.Parse(http.TimeFormat, h.Get("Last-Modified"))
+ mtime, err := parseRFC7231Time(h.Get("Last-Modified"))
if err != nil {
return ObjectInfo{}, ErrorResponse{
Code: "InternalError",
@@ -289,7 +310,18 @@ func ToObjectInfo(bucketName string, objectName string, h http.Header) (ObjectIn
expiryStr := h.Get("Expires")
var expiry time.Time
if expiryStr != "" {
- expiry, _ = time.Parse(http.TimeFormat, expiryStr)
+ expiry, err = parseRFC7231Time(expiryStr)
+ if err != nil {
+ return ObjectInfo{}, ErrorResponse{
+ Code: "InternalError",
+ Message: fmt.Sprintf("'Expiry' is not in supported format: %v", err),
+ BucketName: bucketName,
+ Key: objectName,
+ RequestID: h.Get("x-amz-request-id"),
+ HostID: h.Get("x-amz-id-2"),
+ Region: h.Get("x-amz-bucket-region"),
+ }
+ }
}
metadata := extractObjMetadata(h)
@@ -337,7 +369,7 @@ func ToObjectInfo(bucketName string, objectName string, h http.Header) (ObjectIn
ETag: etag,
Key: objectName,
Size: size,
- LastModified: date,
+ LastModified: mtime,
ContentType: contentType,
Expires: expiry,
VersionID: h.Get(amzVersionID),
@@ -404,7 +436,7 @@ func redactSignature(origAuth string) string {
return "AWS **REDACTED**:**REDACTED**"
}
- /// Signature V4 authorization header.
+ // Signature V4 authorization header.
// Strip out accessKeyID from:
// Credential=<access-key-id>/<date>/<aws-region>/<aws-service>/aws4_request
@@ -552,6 +584,11 @@ func IsNetworkOrHostDown(err error, expectTimeouts bool) bool {
if expectTimeouts && errors.Is(err, context.DeadlineExceeded) {
return false
}
+
+ if errors.Is(err, context.DeadlineExceeded) {
+ return true
+ }
+
// We need to figure if the error either a timeout
// or a non-temporary error.
urlErr := &url.Error{}
@@ -581,6 +618,10 @@ func IsNetworkOrHostDown(err error, expectTimeouts bool) bool {
case strings.Contains(err.Error(), "connection timed out"):
// If err is a net.Dial timeout.
return true
+ case strings.Contains(err.Error(), "connection refused"):
+ // If err is connection refused
+ return true
+
case strings.Contains(strings.ToLower(err.Error()), "503 service unavailable"):
// Denial errors
return true