From 62f8343879162afad14093fef920a874bdb79dc6 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 18 Jan 2017 12:24:34 -0800 Subject: [PATCH] Add constants for commonly used values. (#3588) This is a consolidation effort, avoiding usage of naked strings in codebase. Whenever possible use constants which can be repurposed elsewhere. This also fixes `goconst ./...` reported issues. --- cmd/admin-handlers_test.go | 8 +-- cmd/admin-rpc-server_test.go | 4 +- cmd/api-errors.go | 16 ++--- cmd/api-response.go | 28 ++++---- cmd/auth-handler.go | 4 +- cmd/auth-handler_test.go | 14 ++-- cmd/auth-rpc-server_test.go | 6 +- cmd/benchmark-utils_test.go | 18 ++--- cmd/bucket-handlers.go | 10 +-- cmd/bucket-notification-handlers_test.go | 8 +-- cmd/bucket-notification-utils_test.go | 6 +- cmd/build-constants.go | 9 ++- cmd/checkport_test.go | 4 +- cmd/config-migrate.go | 24 +++---- cmd/config-migrate_test.go | 10 +-- cmd/config-v13.go | 4 +- cmd/config-v13_test.go | 6 +- cmd/erasure-utils.go | 4 +- cmd/event-notifier_test.go | 20 +++--- cmd/format-config-v1_test.go | 6 +- cmd/fs-v1-helpers_test.go | 2 +- cmd/fs-v1-metadata.go | 17 ++++- cmd/fs-v1-multipart-common.go | 4 +- cmd/fs-v1-multipart_test.go | 4 +- cmd/fs-v1-rwpool_test.go | 8 +-- cmd/fs-v1.go | 4 +- cmd/fs-v1_test.go | 4 +- cmd/generic-handlers.go | 26 ++++++- cmd/globals.go | 13 ++-- cmd/handler-utils.go | 6 +- cmd/handler-utils_test.go | 10 +-- cmd/jwt_test.go | 4 +- cmd/lock-rpc-server_test.go | 22 +++--- cmd/notify-webhook_test.go | 2 +- cmd/object-api-common.go | 6 +- cmd/object-api-common_test.go | 4 +- cmd/object-api-getobject_test.go | 4 +- cmd/object-api-listobjects_test.go | 4 +- cmd/object-api-multipart_test.go | 6 +- cmd/posix-errors.go | 8 +-- cmd/posix-errors_test.go | 6 +- cmd/posix-prepare-path.go | 4 +- cmd/posix.go | 4 +- cmd/posix_test.go | 18 ++--- cmd/post-policy_test.go | 6 +- cmd/postpolicyform.go | 55 +++++++------- cmd/prepare-storage-msg.go | 18 +++-- cmd/prepare-storage-msg_test.go | 14 ++-- cmd/retry-storage_test.go | 4 +- cmd/s3-peer-client_test.go | 4 +- cmd/scan-bar.go | 92 ------------------------ cmd/server-main.go | 33 +++++---- cmd/server-main_test.go | 10 +-- cmd/server-mux.go | 26 ++++--- cmd/server-mux_test.go | 6 +- cmd/server-startup-msg.go | 4 +- cmd/server-startup-msg_test.go | 8 +-- cmd/server-startup-utils.go | 4 +- cmd/signature-v2_test.go | 2 +- cmd/signature-v4-parser_test.go | 4 +- cmd/signature-v4-utils.go | 8 +-- cmd/signature-v4-utils_test.go | 6 +- cmd/signature-v4.go | 13 ++-- cmd/signature-v4_test.go | 18 ++--- cmd/storage-rpc-client_test.go | 4 +- cmd/storage-rpc-server_test.go | 4 +- cmd/test-utils_test.go | 26 +++---- cmd/trie_test.go | 6 +- cmd/update-main.go | 8 +-- cmd/update-notifier.go | 2 +- cmd/url-sort_test.go | 12 ++-- cmd/utils.go | 10 ++- cmd/utils_test.go | 20 +++--- cmd/web-handlers_test.go | 42 +++++------ cmd/xl-v1-healing_test.go | 8 +-- cmd/xl-v1-list-objects-heal_test.go | 4 +- cmd/xl-v1-metadata.go | 31 ++++++-- cmd/xl-v1-multipart-common_test.go | 4 +- cmd/xl-v1-utils_test.go | 8 +-- 79 files changed, 461 insertions(+), 462 deletions(-) delete mode 100644 cmd/scan-bar.go diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index 15b620623..7daa801f7 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -121,7 +121,7 @@ func testServicesCmdHandler(cmd cmdType, args map[string]interface{}, t *testing // initialize NSLock. initNSLock(false) // Initialize configuration for access/secret credentials. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Unable to initialize server config. %s", err) } @@ -238,7 +238,7 @@ func TestListLocksHandler(t *testing.T) { // initialize NSLock. initNSLock(false) - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Unable to initialize server config. %s", err) } @@ -323,7 +323,7 @@ func TestClearLocksHandler(t *testing.T) { // initialize NSLock. initNSLock(false) - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Unable to initialize server config. %s", err) } diff --git a/cmd/admin-rpc-server_test.go b/cmd/admin-rpc-server_test.go index 5894514c7..5577c1b2c 100644 --- a/cmd/admin-rpc-server_test.go +++ b/cmd/admin-rpc-server_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ func testAdminCmd(cmd cmdType, t *testing.T) { // this is to make sure that the tests are not affected by modified globals. resetTestGlobals() - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Failed to create test config - %v", err) } diff --git a/cmd/api-errors.go b/cmd/api-errors.go index 99b18ccd6..8021b8098 100644 --- a/cmd/api-errors.go +++ b/cmd/api-errors.go @@ -675,15 +675,11 @@ func getAPIError(code APIErrorCode) APIError { // getErrorResponse gets in standard error and resource value and // provides a encodable populated response values func getAPIErrorResponse(err APIError, resource string) APIErrorResponse { - var data = APIErrorResponse{} - data.Code = err.Code - data.Message = err.Description - if resource != "" { - data.Resource = resource + return APIErrorResponse{ + Code: err.Code, + Message: err.Description, + Resource: resource, + RequestID: "3L137", + HostID: "3L137", } - // TODO implement this in future - data.RequestID = "3L137" - data.HostID = "3L137" - - return data } diff --git a/cmd/api-response.go b/cmd/api-response.go index f8f175903..f07779112 100644 --- a/cmd/api-response.go +++ b/cmd/api-response.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -278,8 +278,8 @@ func generateListBucketsResponse(buckets []BucketInfo) ListBucketsResponse { var data = ListBucketsResponse{} var owner = Owner{} - owner.ID = "minio" - owner.DisplayName = "minio" + owner.ID = globalMinioDefaultOwnerID + owner.DisplayName = globalMinioDefaultOwnerID for _, bucket := range buckets { var listbucket = Bucket{} @@ -301,8 +301,8 @@ func generateListObjectsV1Response(bucket, prefix, marker, delimiter string, max var owner = Owner{} var data = ListObjectsResponse{} - owner.ID = "minio" - owner.DisplayName = "minio" + owner.ID = globalMinioDefaultOwnerID + owner.DisplayName = globalMinioDefaultOwnerID for _, object := range resp.Objects { var content = Object{} @@ -315,7 +315,7 @@ func generateListObjectsV1Response(bucket, prefix, marker, delimiter string, max content.ETag = "\"" + object.MD5Sum + "\"" } content.Size = object.Size - content.StorageClass = "STANDARD" + content.StorageClass = globalMinioDefaultStorageClass content.Owner = owner // object.HealInfo is non-empty only when resp is constructed in ListObjectsHeal. content.HealInfo = object.HealInfo @@ -349,8 +349,8 @@ func generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter var data = ListObjectsV2Response{} if fetchOwner { - owner.ID = "minio" - owner.DisplayName = "minio" + owner.ID = globalMinioDefaultOwnerID + owner.DisplayName = globalMinioDefaultOwnerID } for _, object := range resp.Objects { @@ -364,7 +364,7 @@ func generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter content.ETag = "\"" + object.MD5Sum + "\"" } content.Size = object.Size - content.StorageClass = "STANDARD" + content.StorageClass = globalMinioDefaultStorageClass content.Owner = owner contents = append(contents, content) } @@ -423,11 +423,11 @@ func generateListPartsResponse(partsInfo ListPartsInfo) ListPartsResponse { listPartsResponse.Bucket = partsInfo.Bucket listPartsResponse.Key = partsInfo.Object listPartsResponse.UploadID = partsInfo.UploadID - listPartsResponse.StorageClass = "STANDARD" - listPartsResponse.Initiator.ID = "minio" - listPartsResponse.Initiator.DisplayName = "minio" - listPartsResponse.Owner.ID = "minio" - listPartsResponse.Owner.DisplayName = "minio" + listPartsResponse.StorageClass = globalMinioDefaultStorageClass + listPartsResponse.Initiator.ID = globalMinioDefaultOwnerID + listPartsResponse.Initiator.DisplayName = globalMinioDefaultOwnerID + listPartsResponse.Owner.ID = globalMinioDefaultOwnerID + listPartsResponse.Owner.DisplayName = globalMinioDefaultOwnerID listPartsResponse.MaxParts = partsInfo.MaxParts listPartsResponse.PartNumberMarker = partsInfo.PartNumberMarker diff --git a/cmd/auth-handler.go b/cmd/auth-handler.go index afb8330a8..a50219d59 100644 --- a/cmd/auth-handler.go +++ b/cmd/auth-handler.go @@ -58,12 +58,12 @@ func isRequestPresignedSignatureV2(r *http.Request) bool { // Verify if request has AWS Post policy Signature Version '4'. func isRequestPostPolicySignatureV4(r *http.Request) bool { - return strings.Contains(r.Header.Get("Content-Type"), "multipart/form-data") && r.Method == "POST" + return strings.Contains(r.Header.Get("Content-Type"), "multipart/form-data") && r.Method == httpPOST } // Verify if the request has AWS Streaming Signature Version '4'. This is only valid for 'PUT' operation. func isRequestSignStreamingV4(r *http.Request) bool { - return r.Header.Get("x-amz-content-sha256") == streamingContentSHA256 && r.Method == "PUT" + return r.Header.Get("x-amz-content-sha256") == streamingContentSHA256 && r.Method == httpPUT } // Authorization type. diff --git a/cmd/auth-handler_test.go b/cmd/auth-handler_test.go index a1a536131..de9d8e124 100644 --- a/cmd/auth-handler_test.go +++ b/cmd/auth-handler_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ func TestGetRequestAuthType(t *testing.T) { req: &http.Request{ URL: &url.URL{ Host: "localhost:9000", - Scheme: "http", + Scheme: httpScheme, Path: "/", }, Header: http.Header{ @@ -54,7 +54,7 @@ func TestGetRequestAuthType(t *testing.T) { req: &http.Request{ URL: &url.URL{ Host: "localhost:9000", - Scheme: "http", + Scheme: httpScheme, Path: "/", }, Header: http.Header{ @@ -69,7 +69,7 @@ func TestGetRequestAuthType(t *testing.T) { req: &http.Request{ URL: &url.URL{ Host: "localhost:9000", - Scheme: "http", + Scheme: httpScheme, Path: "/", }, Header: http.Header{ @@ -84,7 +84,7 @@ func TestGetRequestAuthType(t *testing.T) { req: &http.Request{ URL: &url.URL{ Host: "localhost:9000", - Scheme: "http", + Scheme: httpScheme, Path: "/", RawQuery: "X-Amz-Credential=EXAMPLEINVALIDEXAMPL%2Fs3%2F20160314%2Fus-east-1", }, @@ -97,7 +97,7 @@ func TestGetRequestAuthType(t *testing.T) { req: &http.Request{ URL: &url.URL{ Host: "localhost:9000", - Scheme: "http", + Scheme: httpScheme, Path: "/", }, Header: http.Header{ @@ -309,7 +309,7 @@ func mustNewSignedRequest(method string, urlStr string, contentLength int64, bod // Tests is requested authenticated function, tests replies for s3 errors. func TestIsReqAuthenticated(t *testing.T) { - path, err := newTestConfig("us-east-1") + path, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("unable initialize config file, %s", err) } diff --git a/cmd/auth-rpc-server_test.go b/cmd/auth-rpc-server_test.go index e95c98340..39ec686c0 100644 --- a/cmd/auth-rpc-server_test.go +++ b/cmd/auth-rpc-server_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import ( ) func TestLogin(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Failed to create test config - %v", err) } @@ -77,7 +77,7 @@ func TestLogin(t *testing.T) { // Invalid password length { args: LoginRPCArgs{ - Username: "minio", + Username: globalMinioDefaultOwnerID, Password: "aaa", Version: Version, }, diff --git a/cmd/benchmark-utils_test.go b/cmd/benchmark-utils_test.go index fd80e45bb..079fd0cfb 100644 --- a/cmd/benchmark-utils_test.go +++ b/cmd/benchmark-utils_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -148,7 +148,7 @@ func runPutObjectPartBenchmark(b *testing.B, obj ObjectLayer, partSize int) { // creates XL/FS backend setup, obtains the object layer and calls the runPutObjectPartBenchmark function. func benchmarkPutObjectPart(b *testing.B, instanceType string, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } @@ -167,7 +167,7 @@ func benchmarkPutObjectPart(b *testing.B, instanceType string, objSize int) { // creates XL/FS backend setup, obtains the object layer and calls the runPutObjectBenchmark function. func benchmarkPutObject(b *testing.B, instanceType string, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } @@ -186,7 +186,7 @@ func benchmarkPutObject(b *testing.B, instanceType string, objSize int) { // creates XL/FS backend setup, obtains the object layer and runs parallel benchmark for put object. func benchmarkPutObjectParallel(b *testing.B, instanceType string, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } @@ -206,7 +206,7 @@ func benchmarkPutObjectParallel(b *testing.B, instanceType string, objSize int) // Benchmark utility functions for ObjectLayer.GetObject(). // Creates Object layer setup ( MakeBucket, PutObject) and then runs the benchmark. func runGetObjectBenchmark(b *testing.B, obj ObjectLayer, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } @@ -275,7 +275,7 @@ func generateBytesData(size int) []byte { // creates XL/FS backend setup, obtains the object layer and calls the runGetObjectBenchmark function. func benchmarkGetObject(b *testing.B, instanceType string, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } @@ -294,7 +294,7 @@ func benchmarkGetObject(b *testing.B, instanceType string, objSize int) { // creates XL/FS backend setup, obtains the object layer and runs parallel benchmark for ObjectLayer.GetObject() . func benchmarkGetObjectParallel(b *testing.B, instanceType string, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } @@ -314,7 +314,7 @@ func benchmarkGetObjectParallel(b *testing.B, instanceType string, objSize int) // Parallel benchmark utility functions for ObjectLayer.PutObject(). // Creates Object layer setup ( MakeBucket ) and then runs the PutObject benchmark. func runPutObjectBenchmarkParallel(b *testing.B, obj ObjectLayer, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } @@ -362,7 +362,7 @@ func runPutObjectBenchmarkParallel(b *testing.B, obj ObjectLayer, objSize int) { // Parallel benchmark utility functions for ObjectLayer.GetObject(). // Creates Object layer setup ( MakeBucket, PutObject) and then runs the benchmark. func runGetObjectBenchmarkParallel(b *testing.B, obj ObjectLayer, objSize int) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index c0ebb652f..aadd99bb4 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,7 +100,7 @@ func (api objectAPIHandlers) GetBucketLocationHandler(w http.ResponseWriter, r * return } - if s3Error := checkRequestAuthType(r, bucket, "s3:GetBucketLocation", "us-east-1"); s3Error != ErrNone { + if s3Error := checkRequestAuthType(r, bucket, "s3:GetBucketLocation", globalMinioDefaultRegion); s3Error != ErrNone { writeErrorResponse(w, s3Error, r.URL) return } @@ -115,7 +115,7 @@ func (api objectAPIHandlers) GetBucketLocationHandler(w http.ResponseWriter, r * encodedSuccessResponse := encodeResponse(LocationResponse{}) // Get current region. region := serverConfig.GetRegion() - if region != "us-east-1" { + if region != globalMinioDefaultRegion { encodedSuccessResponse = encodeResponse(LocationResponse{ Location: region, }) @@ -187,7 +187,7 @@ func (api objectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.R } // ListBuckets does not have any bucket action. - s3Error := checkRequestAuthType(r, "", "", "us-east-1") + s3Error := checkRequestAuthType(r, "", "", globalMinioDefaultRegion) if s3Error == ErrInvalidRegion { // Clients like boto3 send listBuckets() call signed with region that is configured. s3Error = checkRequestAuthType(r, "", "", serverConfig.GetRegion()) @@ -334,7 +334,7 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req } // PutBucket does not have any bucket action. - if s3Error := checkRequestAuthType(r, "", "", "us-east-1"); s3Error != ErrNone { + if s3Error := checkRequestAuthType(r, "", "", globalMinioDefaultRegion); s3Error != ErrNone { writeErrorResponse(w, s3Error, r.URL) return } diff --git a/cmd/bucket-notification-handlers_test.go b/cmd/bucket-notification-handlers_test.go index 986749fdd..d4db4445c 100644 --- a/cmd/bucket-notification-handlers_test.go +++ b/cmd/bucket-notification-handlers_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ func newFlushWriter(writer io.Writer) http.ResponseWriter { // Tests write notification code. func TestWriteNotification(t *testing.T) { // Initialize a new test config. - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Unable to initialize test config %s", err) } @@ -112,7 +112,7 @@ func TestWriteNotification(t *testing.T) { func TestSendBucketNotification(t *testing.T) { // Initialize a new test config. - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Unable to initialize test config %s", err) } @@ -185,7 +185,7 @@ func testGetBucketNotificationHandler(obj ObjectLayer, instanceType, bucketName filterRules := []filterRule{ { Name: "prefix", - Value: "minio", + Value: globalMinioDefaultOwnerID, }, { Name: "suffix", diff --git a/cmd/bucket-notification-utils_test.go b/cmd/bucket-notification-utils_test.go index 0a59f30f2..22d64be3a 100644 --- a/cmd/bucket-notification-utils_test.go +++ b/cmd/bucket-notification-utils_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -218,7 +218,7 @@ func TestValidEvents(t *testing.T) { // Tests queue arn validation. func TestQueueARN(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("unable initialize config file, %s", err) } @@ -302,7 +302,7 @@ func TestQueueARN(t *testing.T) { // Test unmarshal queue arn. func TestUnmarshalSQSARN(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("unable initialize config file, %s", err) } diff --git a/cmd/build-constants.go b/cmd/build-constants.go index 0eb6c238f..ff2a55f57 100644 --- a/cmd/build-constants.go +++ b/cmd/build-constants.go @@ -22,12 +22,15 @@ var ( // GOPATH - GOPATH value at the time of build. GOPATH = "" + // Go get development tag. + goGetTag = "DEVELOPMENT.GOGET" + // Version - version time.RFC3339. - Version = "DEVELOPMENT.GOGET" + Version = goGetTag // ReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ. - ReleaseTag = "DEVELOPMENT.GOGET" + ReleaseTag = goGetTag // CommitID - latest commit id. - CommitID = "DEVELOPMENT.GOGET" + CommitID = goGetTag // ShortCommitID - first 12 characters from CommitID. ShortCommitID = CommitID[:12] ) diff --git a/cmd/checkport_test.go b/cmd/checkport_test.go index 9b3c4c087..bbdb01dd7 100644 --- a/cmd/checkport_test.go +++ b/cmd/checkport_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ func TestCheckPortAvailability(t *testing.T) { err = checkPortAvailability(test.port) // Skip if the os is windows due to https://github.com/golang/go/issues/7598 - if err == nil && runtime.GOOS != "windows" { + if err == nil && runtime.GOOS != globalWindowsOSName { t.Fatalf("checkPortAvailability should fail for port: %s. Error: %v", test.port, err) } } diff --git a/cmd/config-migrate.go b/cmd/config-migrate.go index acf72f017..f153f17ff 100644 --- a/cmd/config-migrate.go +++ b/cmd/config-migrate.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,7 +127,7 @@ func migrateV2ToV3() error { srvConfig.Region = cv2.Credentials.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature V4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = consoleLogger{ Enable: true, @@ -191,7 +191,7 @@ func migrateV3ToV4() error { srvConfig.Region = cv3.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv3.Logger.Console srvConfig.Logger.File = cv3.Logger.File @@ -237,7 +237,7 @@ func migrateV4ToV5() error { srvConfig.Region = cv4.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv4.Logger.Console srvConfig.Logger.File = cv4.Logger.File @@ -286,7 +286,7 @@ func migrateV5ToV6() error { srvConfig.Region = cv5.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv5.Logger.Console srvConfig.Logger.File = cv5.Logger.File @@ -362,7 +362,7 @@ func migrateV6ToV7() error { srvConfig.Region = cv6.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv6.Logger.Console srvConfig.Logger.File = cv6.Logger.File @@ -426,7 +426,7 @@ func migrateV7ToV8() error { srvConfig.Region = cv7.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv7.Logger.Console srvConfig.Logger.File = cv7.Logger.File @@ -496,7 +496,7 @@ func migrateV8ToV9() error { srvConfig.Region = cv8.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv8.Logger.Console srvConfig.Logger.Console.Level = "error" @@ -583,7 +583,7 @@ func migrateV9ToV10() error { srvConfig.Region = cv9.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv9.Logger.Console srvConfig.Logger.File = cv9.Logger.File @@ -668,7 +668,7 @@ func migrateV10ToV11() error { srvConfig.Region = cv10.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv10.Logger.Console srvConfig.Logger.File = cv10.Logger.File @@ -756,7 +756,7 @@ func migrateV11ToV12() error { srvConfig.Region = cv11.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv11.Logger.Console srvConfig.Logger.File = cv11.Logger.File @@ -861,7 +861,7 @@ func migrateV12ToV13() error { srvConfig.Region = cv12.Region if srvConfig.Region == "" { // Region needs to be set for AWS Signature Version 4. - srvConfig.Region = "us-east-1" + srvConfig.Region = globalMinioDefaultRegion } srvConfig.Logger.Console = cv12.Logger.Console srvConfig.Logger.File = cv12.Logger.File diff --git a/cmd/config-migrate_test.go b/cmd/config-migrate_test.go index e5478cd00..c5b8a0827 100644 --- a/cmd/config-migrate_test.go +++ b/cmd/config-migrate_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( // Test if config v1 is purged func TestServerConfigMigrateV1(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -58,7 +58,7 @@ func TestServerConfigMigrateV1(t *testing.T) { // Test if all migrate code returns nil when config file does not // exist func TestServerConfigMigrateInexistentConfig(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -110,7 +110,7 @@ func TestServerConfigMigrateInexistentConfig(t *testing.T) { // Test if a config migration from v2 to v12 is successfully done func TestServerConfigMigrateV2toV12(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -169,7 +169,7 @@ func TestServerConfigMigrateV2toV12(t *testing.T) { // Test if all migrate code returns error with corrupted config files func TestServerConfigMigrateFaultyConfig(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } diff --git a/cmd/config-v13.go b/cmd/config-v13.go index b29419699..5ba8b78c6 100644 --- a/cmd/config-v13.go +++ b/cmd/config-v13.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ func initConfig() (bool, error) { // Initialize server config. srvCfg := &serverConfigV13{} srvCfg.Version = globalMinioConfigVersion - srvCfg.Region = "us-east-1" + srvCfg.Region = globalMinioDefaultRegion srvCfg.Credential = newCredential() // Enable console logger by default on a fresh run. diff --git a/cmd/config-v13_test.go b/cmd/config-v13_test.go index 5a80e43aa..54312714e 100644 --- a/cmd/config-v13_test.go +++ b/cmd/config-v13_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,14 +22,14 @@ import ( ) func TestServerConfig(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } // remove the root directory after the test ends. defer removeAll(rootPath) - if serverConfig.GetRegion() != "us-east-1" { + if serverConfig.GetRegion() != globalMinioDefaultRegion { t.Errorf("Expecting region `us-east-1` found %s", serverConfig.GetRegion()) } diff --git a/cmd/erasure-utils.go b/cmd/erasure-utils.go index c9b5f2f28..814df1c47 100644 --- a/cmd/erasure-utils.go +++ b/cmd/erasure-utils.go @@ -40,11 +40,11 @@ func newHashWriters(diskCount int, algo string) []hash.Hash { // newHash - gives you a newly allocated hash depending on the input algorithm. func newHash(algo string) (h hash.Hash) { switch algo { - case "sha256": + case sha256Algo: // sha256 checksum specially on ARM64 platforms or whenever // requested as dictated by `xl.json` entry. h = sha256.New() - case "blake2b": + case blake2bAlgo: // ignore the error, because New512 without a key never fails // New512 only returns a non-nil error, if the length of the passed // key > 64 bytes - but we use blake2b as hash function (no key) diff --git a/cmd/event-notifier_test.go b/cmd/event-notifier_test.go index 89556b0c1..0b52f65da 100644 --- a/cmd/event-notifier_test.go +++ b/cmd/event-notifier_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import ( // Test InitEventNotifier with faulty disks func TestInitEventNotifierFaultyDisks(t *testing.T) { // Prepare for tests - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -85,7 +85,7 @@ func TestInitEventNotifierFaultyDisks(t *testing.T) { func TestInitEventNotifierWithPostgreSQL(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -116,7 +116,7 @@ func TestInitEventNotifierWithPostgreSQL(t *testing.T) { func TestInitEventNotifierWithNATS(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -147,7 +147,7 @@ func TestInitEventNotifierWithNATS(t *testing.T) { func TestInitEventNotifierWithWebHook(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -178,7 +178,7 @@ func TestInitEventNotifierWithWebHook(t *testing.T) { func TestInitEventNotifierWithAMQP(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -209,7 +209,7 @@ func TestInitEventNotifierWithAMQP(t *testing.T) { func TestInitEventNotifierWithElasticSearch(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -240,7 +240,7 @@ func TestInitEventNotifierWithElasticSearch(t *testing.T) { func TestInitEventNotifierWithRedis(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -346,7 +346,7 @@ func TestInitEventNotifier(t *testing.T) { filterRules := []filterRule{ { Name: "prefix", - Value: "minio", + Value: globalMinioDefaultOwnerID, }, { Name: "suffix", @@ -569,7 +569,7 @@ func TestAddRemoveBucketListenerConfig(t *testing.T) { filterRules := []filterRule{ { Name: "prefix", - Value: "minio", + Value: globalMinioDefaultOwnerID, }, { Name: "suffix", diff --git a/cmd/format-config-v1_test.go b/cmd/format-config-v1_test.go index 8e46fdde3..b92532b0a 100644 --- a/cmd/format-config-v1_test.go +++ b/cmd/format-config-v1_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -812,7 +812,7 @@ func TestLoadFormatXLErrs(t *testing.T) { // Tests for healFormatXLCorruptedDisks() with cases which lead to errors func TestHealFormatXLCorruptedDisksErrs(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } @@ -968,7 +968,7 @@ func TestHealFormatXLCorruptedDisksErrs(t *testing.T) { // Tests for healFormatXLFreshDisks() with cases which lead to errors func TestHealFormatXLFreshDisksErrs(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } diff --git a/cmd/fs-v1-helpers_test.go b/cmd/fs-v1-helpers_test.go index ef815ebad..67541f670 100644 --- a/cmd/fs-v1-helpers_test.go +++ b/cmd/fs-v1-helpers_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cmd/fs-v1-metadata.go b/cmd/fs-v1-metadata.go index 99d475541..ae0b3532a 100644 --- a/cmd/fs-v1-metadata.go +++ b/cmd/fs-v1-metadata.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -164,11 +164,22 @@ func (m *fsMetaV1) ReadFrom(reader io.Reader) (n int64, err error) { return int64(len(metadataBytes)), nil } +// FS metadata constants. +const ( + // FS backend meta version. + fsMetaVersion = "1.0.0" + + // FS backend meta format. + fsMetaFormat = "fs" + + // Add more constants here. +) + // newFSMetaV1 - initializes new fsMetaV1. func newFSMetaV1() (fsMeta fsMetaV1) { fsMeta = fsMetaV1{} - fsMeta.Version = "1.0.0" - fsMeta.Format = "fs" + fsMeta.Version = fsMetaVersion + fsMeta.Format = fsMetaFormat fsMeta.Minio.Release = ReleaseTag return fsMeta } diff --git a/cmd/fs-v1-multipart-common.go b/cmd/fs-v1-multipart-common.go index c7b9c7f63..940b0645e 100644 --- a/cmd/fs-v1-multipart-common.go +++ b/cmd/fs-v1-multipart-common.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ func (fs fsObjects) deleteUploadsJSON(bucket, object, uploadID string) error { uploadsMetaPath := pathJoin(uploadPath, uploadsJSONFile) // Special case for windows please read through. - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { // Ordinarily windows does not permit deletion or renaming of files still // in use, but if all open handles to that file were opened with FILE_SHARE_DELETE // then it can permit renames and deletions of open files. diff --git a/cmd/fs-v1-multipart_test.go b/cmd/fs-v1-multipart_test.go index 660b7af78..ee6126fed 100644 --- a/cmd/fs-v1-multipart_test.go +++ b/cmd/fs-v1-multipart_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ func TestNewMultipartUploadFaultyDisk(t *testing.T) { // TestPutObjectPartFaultyDisk - test PutObjectPart with faulty disks func TestPutObjectPartFaultyDisk(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } diff --git a/cmd/fs-v1-rwpool_test.go b/cmd/fs-v1-rwpool_test.go index 4a9280f33..dc9459379 100644 --- a/cmd/fs-v1-rwpool_test.go +++ b/cmd/fs-v1-rwpool_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,7 +69,7 @@ func TestRWPool(t *testing.T) { // Fails to create a file if there is a directory. _, err = rwPool.Create(pathJoin(path, "success-vol", "file")) - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { if err != errFileAccessDenied { t.Fatal("Unexpected error", err) } @@ -87,7 +87,7 @@ func TestRWPool(t *testing.T) { // Fails to read a directory. _, err = rwPool.Open(pathJoin(path, "success-vol", "file")) - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { if err != errFileAccessDenied { t.Fatal("Unexpected error", err) } @@ -99,7 +99,7 @@ func TestRWPool(t *testing.T) { // Fails to open a file which has a parent as file. _, err = rwPool.Open(pathJoin(path, "success-vol", "file/path/1.txt/test")) - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { if err != errFileAccessDenied { t.Fatal("Unexpected error", err) } diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index 6f33594e7..24c25b124 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -179,7 +179,7 @@ func newFSObjectLayer(fsPath string) (ObjectLayer, error) { func (fs fsObjects) checkDiskFree() (err error) { // We don't validate disk space or inode utilization on windows. // Each windows calls to 'GetVolumeInformationW' takes around 3-5seconds. - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { return nil } diff --git a/cmd/fs-v1_test.go b/cmd/fs-v1_test.go index e0176d18e..97d2d36c4 100644 --- a/cmd/fs-v1_test.go +++ b/cmd/fs-v1_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ func TestNewFS(t *testing.T) { // TestFSShutdown - initialize a new FS object layer then calls // Shutdown to check returned results func TestFSShutdown(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } diff --git a/cmd/generic-handlers.go b/cmd/generic-handlers.go index e0850b3f4..974045687 100644 --- a/cmd/generic-handlers.go +++ b/cmd/generic-handlers.go @@ -139,7 +139,7 @@ func setBrowserCacheControlHandler(h http.Handler) http.Handler { } func (h cacheControlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method == "GET" && guessIsBrowserReq(r) && globalIsBrowserEnabled { + if r.Method == httpGET && guessIsBrowserReq(r) && globalIsBrowserEnabled { // For all browser requests set appropriate Cache-Control policies if strings.HasPrefix(r.URL.Path, reservedBucket+"/") { if strings.HasSuffix(r.URL.Path, ".js") || r.URL.Path == reservedBucket+"/favicon.ico" { @@ -249,11 +249,31 @@ type resourceHandler struct { handler http.Handler } +// List of http methods. +const ( + httpGET = "GET" + httpPUT = "PUT" + httpHEAD = "HEAD" + httpPOST = "POST" + httpDELETE = "DELETE" + httpOPTIONS = "OPTIONS" +) + +// List of default allowable HTTP methods. +var defaultAllowableHTTPMethods = []string{ + httpGET, + httpPUT, + httpHEAD, + httpPOST, + httpDELETE, + httpOPTIONS, +} + // setCorsHandler handler for CORS (Cross Origin Resource Sharing) func setCorsHandler(h http.Handler) http.Handler { c := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"}, + AllowedMethods: defaultAllowableHTTPMethods, AllowedHeaders: []string{"*"}, ExposedHeaders: []string{"ETag"}, }) @@ -328,7 +348,7 @@ func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } // A put method on path "/" doesn't make sense, ignore it. - if r.Method == "PUT" && r.URL.Path == "/" { + if r.Method == httpPUT && r.URL.Path == "/" { writeErrorResponse(w, ErrNotImplemented, r.URL) return } diff --git a/cmd/globals.go b/cmd/globals.go index ce3a0a983..c2f2a7861 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,6 +45,11 @@ const ( globalMinioKeyFile = "private.key" globalMinioConfigFile = "config.json" globalMinioCertExpireWarnDays = time.Hour * 24 * 30 // 30 days. + + globalMinioDefaultRegion = "us-east-1" + globalMinioDefaultOwnerID = "minio" + globalMinioDefaultStorageClass = "STANDARD" + globalWindowsOSName = "windows" // Add new global values here. ) @@ -118,10 +123,8 @@ var ( // global colors. var ( - colorRed = color.New(color.FgRed).SprintFunc() - colorBold = color.New(color.Bold).SprintFunc() - colorBlue = color.New(color.FgBlue).SprintfFunc() - colorGreen = color.New(color.FgGreen).SprintfFunc() + colorBold = color.New(color.Bold).SprintFunc() + colorBlue = color.New(color.FgBlue).SprintfFunc() ) // Parse command arguments and set global variables accordingly diff --git a/cmd/handler-utils.go b/cmd/handler-utils.go index 23d227140..a97f0f192 100644 --- a/cmd/handler-utils.go +++ b/cmd/handler-utils.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,9 +39,9 @@ func isValidLocationConstraint(r *http.Request) (s3Error APIErrorCode) { // Once region has been obtained we proceed to verify it. incomingRegion := locationConstraint.Location if incomingRegion == "" { - // Location constraint is empty for region "us-east-1", + // Location constraint is empty for region globalMinioDefaultRegion, // in accordance with protocol. - incomingRegion = "us-east-1" + incomingRegion = globalMinioDefaultRegion } // Return errInvalidRegion if location constraint does not match // with configured region. diff --git a/cmd/handler-utils_test.go b/cmd/handler-utils_test.go index bedd705ad..0bf34b3c5 100644 --- a/cmd/handler-utils_test.go +++ b/cmd/handler-utils_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import ( // Tests validate bucket LocationConstraint. func TestIsValidLocationContraint(t *testing.T) { - path, err := newTestConfig("us-east-1") + path, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("unable initialize config file, %s", err) } @@ -63,12 +63,12 @@ func TestIsValidLocationContraint(t *testing.T) { expectedCode APIErrorCode }{ // Test case - 1. - {"us-east-1", "us-east-1", ErrNone}, + {globalMinioDefaultRegion, globalMinioDefaultRegion, ErrNone}, // Test case - 2. // In case of empty request body ErrNone is returned. - {"", "us-east-1", ErrNone}, + {"", globalMinioDefaultRegion, ErrNone}, // Test case - 3. - {"eu-central-1", "us-east-1", ErrInvalidRegion}, + {"eu-central-1", globalMinioDefaultRegion, ErrInvalidRegion}, } for i, testCase := range testCases { inputRequest, e := createExpectedRequest(&http.Request{}, testCase.locationForInputRequest) diff --git a/cmd/jwt_test.go b/cmd/jwt_test.go index 341ecd591..32cdfa8fe 100644 --- a/cmd/jwt_test.go +++ b/cmd/jwt_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package cmd import "testing" func testAuthenticate(authType string, t *testing.T) { - testPath, err := newTestConfig("us-east-1") + testPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("unable initialize config file, %s", err) } diff --git a/cmd/lock-rpc-server_test.go b/cmd/lock-rpc-server_test.go index 9e406dbda..3251a37bb 100644 --- a/cmd/lock-rpc-server_test.go +++ b/cmd/lock-rpc-server_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ func testLockEquality(lriLeft, lriRight []lockRequesterInfo) bool { // Helper function to create a lock server for testing func createLockTestServer(t *testing.T) (string, *lockServer, string) { - testPath, err := newTestConfig("us-east-1") + testPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("unable initialize config file, %s", err) } @@ -446,7 +446,7 @@ func TestLockRpcServerExpired(t *testing.T) { // Test initialization of lock servers. func TestLockServers(t *testing.T) { - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { return } @@ -466,19 +466,19 @@ func TestLockServers(t *testing.T) { isDistXL: true, srvCmdConfig: serverCmdConfig{ endpoints: []*url.URL{{ - Scheme: "http", + Scheme: httpScheme, Host: "localhost:9000", Path: "/mnt/disk1", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.1.2:9000", Path: "/mnt/disk2", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.1:9000", Path: "/mnt/disk3", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.2:9000", Path: "/mnt/disk4", }}, @@ -490,19 +490,19 @@ func TestLockServers(t *testing.T) { isDistXL: true, srvCmdConfig: serverCmdConfig{ endpoints: []*url.URL{{ - Scheme: "http", + Scheme: httpScheme, Host: "localhost:9000", Path: "/mnt/disk1", }, { - Scheme: "http", + Scheme: httpScheme, Host: "localhost:9000", Path: "/mnt/disk2", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.1:9000", Path: "/mnt/disk3", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.2:9000", Path: "/mnt/disk4", }}, diff --git a/cmd/notify-webhook_test.go b/cmd/notify-webhook_test.go index 3f298694f..4740901f0 100644 --- a/cmd/notify-webhook_test.go +++ b/cmd/notify-webhook_test.go @@ -40,7 +40,7 @@ func (p postHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Tests web hook initialization. func TestNewWebHookNotify(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } diff --git a/cmd/object-api-common.go b/cmd/object-api-common.go index aaf2d8c43..a371e3553 100644 --- a/cmd/object-api-common.go +++ b/cmd/object-api-common.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -159,12 +159,12 @@ func getPath(ep *url.URL) string { } var diskPath string // For windows ep.Path is usually empty - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { switch ep.Scheme { case "": // Eg. "minio server .\export" diskPath = ep.Path - case "http", "https": + case httpScheme, httpsScheme: // For full URLs windows drive is part of URL path. // Eg: http://ip:port/C:\mydrive // For windows trim off the preceding "/". diff --git a/cmd/object-api-common_test.go b/cmd/object-api-common_test.go index 3946f4d67..d312901c5 100644 --- a/cmd/object-api-common_test.go +++ b/cmd/object-api-common_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -106,7 +106,7 @@ func TestGetPath(t *testing.T) { epStr string path string } - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { testCases = []struct { epStr string path string diff --git a/cmd/object-api-getobject_test.go b/cmd/object-api-getobject_test.go index 5385952a9..1e6b429a7 100644 --- a/cmd/object-api-getobject_test.go +++ b/cmd/object-api-getobject_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -182,7 +182,7 @@ func testGetObject(obj ObjectLayer, instanceType string, t TestErrHandler) { // Wrapper for calling GetObject with permission denied expected func TestGetObjectPermissionDenied(t *testing.T) { // Windows doesn't support Chmod under golang - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { ExecObjectLayerDiskAlteredTest(t, testGetObjectPermissionDenied) } } diff --git a/cmd/object-api-listobjects_test.go b/cmd/object-api-listobjects_test.go index 8b3d4e94d..2b25441a0 100644 --- a/cmd/object-api-listobjects_test.go +++ b/cmd/object-api-listobjects_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015-2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015-2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -588,7 +588,7 @@ func BenchmarkListObjects(b *testing.B) { } defer removeAll(directory) // initialize the root directory. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { b.Fatalf("Unable to initialize config. %s", err) } diff --git a/cmd/object-api-multipart_test.go b/cmd/object-api-multipart_test.go index abb5f8841..5e0146f3e 100644 --- a/cmd/object-api-multipart_test.go +++ b/cmd/object-api-multipart_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1061,7 +1061,7 @@ func testListMultipartUploads(obj ObjectLayer, instanceType string, t TestErrHan { MaxUploads: 10, IsTruncated: false, - Prefix: "minio", + Prefix: globalMinioDefaultOwnerID, UploadIDMarker: uploadIDs[4], Uploads: []uploadMetadata{ { @@ -1201,7 +1201,7 @@ func testListMultipartUploads(obj ObjectLayer, instanceType string, t TestErrHan // Test case with `prefix` and `KeyMarker` (Test number 48). {bucketNames[2], "minio-object", objectNames[1], "", "", 10, listMultipartResults[34], nil, true}, // Test case with `prefix` and `uploadIDMarker` (Test number 49). - // {bucketNames[2], "minio", "", uploadIDs[4], "", 10, listMultipartResults[35], nil, true}, + // {bucketNames[2], globalMinioDefaultOwnerID, "", uploadIDs[4], "", 10, listMultipartResults[35], nil, true}, // Test case with `KeyMarker` and `uploadIDMarker` (Test number 50). // {bucketNames[2], "minio-object.txt", "", uploadIDs[5], "", 10, listMultipartResults[36], nil, true}, } diff --git a/cmd/posix-errors.go b/cmd/posix-errors.go index dfa583257..7bdde538d 100644 --- a/cmd/posix-errors.go +++ b/cmd/posix-errors.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,7 +79,7 @@ func isSysErrTooLong(err error) bool { // and ERROR_DIR_NOT_EMPTY for windows (directory not empty). func isSysErrNotEmpty(err error) bool { if pathErr, ok := err.(*os.PathError); ok { - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { if errno, _ok := pathErr.Err.(syscall.Errno); _ok && errno == 0x91 { // ERROR_DIR_NOT_EMPTY return true @@ -95,7 +95,7 @@ func isSysErrNotEmpty(err error) bool { // Check if the given error corresponds to the specific ERROR_PATH_NOT_FOUND for windows func isSysErrPathNotFound(err error) bool { - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { return false } if pathErr, ok := err.(*os.PathError); ok { @@ -109,7 +109,7 @@ func isSysErrPathNotFound(err error) bool { // Check if the given error corresponds to the specific ERROR_INVALID_HANDLE for windows func isSysErrHandleInvalid(err error) bool { - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { return false } // Check if err contains ERROR_INVALID_HANDLE errno diff --git a/cmd/posix-errors_test.go b/cmd/posix-errors_test.go index 498022f50..254744d6a 100644 --- a/cmd/posix-errors_test.go +++ b/cmd/posix-errors_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ func TestSysErrors(t *testing.T) { if !ok { t.Fatalf("Unexpected error expecting %s", syscall.ENOTDIR) } - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { pathErr = &os.PathError{Err: syscall.ENOTEMPTY} ok = isSysErrNotEmpty(pathErr) if !ok { @@ -47,7 +47,7 @@ func TestSysErrors(t *testing.T) { t.Fatal("Unexpected error expecting 0x91") } } - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { pathErr = &os.PathError{Err: syscall.Errno(0x03)} ok = isSysErrPathNotFound(pathErr) if !ok { diff --git a/cmd/posix-prepare-path.go b/cmd/posix-prepare-path.go index 23db02eed..5cd3ed8ee 100644 --- a/cmd/posix-prepare-path.go +++ b/cmd/posix-prepare-path.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( // preparePath rewrites path to handle any OS specific details. func preparePath(path string) string { - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { // Microsoft Windows supports long path names using // uniform naming convention (UNC). return UNCPath(path) diff --git a/cmd/posix.go b/cmd/posix.go index bdfb9652b..cc4ff340f 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -157,7 +157,7 @@ func getDiskInfo(diskPath string) (di disk.Info, err error) { func (s *posix) checkDiskFree() (err error) { // We don't validate disk space or inode utilization on windows. // Each windows calls to 'GetVolumeInformationW' takes around 3-5seconds. - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { return nil } diff --git a/cmd/posix_test.go b/cmd/posix_test.go index f1dc0b428..e7fb98927 100644 --- a/cmd/posix_test.go +++ b/cmd/posix_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -286,7 +286,7 @@ func TestPosixMakeVol(t *testing.T) { } // TestPosix for permission denied. - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { // Initialize posix storage layer for permission denied error. posix, err := newPosix("/usr") if err != nil { @@ -377,7 +377,7 @@ func TestPosixDeleteVol(t *testing.T) { } // TestPosix for permission denied. - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { // Initialize posix storage layer for permission denied error. posixStorage, err = newPosix("/usr") if err != nil { @@ -656,7 +656,7 @@ func TestPosixPosixListDir(t *testing.T) { } // TestPosix for permission denied. - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { // Initialize posix storage layer for permission denied error. posixStorage, err = newPosix("/usr") if err != nil { @@ -770,7 +770,7 @@ func TestPosixDeleteFile(t *testing.T) { } // TestPosix for permission denied. - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { // Initialize posix storage layer for permission denied error. posixStorage, err = newPosix("/usr") if err != nil { @@ -881,7 +881,7 @@ func TestPosixReadFile(t *testing.T) { -1, 5, nil, func() error { - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { return &os.PathError{ Op: "seek", Path: preparePath(slashpath.Join(path, "success-vol", "myobject")), @@ -937,7 +937,7 @@ func TestPosixReadFile(t *testing.T) { if err != nil && testCase.expectedErr != nil { // Validate if the type string of the errors are an exact match. if err.Error() != testCase.expectedErr.Error() { - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { t.Errorf("Case: %d %#v, expected: %s, got: %s", i+1, testCase, testCase.expectedErr, err) } else { var resultErrno, expectErrno uintptr @@ -1075,7 +1075,7 @@ func TestPosixAppendFile(t *testing.T) { } // TestPosix for permission denied. - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { // Initialize posix storage layer for permission denied error. posixStorage, err = newPosix("/usr") if err != nil { @@ -1162,7 +1162,7 @@ func TestPosixPrepareFile(t *testing.T) { } // TestPosix for permission denied. - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { // Initialize posix storage layer for permission denied error. posixStorage, err = newPosix("/usr") if err != nil { diff --git a/cmd/post-policy_test.go b/cmd/post-policy_test.go index 52bd96058..60333e3a3 100644 --- a/cmd/post-policy_test.go +++ b/cmd/post-policy_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,7 +115,7 @@ func TestPostPolicyBucketHandler(t *testing.T) { // testPostPolicyBucketHandler - Tests validate post policy handler uploading objects. func testPostPolicyBucketHandler(obj ObjectLayer, instanceType string, t TestErrHandler) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Initializing config.json failed") } @@ -402,7 +402,7 @@ func TestPostPolicyBucketHandlerRedirect(t *testing.T) { // testPostPolicyBucketHandlerRedirect tests POST Object when success_action_redirect is specified func testPostPolicyBucketHandlerRedirect(obj ObjectLayer, instanceType string, t TestErrHandler) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Initializing config.json failed") } diff --git a/cmd/postpolicyform.go b/cmd/postpolicyform.go index b3c8aeb04..799f5f818 100644 --- a/cmd/postpolicyform.go +++ b/cmd/postpolicyform.go @@ -27,6 +27,31 @@ import ( "time" ) +// startWithConds - map which indicates if a given condition supports starts-with policy operator +var startsWithConds = map[string]bool{ + "$acl": true, + "$bucket": false, + "$cache-control": true, + "$content-type": true, + "$content-disposition": true, + "$content-encoding": true, + "$expires": true, + "$key": true, + "$success_action_redirect": true, + "$redirect": true, + "$success_action_status": false, + "$x-amz-algorithm": false, + "$x-amz-credential": false, + "$x-amz-date": false, +} + +// Add policy conditionals. +const ( + policyCondEqual = "eq" + policyCondStartsWith = "starts-with" + policyCondContentLength = "content-length-range" +) + // toString - Safely convert interface to string without causing panic. func toString(val interface{}) string { switch v := val.(type) { @@ -127,7 +152,7 @@ func parsePostPolicyForm(policy string) (PostPolicyForm, error) { Operator string Value string }{ - Operator: "eq", + Operator: policyCondEqual, Value: toString(v), } } @@ -136,7 +161,7 @@ func parsePostPolicyForm(policy string) (PostPolicyForm, error) { return parsedPolicy, fmt.Errorf("Malformed conditional fields %s of type %s found in POST policy form", condt, reflect.TypeOf(condt).String()) } switch toLowerString(condt[0]) { - case "eq", "starts-with": + case policyCondEqual, policyCondStartsWith: for _, v := range condt { // Pre-check all values for type. if !isString(v) { // All values must be of type string. @@ -151,7 +176,7 @@ func parsePostPolicyForm(policy string) (PostPolicyForm, error) { Operator: operator, Value: value, } - case "content-length-range": + case policyCondContentLength: min, err := toInteger(condt[1]) if err != nil { return parsedPolicy, err @@ -180,31 +205,13 @@ func parsePostPolicyForm(policy string) (PostPolicyForm, error) { return parsedPolicy, nil } -// startWithConds - map which indicates if a given condition supports starts-with policy operator -var startsWithConds = map[string]bool{ - "$acl": true, - "$bucket": false, - "$cache-control": true, - "$content-type": true, - "$content-disposition": true, - "$content-encoding": true, - "$expires": true, - "$key": true, - "$success_action_redirect": true, - "$redirect": true, - "$success_action_status": false, - "$x-amz-algorithm": false, - "$x-amz-credential": false, - "$x-amz-date": false, -} - // checkPolicyCond returns a boolean to indicate if a condition is satisified according // to the passed operator func checkPolicyCond(op string, input1, input2 string) bool { switch op { - case "eq": + case policyCondEqual: return input1 == input2 - case "starts-with": + case policyCondStartsWith: return strings.HasPrefix(input1, input2) } return false @@ -231,7 +238,7 @@ func checkPostPolicy(formValues map[string]string, postPolicyForm PostPolicyForm // If the current policy condition is known if startsWithSupported, condFound := startsWithConds[cond]; condFound { // Check if the current condition supports starts-with operator - if op == "starts-with" && !startsWithSupported { + if op == policyCondStartsWith && !startsWithSupported { return ErrAccessDenied } // Check if current policy condition is satisfied diff --git a/cmd/prepare-storage-msg.go b/cmd/prepare-storage-msg.go index 9cc699b9f..445bbefca 100644 --- a/cmd/prepare-storage-msg.go +++ b/cmd/prepare-storage-msg.go @@ -65,9 +65,9 @@ func printHealMsg(endpoints []*url.URL, storageDisks []StorageAPI, fn printOnceF // for single node XL, distributed XL and when minio server is bound // to a specific ip:port. func getHealEndpoint(tls bool, firstEndpoint *url.URL) (cEndpoint *url.URL) { - scheme := "http" + scheme := httpScheme if tls { - scheme = "https" + scheme = httpsScheme } cEndpoint = &url.URL{ Scheme: scheme, @@ -93,6 +93,12 @@ func getHealEndpoint(tls bool, firstEndpoint *url.URL) (cEndpoint *url.URL) { return cEndpoint } +// Disks offline and online strings.. +const ( + diskOffline = "offline" + diskOnline = "online" +) + // Constructs a formatted heal message, when cluster is found to be in state where it requires healing. // healing is optional, server continues to initialize object layer after printing this message. // it is upto the end user to perform a heal if needed. @@ -112,9 +118,9 @@ func getHealMsg(endpoints []*url.URL, storageDisks []StorageAPI) string { humanize.IBytes(uint64(info.Total)), func() string { if info.Total > 0 { - return "online" + return diskOnline } - return "offline" + return diskOffline }(), ) } @@ -142,9 +148,9 @@ func getStorageInitMsg(titleMsg string, endpoints []*url.URL, storageDisks []Sto humanize.IBytes(uint64(info.Total)), func() string { if info.Total > 0 { - return "online" + return diskOnline } - return "offline" + return diskOffline }(), ) } diff --git a/cmd/prepare-storage-msg_test.go b/cmd/prepare-storage-msg_test.go index 5b39a50e9..af5c9bf1a 100644 --- a/cmd/prepare-storage-msg_test.go +++ b/cmd/prepare-storage-msg_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,11 @@ func TestGetHealEndpoint(t *testing.T) { // Test for a SSL scheme. tls := true hURL := getHealEndpoint(tls, &url.URL{ - Scheme: "http", + Scheme: httpScheme, Host: "localhost:9000", }) sHURL := &url.URL{ - Scheme: "https", + Scheme: httpsScheme, Host: "localhost:9000", } if !reflect.DeepEqual(hURL, sHURL) { @@ -41,11 +41,11 @@ func TestGetHealEndpoint(t *testing.T) { // Test a non-TLS scheme. tls = false hURL = getHealEndpoint(tls, &url.URL{ - Scheme: "https", + Scheme: httpsScheme, Host: "localhost:9000", }) sHURL = &url.URL{ - Scheme: "http", + Scheme: httpScheme, Host: "localhost:9000", } if !reflect.DeepEqual(hURL, sHURL) { @@ -61,7 +61,7 @@ func TestGetHealEndpoint(t *testing.T) { Path: "/export", }) sHURL = &url.URL{ - Scheme: "http", + Scheme: httpScheme, Host: "", } globalMinioAddr = "" @@ -73,7 +73,7 @@ func TestGetHealEndpoint(t *testing.T) { // Tests heal message to be correct and properly formatted. func TestHealMsg(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Unable to initialize test config", err) } diff --git a/cmd/retry-storage_test.go b/cmd/retry-storage_test.go index 04556323b..5642910f8 100644 --- a/cmd/retry-storage_test.go +++ b/cmd/retry-storage_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import ( // Tests retry storage. func TestRetryStorage(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } diff --git a/cmd/s3-peer-client_test.go b/cmd/s3-peer-client_test.go index 023bb619a..4c6824d04 100644 --- a/cmd/s3-peer-client_test.go +++ b/cmd/s3-peer-client_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import ( // endpoints. func TestMakeS3Peers(t *testing.T) { // Initialize configuration - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("%s", err) } diff --git a/cmd/scan-bar.go b/cmd/scan-bar.go deleted file mode 100644 index fbfa5ad75..000000000 --- a/cmd/scan-bar.go +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Minio Cloud Storage (C) 2016 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 cmd - -import ( - "fmt" - "runtime" - "strings" - - "github.com/cheggaaa/pb" - "github.com/dustin/go-humanize" - "github.com/minio/mc/pkg/console" -) - -// fixateScanBar truncates or stretches text to fit within the terminal size. -func fixateScanBar(text string, width int) string { - if len([]rune(text)) > width { - // Trim text to fit within the screen - trimSize := len([]rune(text)) - width + 3 //"..." - if trimSize < len([]rune(text)) { - text = "..." + text[trimSize:] - } - } else { - text += strings.Repeat(" ", width-len([]rune(text))) - } - return text -} - -// Progress bar function report objects being scaned. -type scanBarFunc func(string) - -// scanBarFactory returns a progress bar function to report URL scanning. -func scanBarFactory() scanBarFunc { - fileCount := 0 - termWidth, err := pb.GetTerminalWidth() - if err != nil { - termWidth = 80 - } - - // Cursor animate channel. - cursorCh := cursorAnimate() - return func(source string) { - scanPrefix := fmt.Sprintf("[%s] %s ", humanize.Comma(int64(fileCount)), string(<-cursorCh)) - source = fixateScanBar(source, termWidth-len([]rune(scanPrefix))) - barText := scanPrefix + source - console.PrintC("\r" + barText + "\r") - fileCount++ - } -} - -// cursorAnimate - returns a animated rune through read channel for every read. -func cursorAnimate() <-chan rune { - cursorCh := make(chan rune) - var cursors string - - switch runtime.GOOS { - case "linux": - // cursors = "➩➪➫➬➭➮➯➱" - // cursors = "▁▃▄▅▆▇█▇▆▅▄▃" - cursors = "◐◓◑◒" - // cursors = "←↖↑↗→↘↓↙" - // cursors = "◴◷◶◵" - // cursors = "◰◳◲◱" - //cursors = "⣾⣽⣻⢿⡿⣟⣯⣷" - case "darwin": - cursors = "◐◓◑◒" - default: - cursors = "|/-\\" - } - go func() { - for { - for _, cursor := range cursors { - cursorCh <- cursor - } - } - }() - return cursorCh -} diff --git a/cmd/server-main.go b/cmd/server-main.go index ea0a373dd..87f9fee00 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -195,36 +195,45 @@ func isDistributedSetup(eps []*url.URL) bool { return false } +// Returns true if path is empty, or equals to '.', '/', '\' characters. +func isPathSentinel(path string) bool { + return path == "" || path == "." || path == "/" || path == `\` +} + +// Returned when path is empty or root path. +var errEmptyRootPath = errors.New("Empty or root path is not allowed") + +// Invalid scheme passed. +var errInvalidScheme = errors.New("Invalid scheme") + // Check if endpoint is in expected syntax by valid scheme/path across all platforms. func checkEndpointURL(endpointURL *url.URL) (err error) { - // applicable to all OS. - if endpointURL.Scheme == "" || endpointURL.Scheme == "http" || endpointURL.Scheme == "https" { - urlPath := path.Clean(endpointURL.Path) - if urlPath == "" || urlPath == "." || urlPath == "/" || urlPath == `\` { - err = fmt.Errorf("Empty or root path is not allowed") + // Applicable to all OS. + if endpointURL.Scheme == "" || endpointURL.Scheme == httpScheme || endpointURL.Scheme == httpsScheme { + if isPathSentinel(path.Clean(endpointURL.Path)) { + err = errEmptyRootPath } return err } // Applicable to Windows only. - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { // On Windows, endpoint can be a path with drive eg. C:\Export and its URL.Scheme is 'C'. // Check if URL.Scheme is a single letter alphabet to represent a drive. // Note: URL.Parse() converts scheme into lower case always. if len(endpointURL.Scheme) == 1 && endpointURL.Scheme[0] >= 'a' && endpointURL.Scheme[0] <= 'z' { // If endpoint is C:\ or C:\export, URL.Path does not have path information like \ or \export // hence we directly work with endpoint. - urlPath := strings.SplitN(path.Clean(endpointURL.String()), ":", 2)[1] - if urlPath == "" || urlPath == "." || urlPath == "/" || urlPath == `\` { - err = fmt.Errorf("Empty or root path is not allowed") + if isPathSentinel(strings.SplitN(path.Clean(endpointURL.String()), ":", 2)[1]) { + err = errEmptyRootPath } return err } } - return fmt.Errorf("Invalid scheme") + return errInvalidScheme } // Check if endpoints are in expected syntax by valid scheme/path across all platforms. @@ -300,7 +309,7 @@ func checkServerSyntax(c *cli.Context) { } for _, ep := range endpoints { - if ep.Scheme == "https" && !globalIsSSL { + if ep.Scheme == httpsScheme && !globalIsSSL { // Certificates should be provided for https configuration. fatalIf(errInvalidArgument, "Certificates not provided for secure configuration") } diff --git a/cmd/server-main_test.go b/cmd/server-main_test.go index 627dd7065..df152b3ae 100644 --- a/cmd/server-main_test.go +++ b/cmd/server-main_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -133,7 +133,7 @@ func TestFinalizeAPIEndpoints(t *testing.T) { // Tests all the expected input disks for function checkSufficientDisks. func TestCheckSufficientDisks(t *testing.T) { var xlDisks []string - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { xlDisks = []string{ "C:\\mnt\\backend1", "C:\\mnt\\backend2", @@ -330,7 +330,7 @@ func TestCheckEndpointsSyntax(t *testing.T) { "server:/export", } - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { successCases = append(successCases, `\export`, `D:\export`, @@ -401,7 +401,7 @@ func TestIsDistributedSetup(t *testing.T) { disks []string result bool } - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { testCases = []struct { disks []string result bool @@ -457,7 +457,7 @@ func TestIsDistributedSetup(t *testing.T) { func TestInitServerConfig(t *testing.T) { ctx := &cli.Context{} - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Failed to set up test config") } diff --git a/cmd/server-mux.go b/cmd/server-mux.go index e879e0c61..c7e9ffd1e 100644 --- a/cmd/server-mux.go +++ b/cmd/server-mux.go @@ -71,6 +71,12 @@ func NewConnMux(c net.Conn) *ConnMux { } } +const ( + protocolTLS = "tls" + protocolHTTP1 = "http" + protocolHTTP2 = "http2" +) + // PeekProtocol - reads the first bytes, then checks if it is similar // to one of the default http methods func (c *ConnMux) PeekProtocol() string { @@ -79,19 +85,19 @@ func (c *ConnMux) PeekProtocol() string { if err != io.EOF { errorIf(err, "Unable to peek into the protocol") } - return "http" + return protocolHTTP1 } for _, m := range defaultHTTP1Methods { if strings.HasPrefix(string(buf), m) { - return "http" + return protocolHTTP1 } } for _, m := range defaultHTTP2Methods { if strings.HasPrefix(string(buf), m) { - return "http2" + return protocolHTTP2 } } - return "tls" + return protocolTLS } // Read - streams the ConnMux buffer when reset flag is activated, otherwise @@ -194,10 +200,14 @@ func newListenerMux(listener net.Listener, config *tls.Config) *ListenerMux { // and decide if we need to wrap the connection itself with a TLS or not go func(conn net.Conn) { connMux := NewConnMux(conn) - if connMux.PeekProtocol() == "tls" { - l.acceptResCh <- ListenerMuxAcceptRes{conn: tls.Server(connMux, l.config)} + if connMux.PeekProtocol() == protocolTLS { + l.acceptResCh <- ListenerMuxAcceptRes{ + conn: tls.Server(connMux, l.config), + } } else { - l.acceptResCh <- ListenerMuxAcceptRes{conn: connMux} + l.acceptResCh <- ListenerMuxAcceptRes{ + conn: connMux, + } } }(conn) } @@ -367,7 +377,7 @@ func (m *ServerMux) ListenAndServe(certFile, keyFile string) (err error) { if tlsEnabled && r.TLS == nil { // TLS is enabled but Request is not TLS configured u := url.URL{ - Scheme: "https", + Scheme: httpsScheme, Opaque: r.URL.Opaque, User: r.URL.User, Host: r.Host, diff --git a/cmd/server-mux_test.go b/cmd/server-mux_test.go index 7d0555af4..661ad05a4 100644 --- a/cmd/server-mux_test.go +++ b/cmd/server-mux_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,7 +153,7 @@ func TestInitListeners(t *testing.T) { } } // Windows doesn't have 'localhost' hostname. - if runtime.GOOS != "windows" { + if runtime.GOOS != globalWindowsOSName { listeners, err := initListeners("localhost:"+getFreePort(), &tls.Config{}) if err != nil { t.Fatalf("Test 3: Unable to initialize listeners %s", err) @@ -395,7 +395,7 @@ func TestListenAndServeTLS(t *testing.T) { res, _ := client.Get("http://" + addr) // Without TLS we expect a re-direction from http to https // And also the request is not rejected. - if res != nil && res.StatusCode == http.StatusOK && res.Request.URL.Scheme == "https" { + if res != nil && res.StatusCode == http.StatusOK && res.Request.URL.Scheme == httpsScheme { okNoTLS = true } } diff --git a/cmd/server-startup-msg.go b/cmd/server-startup-msg.go index 0bc8b74f2..0cb7370de 100644 --- a/cmd/server-startup-msg.go +++ b/cmd/server-startup-msg.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,7 +118,7 @@ func printCLIAccessMsg(endPoint string) { // Configure 'mc', following block prints platform specific information for minio client. console.Println(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide) - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { mcMessage := fmt.Sprintf("$ mc.exe config host add myminio %s %s %s", endPoint, cred.AccessKey, cred.SecretKey) console.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) } else { diff --git a/cmd/server-startup-msg_test.go b/cmd/server-startup-msg_test.go index 1a219858c..bd15cd1e4 100644 --- a/cmd/server-startup-msg_test.go +++ b/cmd/server-startup-msg_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ func TestCertificateNotExpired(t *testing.T) { // Test printing server common message. func TestPrintServerCommonMessage(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } @@ -109,7 +109,7 @@ func TestPrintServerCommonMessage(t *testing.T) { // Tests print cli access message. func TestPrintCLIAccessMsg(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } @@ -121,7 +121,7 @@ func TestPrintCLIAccessMsg(t *testing.T) { // Test print startup message. func TestPrintStartupMessage(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } diff --git a/cmd/server-startup-utils.go b/cmd/server-startup-utils.go index 1bb4fce70..aef08e2b6 100644 --- a/cmd/server-startup-utils.go +++ b/cmd/server-startup-utils.go @@ -51,9 +51,9 @@ func getListenIPs(serverAddr string) (hosts []string, port string, err error) { // Finalizes the API endpoints based on the host list and port. func finalizeAPIEndpoints(apiServer *http.Server) (endPoints []string, err error) { // Verify current scheme. - scheme := "http" + scheme := httpScheme if globalIsSSL { - scheme = "https" + scheme = httpsScheme } // Get list of listen ips and port. diff --git a/cmd/signature-v2_test.go b/cmd/signature-v2_test.go index 4b0462a11..91f4176a8 100644 --- a/cmd/signature-v2_test.go +++ b/cmd/signature-v2_test.go @@ -24,7 +24,7 @@ func TestResourceListSorting(t *testing.T) { // Tests presigned v2 signature. func TestDoesPresignedV2SignatureMatch(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Unable to initialize test config.") } diff --git a/cmd/signature-v4-parser_test.go b/cmd/signature-v4-parser_test.go index 16d960686..d30b8bee1 100644 --- a/cmd/signature-v4-parser_test.go +++ b/cmd/signature-v4-parser_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ func validateCredentialfields(t *testing.T, testNum int, expectedCredentials cre // A valid format of creadential should be of the following format. // Credential = accessKey + "/"+ scope // where scope = string.Join([]string{ currTime.Format(yyyymmdd), -// "us-east-1", +// globalMinioDefaultRegion, // "s3", // "aws4_request", // },"/") diff --git a/cmd/signature-v4-utils.go b/cmd/signature-v4-utils.go index bf956636e..bb5c5887d 100644 --- a/cmd/signature-v4-utils.go +++ b/cmd/signature-v4-utils.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,12 +49,12 @@ func skipContentSha256Cksum(r *http.Request) bool { // isValidRegion - verify if incoming region value is valid with configured Region. func isValidRegion(reqRegion string, confRegion string) bool { if confRegion == "" || confRegion == "US" { - confRegion = "us-east-1" + confRegion = globalMinioDefaultRegion } // Some older s3 clients set region as "US" instead of - // "us-east-1", handle it. + // globalMinioDefaultRegion, handle it. if reqRegion == "US" { - reqRegion = "us-east-1" + reqRegion = globalMinioDefaultRegion } return reqRegion == confRegion } diff --git a/cmd/signature-v4-utils_test.go b/cmd/signature-v4-utils_test.go index 17004862c..343c0ec3f 100644 --- a/cmd/signature-v4-utils_test.go +++ b/cmd/signature-v4-utils_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,8 +82,8 @@ func TestIsValidRegion(t *testing.T) { }{ {"", "", false}, - {"us-east-1", "", true}, - {"us-east-1", "US", true}, + {globalMinioDefaultRegion, "", true}, + {globalMinioDefaultRegion, "US", true}, {"us-west-1", "US", false}, {"us-west-1", "us-west-1", true}, // "US" was old naming convention for 'us-east-1'. diff --git a/cmd/signature-v4.go b/cmd/signature-v4.go index cf54c85a3..174e7579d 100644 --- a/cmd/signature-v4.go +++ b/cmd/signature-v4.go @@ -39,9 +39,10 @@ import ( // AWS Signature Version '4' constants. const ( - signV4Algorithm = "AWS4-HMAC-SHA256" - iso8601Format = "20060102T150405Z" - yyyymmdd = "20060102" + signV4Algorithm = "AWS4-HMAC-SHA256" + iso8601Format = "20060102T150405Z" + yyyymmdd = "20060102" + presignedHostHeader = "host" ) // getCanonicalHeaders generate a list of request headers with their values @@ -52,7 +53,7 @@ func getCanonicalHeaders(signedHeaders http.Header, host string) string { headers = append(headers, strings.ToLower(k)) vals[strings.ToLower(k)] = vv } - headers = append(headers, "host") + headers = append(headers, presignedHostHeader) sort.Strings(headers) var buf bytes.Buffer @@ -60,7 +61,7 @@ func getCanonicalHeaders(signedHeaders http.Header, host string) string { buf.WriteString(k) buf.WriteByte(':') switch { - case k == "host": + case k == presignedHostHeader: buf.WriteString(host) fallthrough default: @@ -82,7 +83,7 @@ func getSignedHeaders(signedHeaders http.Header) string { for k := range signedHeaders { headers = append(headers, strings.ToLower(k)) } - headers = append(headers, "host") + headers = append(headers, presignedHostHeader) sort.Strings(headers) return strings.Join(headers, ";") } diff --git a/cmd/signature-v4_test.go b/cmd/signature-v4_test.go index 45efb295b..4990f9941 100644 --- a/cmd/signature-v4_test.go +++ b/cmd/signature-v4_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ func TestDoesPolicySignatureMatch(t *testing.T) { // (1) It should fail if the access key is incorrect. { form: map[string]string{ - "X-Amz-Credential": fmt.Sprintf(credentialTemplate, "EXAMPLEINVALIDEXAMPL", now.Format(yyyymmdd), "us-east-1"), + "X-Amz-Credential": fmt.Sprintf(credentialTemplate, "EXAMPLEINVALIDEXAMPL", now.Format(yyyymmdd), globalMinioDefaultRegion), }, expected: ErrInvalidAccessKeyID, }, @@ -64,14 +64,14 @@ func TestDoesPolicySignatureMatch(t *testing.T) { // (3) It should fail if the date is invalid (or missing, in this case). { form: map[string]string{ - "X-Amz-Credential": fmt.Sprintf(credentialTemplate, accessKey, now.Format(yyyymmdd), "us-east-1"), + "X-Amz-Credential": fmt.Sprintf(credentialTemplate, accessKey, now.Format(yyyymmdd), globalMinioDefaultRegion), }, expected: ErrMalformedDate, }, // (4) It should fail with a bad signature. { form: map[string]string{ - "X-Amz-Credential": fmt.Sprintf(credentialTemplate, accessKey, now.Format(yyyymmdd), "us-east-1"), + "X-Amz-Credential": fmt.Sprintf(credentialTemplate, accessKey, now.Format(yyyymmdd), globalMinioDefaultRegion), "X-Amz-Date": now.Format(iso8601Format), "X-Amz-Signature": "invalidsignature", "Policy": "policy", @@ -81,9 +81,9 @@ func TestDoesPolicySignatureMatch(t *testing.T) { // (5) It should succeed if everything is correct. { form: map[string]string{ - "X-Amz-Credential": fmt.Sprintf(credentialTemplate, accessKey, now.Format(yyyymmdd), "us-east-1"), + "X-Amz-Credential": fmt.Sprintf(credentialTemplate, accessKey, now.Format(yyyymmdd), globalMinioDefaultRegion), "X-Amz-Date": now.Format(iso8601Format), - "X-Amz-Signature": getSignature(getSigningKey(serverConfig.GetCredential().SecretKey, now, "us-east-1"), "policy"), + "X-Amz-Signature": getSignature(getSigningKey(serverConfig.GetCredential().SecretKey, now, globalMinioDefaultRegion), "policy"), "Policy": "policy", }, expected: ErrNone, @@ -100,7 +100,7 @@ func TestDoesPolicySignatureMatch(t *testing.T) { } func TestDoesPresignedSignatureMatch(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } @@ -121,7 +121,7 @@ func TestDoesPresignedSignatureMatch(t *testing.T) { }{ // (0) Should error without a set URL query. { - region: "us-east-1", + region: globalMinioDefaultRegion, expected: ErrInvalidQueryParams, }, // (1) Should error on an invalid access key. @@ -162,7 +162,7 @@ func TestDoesPresignedSignatureMatch(t *testing.T) { "X-Amz-Credential": fmt.Sprintf(credentialTemplate, accessKeyID, now.Format(yyyymmdd), "us-west-1"), "X-Amz-Content-Sha256": payloadSHA256, }, - region: "us-east-1", + region: globalMinioDefaultRegion, expected: ErrInvalidRegion, }, // (4) Should NOT fail with an invalid region if it doesn't verify it. diff --git a/cmd/storage-rpc-client_test.go b/cmd/storage-rpc-client_test.go index 37965075b..eb668fc6d 100644 --- a/cmd/storage-rpc-client_test.go +++ b/cmd/storage-rpc-client_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -188,7 +188,7 @@ func TestRPCStorageClient(t *testing.T) { func (s *TestRPCStorageSuite) testRPCStorageClient(t *testing.T) { // TODO - Fix below tests to run on windows. - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { return } s.testRPCStorageDisksInfo(t) diff --git a/cmd/storage-rpc-server_test.go b/cmd/storage-rpc-server_test.go index 6ed51d6bc..48082e8ad 100644 --- a/cmd/storage-rpc-server_test.go +++ b/cmd/storage-rpc-server_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ type testStorageRPCServer struct { } func createTestStorageServer(t *testing.T) *testStorageRPCServer { - testPath, err := newTestConfig("us-east-1") + testPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("unable initialize config file, %s", err) } diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index cfdc9ad86..21641b42c 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,7 +110,7 @@ func prepareXL() (ObjectLayer, []string, error) { // Initialize FS objects. func initFSObjects(disk string, t *testing.T) (obj ObjectLayer) { - newTestConfig("us-east-1") + newTestConfig(globalMinioDefaultRegion) var err error obj, err = newFSObjectLayer(disk) if err != nil { @@ -203,7 +203,7 @@ func UnstartedTestServer(t TestErrHandler, instanceType string) TestServer { t.Fatal("Failed to create disks for the backend") } - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("%s", err) } @@ -367,7 +367,7 @@ func StartTestStorageRPCServer(t TestErrHandler, instanceType string, diskN int) t.Fatalf("%s", err) } - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("%s", err) } @@ -402,7 +402,7 @@ func StartTestPeersRPCServer(t TestErrHandler, instanceType string) TestServer { t.Fatalf("%s", err) } - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("%s", err) } @@ -691,7 +691,7 @@ func signStreamingRequest(req *http.Request, accessKey, secretKey string, currTi // Get scope. scope := strings.Join([]string{ currTime.Format(yyyymmdd), - "us-east-1", + globalMinioDefaultRegion, "s3", "aws4_request", }, "/") @@ -701,7 +701,7 @@ func signStreamingRequest(req *http.Request, accessKey, secretKey string, currTi stringToSign = stringToSign + getSHA256Hash([]byte(canonicalRequest)) date := sumHMAC([]byte("AWS4"+secretKey), []byte(currTime.Format(yyyymmdd))) - region := sumHMAC(date, []byte("us-east-1")) + region := sumHMAC(date, []byte(globalMinioDefaultRegion)) service := sumHMAC(region, []byte("s3")) signingKey := sumHMAC(service, []byte("aws4_request")) @@ -1919,7 +1919,7 @@ func ExecObjectLayerAPITest(t *testing.T, objAPITest objAPITestType, endpoints [ initNSLock(false) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Unable to initialize server config. %s", err) } @@ -1964,7 +1964,7 @@ type objTestDiskNotFoundType func(obj ObjectLayer, instanceType string, dirs []s func ExecObjectLayerTest(t TestErrHandler, objTest objTestType) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Unexpected error", err) } @@ -1989,7 +1989,7 @@ func ExecObjectLayerTest(t TestErrHandler, objTest objTestType) { // ExecObjectLayerDiskAlteredTest - executes object layer tests while altering // disks in between tests. Creates XL ObjectLayer instance and runs test for XL layer. func ExecObjectLayerDiskAlteredTest(t *testing.T, objTest objTestDiskNotFoundType) { - configPath, err := newTestConfig("us-east-1") + configPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Failed to create config directory", err) } @@ -2010,7 +2010,7 @@ type objTestStaleFilesType func(obj ObjectLayer, instanceType string, dirs []str // ExecObjectLayerStaleFilesTest - executes object layer tests those leaves stale // files/directories under .minio/tmp. Creates XL ObjectLayer instance and runs test for XL layer. func ExecObjectLayerStaleFilesTest(t *testing.T, objTest objTestStaleFilesType) { - configPath, err := newTestConfig("us-east-1") + configPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Failed to create config directory", err) } @@ -2169,7 +2169,7 @@ func initTestBrowserPeerRPCEndPoint() http.Handler { } func StartTestBrowserPeerRPCServer(t TestErrHandler, instanceType string) TestServer { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("%s", err) } @@ -2190,7 +2190,7 @@ func StartTestBrowserPeerRPCServer(t TestErrHandler, instanceType string) TestSe } func StartTestS3PeerRPCServer(t TestErrHandler) (TestServer, []string) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("%s", err) } diff --git a/cmd/trie_test.go b/cmd/trie_test.go index f89af985a..b37093144 100644 --- a/cmd/trie_test.go +++ b/cmd/trie_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ func TestPrefixMatch(t *testing.T) { trie = newTrie() // Feed it some fodder: only 'minio' and 'miny-os' should trip the matcher. - trie.Insert("minio") + trie.Insert(globalMinioDefaultOwnerID) trie.Insert("amazon") trie.Insert("cheerio") trie.Insert("miny-o's") @@ -65,7 +65,7 @@ func TestPrefixMatch(t *testing.T) { t.Errorf("expected two matches, got: %d", len(matches)) } - if matches[0] != "minio" && matches[1] != "minio" { + if matches[0] != globalMinioDefaultOwnerID && matches[1] != globalMinioDefaultOwnerID { t.Errorf("expected one match to be 'minio', got: '%s' and '%s'", matches[0], matches[1]) } } diff --git a/cmd/update-main.go b/cmd/update-main.go index 1cc39dd6b..b301c1520 100644 --- a/cmd/update-main.go +++ b/cmd/update-main.go @@ -84,7 +84,7 @@ func parseReleaseData(data string) (time.Time, error) { if len(releaseDateSplits) < 3 { return time.Time{}, (errors.New("Update data malformed")) } - if releaseDateSplits[0] != "minio" { + if releaseDateSplits[0] != globalMinioDefaultOwnerID { return time.Time{}, (errors.New("Update data malformed, missing minio tag")) } // "OFFICIAL" tag is still kept for backward compatibility. @@ -126,14 +126,14 @@ func isDocker() bool { // Check if the minio server binary was built with source. func isSourceBuild() bool { - return Version == "DEVELOPMENT.GOGET" + return Version == goGetTag } // Fetch the current version of the Minio server binary. func getCurrentMinioVersion() (current time.Time, err error) { // For development builds we check for binary modTime // to validate against latest minio server release. - if Version != "DEVELOPMENT.GOGET" { + if Version != goGetTag { // Parse current minio version into RFC3339. current, err = time.Parse(time.RFC3339, Version) if err != nil { @@ -164,7 +164,7 @@ func getReleaseUpdate(updateURL string, duration time.Duration) (updateMsg updat downloadURL = "docker pull minio/minio" } else { switch runtime.GOOS { - case "windows": + case globalWindowsOSName: // For windows. downloadURL = newUpdateURLPrefix + "/minio.exe" default: diff --git a/cmd/update-notifier.go b/cmd/update-notifier.go index c54a2cfc7..046933594 100644 --- a/cmd/update-notifier.go +++ b/cmd/update-notifier.go @@ -66,7 +66,7 @@ func colorizeUpdateMessage(updateString string, newerThan time.Duration) string default: // on windows terminal turn off unicode characters. var top, bottom, sideBar string - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { top = yellow("*" + strings.Repeat("*", maxContentWidth) + "*") bottom = yellow("*" + strings.Repeat("*", maxContentWidth) + "*") sideBar = yellow("|") diff --git a/cmd/url-sort_test.go b/cmd/url-sort_test.go index fb1b6e5c1..b277952f0 100644 --- a/cmd/url-sort_test.go +++ b/cmd/url-sort_test.go @@ -38,17 +38,17 @@ func TestSortByHostPath(t *testing.T) { }, expected: []*url.URL{ { - Scheme: "http", + Scheme: httpScheme, Host: "abcd.com:9000", Path: "/a/b/c", }, { - Scheme: "http", + Scheme: httpScheme, Host: "abcd.com:9000", Path: "/a/b/d", }, { - Scheme: "http", + Scheme: httpScheme, Host: "abcd.com:9000", Path: "/a/b/e", }, @@ -62,17 +62,17 @@ func TestSortByHostPath(t *testing.T) { }, expected: []*url.URL{ { - Scheme: "http", + Scheme: httpScheme, Host: "abcd.com:9000", Path: "/a/b/c", }, { - Scheme: "http", + Scheme: httpScheme, Host: "defg.com:9000", Path: "/a/b/c", }, { - Scheme: "http", + Scheme: httpScheme, Host: "hijk.com:9000", Path: "/a/b/c", }, diff --git a/cmd/utils.go b/cmd/utils.go index a026d6712..a6a158d48 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -102,9 +102,15 @@ func urlPath2BucketObjectName(u *url.URL) (bucketName, objectName string) { return bucketName, objectName } +// URI scheme constants. +const ( + httpScheme = "http" + httpsScheme = "https" +) + var portMap = map[string]string{ - "http": "80", - "https": "443", + httpScheme: "80", + httpsScheme: "443", } // Given a string of the form "host", "host:port", or "[ipv6::address]:port", diff --git a/cmd/utils_test.go b/cmd/utils_test.go index 49d9f65eb..d2b2ba9f6 100644 --- a/cmd/utils_test.go +++ b/cmd/utils_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -275,7 +275,7 @@ func TestStartProfiler(t *testing.T) { // Tests fetch local address. func TestLocalAddress(t *testing.T) { - if runtime.GOOS == "windows" { + if runtime.GOOS == globalWindowsOSName { return } @@ -297,19 +297,19 @@ func TestLocalAddress(t *testing.T) { isDistXL: true, srvCmdConfig: serverCmdConfig{ endpoints: []*url.URL{{ - Scheme: "http", + Scheme: httpScheme, Host: "localhost:9000", Path: "/mnt/disk1", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.1.2:9000", Path: "/mnt/disk2", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.1:9000", Path: "/mnt/disk3", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.2:9000", Path: "/mnt/disk4", }}, @@ -338,19 +338,19 @@ func TestLocalAddress(t *testing.T) { isDistXL: true, srvCmdConfig: serverCmdConfig{ endpoints: []*url.URL{{ - Scheme: "http", + Scheme: httpScheme, Host: "1.1.1.1:9000", Path: "/mnt/disk2", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.1.2:9000", Path: "/mnt/disk2", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.1:9000", Path: "/mnt/disk3", }, { - Scheme: "http", + Scheme: httpScheme, Host: "1.1.2.2:9000", Path: "/mnt/disk4", }}, diff --git a/cmd/web-handlers_test.go b/cmd/web-handlers_test.go index f3c0ff026..238713078 100644 --- a/cmd/web-handlers_test.go +++ b/cmd/web-handlers_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -130,7 +130,7 @@ func testLoginWebHandler(obj ObjectLayer, instanceType string, t TestErrHandler) apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -179,7 +179,7 @@ func testStorageInfoWebHandler(obj ObjectLayer, instanceType string, t TestErrHa apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -225,7 +225,7 @@ func testServerInfoWebHandler(obj ObjectLayer, instanceType string, t TestErrHan apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -271,7 +271,7 @@ func testMakeBucketWebHandler(obj ObjectLayer, instanceType string, t TestErrHan apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -331,7 +331,7 @@ func testListBucketsWebHandler(obj ObjectLayer, instanceType string, t TestErrHa apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -388,7 +388,7 @@ func testListObjectsWebHandler(obj ObjectLayer, instanceType string, t TestErrHa apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -492,7 +492,7 @@ func testRemoveObjectWebHandler(obj ObjectLayer, instanceType string, t TestErrH apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -568,7 +568,7 @@ func testGenerateAuthWebHandler(obj ObjectLayer, instanceType string, t TestErrH apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -614,7 +614,7 @@ func testSetAuthWebHandler(obj ObjectLayer, instanceType string, t TestErrHandle apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -675,7 +675,7 @@ func testGetAuthWebHandler(obj ObjectLayer, instanceType string, t TestErrHandle apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -720,7 +720,7 @@ func testUploadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandler apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -811,7 +811,7 @@ func testDownloadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandl apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -903,7 +903,7 @@ func testWebPresignedGetHandler(obj ObjectLayer, instanceType string, t TestErrH apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -1016,7 +1016,7 @@ func testWebGetBucketPolicyHandler(obj ObjectLayer, instanceType string, t TestE apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -1099,7 +1099,7 @@ func testWebListAllBucketPoliciesHandler(obj ObjectLayer, instanceType string, t apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -1205,7 +1205,7 @@ func testWebSetBucketPolicyHandler(obj ObjectLayer, instanceType string, t TestE apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } @@ -1283,7 +1283,7 @@ func TestWebCheckAuthorization(t *testing.T) { apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Init Test config failed", err) } @@ -1365,7 +1365,7 @@ func TestWebObjectLayerNotReady(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Init Test config failed", err) } @@ -1444,7 +1444,7 @@ func TestWebObjectLayerNotReady(t *testing.T) { // TestWebObjectLayerFaultyDisks - Test Web RPC responses with faulty disks func TestWebObjectLayerFaultyDisks(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } @@ -1469,7 +1469,7 @@ func TestWebObjectLayerFaultyDisks(t *testing.T) { // initialize the server and obtain the credentials and root. // credentials are necessary to sign the HTTP request. - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal("Init Test config failed", err) } diff --git a/cmd/xl-v1-healing_test.go b/cmd/xl-v1-healing_test.go index d770f96be..728e573e8 100644 --- a/cmd/xl-v1-healing_test.go +++ b/cmd/xl-v1-healing_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import ( // Tests healing of format XL. func TestHealFormatXL(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } @@ -271,7 +271,7 @@ func TestHealFormatXL(t *testing.T) { // Tests undoes and validates if the undoing completes successfully. func TestUndoMakeBucket(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } @@ -316,7 +316,7 @@ func TestUndoMakeBucket(t *testing.T) { // Tests quick healing of bucket and bucket metadata. func TestQuickHeal(t *testing.T) { - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatal(err) } diff --git a/cmd/xl-v1-list-objects-heal_test.go b/cmd/xl-v1-list-objects-heal_test.go index 701c12bca..e21ab7765 100644 --- a/cmd/xl-v1-list-objects-heal_test.go +++ b/cmd/xl-v1-list-objects-heal_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage (C) 2016 Minio, Inc. + * Minio Cloud Storage (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import ( // TestListObjectsHeal - Tests ListObjectsHeal API for XL func TestListObjectsHeal(t *testing.T) { - rootPath, err := newTestConfig("us-east-1") + rootPath, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("Init Test config failed") } diff --git a/cmd/xl-v1-metadata.go b/cmd/xl-v1-metadata.go index f50b083ad..05149c48e 100644 --- a/cmd/xl-v1-metadata.go +++ b/cmd/xl-v1-metadata.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,14 @@ type checkSumInfo struct { Hash string `json:"hash"` } +// Various algorithms supported by bit-rot protection feature. +const ( + // "sha256" is specifically used on arm64 bit platforms. + sha256Algo = "sha256" + // Rest of the platforms default to blake2b. + blake2bAlgo = "blake2b" +) + // Constant indicates current bit-rot algo used when creating objects. // Depending on the architecture we are choosing a different checksum. var bitRotAlgo = getDefaultBitRotAlgo() @@ -71,10 +79,10 @@ func getDefaultBitRotAlgo() string { // This would also allows erasure coded writes // on ARM64 servers to be on-par with their // counter-part X86_64 servers. - return "sha256" + return sha256Algo default: // Default for all other architectures we use blake2b. - return "blake2b" + return blake2bAlgo } } @@ -135,11 +143,22 @@ type xlMetaV1 struct { Parts []objectPartInfo `json:"parts,omitempty"` } +// XL metadata constants. +const ( + // XL meta version. + xlMetaVersion = "1.0.0" + + // XL meta format string. + xlMetaFormat = "xl" + + // Add new constants here. +) + // newXLMetaV1 - initializes new xlMetaV1, adds version, allocates a fresh erasure info. func newXLMetaV1(object string, dataBlocks, parityBlocks int) (xlMeta xlMetaV1) { xlMeta = xlMetaV1{} - xlMeta.Version = "1.0.0" - xlMeta.Format = "xl" + xlMeta.Version = xlMetaVersion + xlMeta.Format = xlMetaFormat xlMeta.Minio.Release = ReleaseTag xlMeta.Erasure = erasureInfo{ Algorithm: erasureAlgorithmKlauspost, @@ -154,7 +173,7 @@ func newXLMetaV1(object string, dataBlocks, parityBlocks int) (xlMeta xlMetaV1) // IsValid - tells if the format is sane by validating the version // string and format style. func (m xlMetaV1) IsValid() bool { - return m.Version == "1.0.0" && m.Format == "xl" + return m.Version == xlMetaVersion && m.Format == xlMetaFormat } // objectPartIndex - returns the index of matching object part number. diff --git a/cmd/xl-v1-multipart-common_test.go b/cmd/xl-v1-multipart-common_test.go index d3c94b594..5d31eb1b2 100644 --- a/cmd/xl-v1-multipart-common_test.go +++ b/cmd/xl-v1-multipart-common_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2014-2016 Minio, Inc. + * Minio Cloud Storage, (C) 2014-2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import ( func TestUpdateUploadJSON(t *testing.T) { // Initialize configuration - root, err := newTestConfig("us-east-1") + root, err := newTestConfig(globalMinioDefaultRegion) if err != nil { t.Fatalf("%s", err) } diff --git a/cmd/xl-v1-utils_test.go b/cmd/xl-v1-utils_test.go index d66a85c63..1bada5408 100644 --- a/cmd/xl-v1-utils_test.go +++ b/cmd/xl-v1-utils_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -131,9 +131,9 @@ func TestHashOrder(t *testing.T) { // newTestXLMetaV1 - initializes new xlMetaV1, adds version, allocates a fresh erasure info and metadata. func newTestXLMetaV1() xlMetaV1 { xlMeta := xlMetaV1{} - xlMeta.Version = "1.0.0" - xlMeta.Format = "xl" - xlMeta.Minio.Release = "1.0.0" + xlMeta.Version = xlMetaVersion + xlMeta.Format = xlMetaFormat + xlMeta.Minio.Release = "test" xlMeta.Erasure = erasureInfo{ Algorithm: "klauspost/reedsolomon/vandermonde", DataBlocks: 5,