In many situations, while testing we encounter ErrInternalError, to reduce logging we have removed logging from quite a few places which is acceptable but when ErrInternalError occurs we should have a facility to log the corresponding error, this helps to debug Minio server.
Unified · Split
| @@ -78,7 +78,7 @@ func (api objectAPIHandlers) GetBucketACLHandler(w http.ResponseWriter, r *http. · 77 unmodified lines | ||
| 78 | 78 | // Before proceeding validate if bucket exists. |
| 79 | 79 | _, err := objAPI.GetBucketInfo(ctx, bucket) |
| 80 | 80 | if err != nil { |
| 81 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 81 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 82 | 82 | return |
| 83 | 83 | } |
| 84 | 84 | |
| @@ -92,7 +92,7 @@ func (api objectAPIHandlers) GetBucketACLHandler(w http.ResponseWriter, r *http. · 7 unmodified lines | ||
| 92 | 92 | Permission: "FULL_CONTROL", |
| 93 | 93 | }) |
| 94 | 94 | if err := xml.NewEncoder(w).Encode(acl); err != nil { |
| 95 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 95 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 96 | 96 | return |
| 97 | 97 | } |
| 98 | 98 | |
| @@ -128,7 +128,7 @@ func (api objectAPIHandlers) GetObjectACLHandler(w http.ResponseWriter, r *http. · 29 unmodified lines | ||
| 128 | 128 | // Before proceeding validate if object exists. |
| 129 | 129 | _, err := objAPI.GetObjectInfo(ctx, bucket, object, ObjectOptions{}) |
| 130 | 130 | if err != nil { |
| 131 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 131 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 132 | 132 | return |
| 133 | 133 | } |
| 134 | 134 | |
| @@ -142,7 +142,7 @@ func (api objectAPIHandlers) GetObjectACLHandler(w http.ResponseWriter, r *http. · 7 unmodified lines | ||
| 142 | 142 | Permission: "FULL_CONTROL", |
| 143 | 143 | }) |
| 144 | 144 | if err := xml.NewEncoder(w).Encode(acl); err != nil { |
| 145 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 145 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 146 | 146 | return |
| 147 | 147 | } |
| 148 | 148 | |
| @@ -71,7 +71,9 @@ var ( · 70 unmodified lines | ||
| 71 | 71 | // ----------- |
| 72 | 72 | // Returns Administration API version |
| 73 | 73 | func (a adminAPIHandlers) VersionHandler(w http.ResponseWriter, r *http.Request) { |
| 74 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 74 | + ctx := newContext(r, w, "Version") | |
| 75 | + | |
| 76 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 75 | 77 | if adminAPIErr != ErrNone { |
| 76 | 78 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 77 | 79 | return |
| @@ -79,8 +81,7 @@ func (a adminAPIHandlers) VersionHandler(w http.ResponseWriter, r *http.Request) · 1 unmodified line | ||
| 79 | 81 | |
| 80 | 82 | jsonBytes, err := json.Marshal(adminAPIVersionInfo) |
| 81 | 83 | if err != nil { |
| 82 | − writeErrorResponseJSON(w, ErrInternalError, r.URL) | |
| 83 | − logger.LogIf(context.Background(), err) | |
| 84 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 84 | 85 | return |
| 85 | 86 | } |
| 86 | 87 | |
| @@ -91,7 +92,9 @@ func (a adminAPIHandlers) VersionHandler(w http.ResponseWriter, r *http.Request) · 4 unmodified lines | ||
| 91 | 92 | // ---------- |
| 92 | 93 | // Returns server version and uptime. |
| 93 | 94 | func (a adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r *http.Request) { |
| 94 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 95 | + ctx := newContext(r, w, "ServiceStatus") | |
| 96 | + | |
| 97 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 95 | 98 | if adminAPIErr != ErrNone { |
| 96 | 99 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 97 | 100 | return |
| @@ -107,8 +110,7 @@ func (a adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r *http.Re · 9 unmodified lines | ||
| 107 | 110 | // of read-quorum availability. |
| 108 | 111 | uptime, err := getPeerUptimes(globalAdminPeers) |
| 109 | 112 | if err != nil { |
| 110 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 111 | − logger.LogIf(context.Background(), err) | |
| 113 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 112 | 114 | return |
| 113 | 115 | } |
| 114 | 116 | |
| @@ -121,8 +123,7 @@ func (a adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r *http.Re · 6 unmodified lines | ||
| 121 | 123 | // Marshal API response |
| 122 | 124 | jsonBytes, err := json.Marshal(serverStatus) |
| 123 | 125 | if err != nil { |
| 124 | − writeErrorResponseJSON(w, ErrInternalError, r.URL) | |
| 125 | − logger.LogIf(context.Background(), err) | |
| 126 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 126 | 127 | return |
| 127 | 128 | } |
| 128 | 129 | // Reply with storage information (across nodes in a |
| @@ -136,7 +137,9 @@ func (a adminAPIHandlers) ServiceStatusHandler(w http.ResponseWriter, r *http.Re · 7 unmodified lines | ||
| 136 | 137 | // Restarts/Stops minio server gracefully. In a distributed setup, |
| 137 | 138 | // restarts all the servers in the cluster. |
| 138 | 139 | func (a adminAPIHandlers) ServiceStopNRestartHandler(w http.ResponseWriter, r *http.Request) { |
| 139 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 140 | + ctx := newContext(r, w, "ServiceStopNRestart") | |
| 141 | + | |
| 142 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 140 | 143 | if adminAPIErr != ErrNone { |
| 141 | 144 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 142 | 145 | return |
| @@ -145,7 +148,7 @@ func (a adminAPIHandlers) ServiceStopNRestartHandler(w http.ResponseWriter, r *h · 2 unmodified lines | ||
| 145 | 148 | var sa madmin.ServiceAction |
| 146 | 149 | err := json.NewDecoder(r.Body).Decode(&sa) |
| 147 | 150 | if err != nil { |
| 148 | − logger.LogIf(context.Background(), err) | |
| 151 | + logger.LogIf(ctx, err) | |
| 149 | 152 | writeErrorResponseJSON(w, ErrRequestBodyParse, r.URL) |
| 150 | 153 | return |
| 151 | 154 | } |
| @@ -158,7 +161,7 @@ func (a adminAPIHandlers) ServiceStopNRestartHandler(w http.ResponseWriter, r *h · 6 unmodified lines | ||
| 158 | 161 | serviceSig = serviceStop |
| 159 | 162 | default: |
| 160 | 163 | writeErrorResponseJSON(w, ErrMalformedPOSTRequest, r.URL) |
| 161 | − logger.LogIf(context.Background(), errors.New("Invalid service action received")) | |
| 164 | + logger.LogIf(ctx, errors.New("Invalid service action received")) | |
| 162 | 165 | return |
| 163 | 166 | } |
| 164 | 167 | |
| @@ -227,10 +230,12 @@ type ServerInfo struct { · 62 unmodified lines | ||
| 227 | 230 | // ---------- |
| 228 | 231 | // Get server information |
| 229 | 232 | func (a adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *http.Request) { |
| 233 | + ctx := newContext(r, w, "ServerInfo") | |
| 234 | + | |
| 230 | 235 | // Authenticate request |
| 231 | 236 | |
| 232 | 237 | // Setting the region as empty so as the mc server info command is irrespective to the region. |
| 233 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 238 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 234 | 239 | if adminAPIErr != ErrNone { |
| 235 | 240 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 236 | 241 | return |
| @@ -255,7 +260,7 @@ func (a adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *http.Reque · 18 unmodified lines | ||
| 255 | 260 | serverInfoData, err := peer.cmdRunner.ServerInfo() |
| 256 | 261 | if err != nil { |
| 257 | 262 | reqInfo := (&logger.ReqInfo{}).AppendTags("peerAddress", peer.addr) |
| 258 | − ctx := logger.SetReqInfo(context.Background(), reqInfo) | |
| 263 | + ctx := logger.SetReqInfo(ctx, reqInfo) | |
| 259 | 264 | logger.LogIf(ctx, err) |
| 260 | 265 | reply[idx].Error = err.Error() |
| 261 | 266 | return |
| @@ -270,8 +275,7 @@ func (a adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *http.Reque · 8 unmodified lines | ||
| 270 | 275 | // Marshal API response |
| 271 | 276 | jsonBytes, err := json.Marshal(reply) |
| 272 | 277 | if err != nil { |
| 273 | − writeErrorResponseJSON(w, ErrInternalError, r.URL) | |
| 274 | − logger.LogIf(context.Background(), err) | |
| 278 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 275 | 279 | return |
| 276 | 280 | } |
| 277 | 281 | |
| @@ -292,7 +296,9 @@ type StartProfilingResult struct { · 14 unmodified lines | ||
| 292 | 296 | // ---------- |
| 293 | 297 | // Enable server profiling |
| 294 | 298 | func (a adminAPIHandlers) StartProfilingHandler(w http.ResponseWriter, r *http.Request) { |
| 295 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 299 | + ctx := newContext(r, w, "StartProfiling") | |
| 300 | + | |
| 301 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 296 | 302 | if adminAPIErr != ErrNone { |
| 297 | 303 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 298 | 304 | return |
| @@ -351,7 +357,9 @@ func (f dummyFileInfo) Sys() interface{} { return f.sys } · 52 unmodified lines | ||
| 351 | 357 | // ---------- |
| 352 | 358 | // Download profiling information of all nodes in a zip format |
| 353 | 359 | func (a adminAPIHandlers) DownloadProfilingHandler(w http.ResponseWriter, r *http.Request) { |
| 354 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 360 | + ctx := newContext(r, w, "DownloadProfiling") | |
| 361 | + | |
| 362 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 355 | 363 | if adminAPIErr != ErrNone { |
| 356 | 364 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 357 | 365 | return |
| @@ -368,7 +376,7 @@ func (a adminAPIHandlers) DownloadProfilingHandler(w http.ResponseWriter, r *htt · 10 unmodified lines | ||
| 368 | 376 | // Get profiling data from a node |
| 369 | 377 | data, err := peer.cmdRunner.DownloadProfilingData() |
| 370 | 378 | if err != nil { |
| 371 | − logger.LogIf(context.Background(), fmt.Errorf("Unable to download profiling data from node `%s`, reason: %s", peer.addr, err.Error())) | |
| 379 | + logger.LogIf(ctx, fmt.Errorf("Unable to download profiling data from node `%s`, reason: %s", peer.addr, err.Error())) | |
| 372 | 380 | continue |
| 373 | 381 | } |
| 374 | 382 | |
| @@ -475,7 +483,7 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) { · 100 unmodified lines | ||
| 475 | 483 | } |
| 476 | 484 | |
| 477 | 485 | // Validate request signature. |
| 478 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 486 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 479 | 487 | if adminAPIErr != ErrNone { |
| 480 | 488 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 481 | 489 | return |
| @@ -570,8 +578,7 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) { · 88 unmodified lines | ||
| 570 | 578 | StartTime: nh.startTime, |
| 571 | 579 | }) |
| 572 | 580 | if err != nil { |
| 573 | − logger.LogIf(context.Background(), err) | |
| 574 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 581 | + writeErrorResponse(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 575 | 582 | return |
| 576 | 583 | } |
| 577 | 584 | // Client token not specified but a heal sequence exists on a path, |
| @@ -630,7 +637,7 @@ func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Reques · 52 unmodified lines | ||
| 630 | 637 | } |
| 631 | 638 | |
| 632 | 639 | // Validate request signature. |
| 633 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 640 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 634 | 641 | if adminAPIErr != ErrNone { |
| 635 | 642 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 636 | 643 | return |
| @@ -638,22 +645,20 @@ func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Reques · 1 unmodified line | ||
| 638 | 645 | |
| 639 | 646 | config, err := readServerConfig(ctx, objectAPI) |
| 640 | 647 | if err != nil { |
| 641 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 648 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 642 | 649 | return |
| 643 | 650 | } |
| 644 | 651 | |
| 645 | 652 | configData, err := json.MarshalIndent(config, "", "\t") |
| 646 | 653 | if err != nil { |
| 647 | − logger.LogIf(ctx, err) | |
| 648 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 654 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 649 | 655 | return |
| 650 | 656 | } |
| 651 | 657 | |
| 652 | 658 | password := config.GetCredential().SecretKey |
| 653 | 659 | econfigData, err := madmin.EncryptData(password, configData) |
| 654 | 660 | if err != nil { |
| 655 | − logger.LogIf(ctx, err) | |
| 656 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 661 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 657 | 662 | return |
| 658 | 663 | } |
| 659 | 664 | |
| @@ -692,7 +697,7 @@ func (a adminAPIHandlers) GetConfigKeysHandler(w http.ResponseWriter, r *http.Re · 32 unmodified lines | ||
| 692 | 697 | } |
| 693 | 698 | |
| 694 | 699 | // Validate request signature. |
| 695 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 700 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 696 | 701 | if adminAPIErr != ErrNone { |
| 697 | 702 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 698 | 703 | return |
| @@ -707,14 +712,13 @@ func (a adminAPIHandlers) GetConfigKeysHandler(w http.ResponseWriter, r *http.Re · 8 unmodified lines | ||
| 707 | 712 | |
| 708 | 713 | config, err := readServerConfig(ctx, objectAPI) |
| 709 | 714 | if err != nil { |
| 710 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 715 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 711 | 716 | return |
| 712 | 717 | } |
| 713 | 718 | |
| 714 | 719 | configData, err := json.Marshal(config) |
| 715 | 720 | if err != nil { |
| 716 | − logger.LogIf(ctx, err) | |
| 717 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 721 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 718 | 722 | return |
| 719 | 723 | } |
| 720 | 724 | |
| @@ -736,8 +740,7 @@ func (a adminAPIHandlers) GetConfigKeysHandler(w http.ResponseWriter, r *http.Re · 15 unmodified lines | ||
| 736 | 740 | password := config.GetCredential().SecretKey |
| 737 | 741 | econfigData, err := madmin.EncryptData(password, []byte(newConfigStr)) |
| 738 | 742 | if err != nil { |
| 739 | − logger.LogIf(ctx, err) | |
| 740 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 743 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 741 | 744 | return |
| 742 | 745 | } |
| 743 | 746 | |
| @@ -746,12 +749,12 @@ func (a adminAPIHandlers) GetConfigKeysHandler(w http.ResponseWriter, r *http.Re · 2 unmodified lines | ||
| 746 | 749 | |
| 747 | 750 | // toAdminAPIErrCode - converts errXLWriteQuorum error to admin API |
| 748 | 751 | // specific error. |
| 749 | −func toAdminAPIErrCode(err error) APIErrorCode { | |
| 752 | +func toAdminAPIErrCode(ctx context.Context, err error) APIErrorCode { | |
| 750 | 753 | switch err { |
| 751 | 754 | case errXLWriteQuorum: |
| 752 | 755 | return ErrAdminConfigNoQuorum |
| 753 | 756 | default: |
| 754 | − return toAPIErrorCode(err) | |
| 757 | + return toAPIErrorCode(ctx, err) | |
| 755 | 758 | } |
| 756 | 759 | } |
| 757 | 760 | |
| @@ -767,7 +770,7 @@ func (a adminAPIHandlers) RemoveUser(w http.ResponseWriter, r *http.Request) { · 9 unmodified lines | ||
| 767 | 770 | } |
| 768 | 771 | |
| 769 | 772 | // Validate request signature. |
| 770 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 773 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 771 | 774 | if adminAPIErr != ErrNone { |
| 772 | 775 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 773 | 776 | return |
| @@ -782,8 +785,7 @@ func (a adminAPIHandlers) RemoveUser(w http.ResponseWriter, r *http.Request) { · 8 unmodified lines | ||
| 782 | 785 | vars := mux.Vars(r) |
| 783 | 786 | accessKey := vars["accessKey"] |
| 784 | 787 | if err := globalIAMSys.DeleteUser(accessKey); err != nil { |
| 785 | − logger.LogIf(ctx, err) | |
| 786 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 788 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 787 | 789 | } |
| 788 | 790 | } |
| 789 | 791 | |
| @@ -799,7 +801,7 @@ func (a adminAPIHandlers) ListUsers(w http.ResponseWriter, r *http.Request) { · 9 unmodified lines | ||
| 799 | 801 | } |
| 800 | 802 | |
| 801 | 803 | // Validate request signature. |
| 802 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 804 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 803 | 805 | if adminAPIErr != ErrNone { |
| 804 | 806 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 805 | 807 | return |
| @@ -807,22 +809,20 @@ func (a adminAPIHandlers) ListUsers(w http.ResponseWriter, r *http.Request) { · 1 unmodified line | ||
| 807 | 809 | |
| 808 | 810 | allCredentials, err := globalIAMSys.ListUsers() |
| 809 | 811 | if err != nil { |
| 810 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 812 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 811 | 813 | return |
| 812 | 814 | } |
| 813 | 815 | |
| 814 | 816 | data, err := json.Marshal(allCredentials) |
| 815 | 817 | if err != nil { |
| 816 | − logger.LogIf(ctx, err) | |
| 817 | − writeErrorResponseJSON(w, ErrInternalError, r.URL) | |
| 818 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 818 | 819 | return |
| 819 | 820 | } |
| 820 | 821 | |
| 821 | 822 | password := globalServerConfig.GetCredential().SecretKey |
| 822 | 823 | econfigData, err := madmin.EncryptData(password, data) |
| 823 | 824 | if err != nil { |
| 824 | − logger.LogIf(ctx, err) | |
| 825 | − writeErrorResponseJSON(w, ErrInternalError, r.URL) | |
| 825 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 826 | 826 | return |
| 827 | 827 | } |
| 828 | 828 | |
| @@ -841,7 +841,7 @@ func (a adminAPIHandlers) SetUserStatus(w http.ResponseWriter, r *http.Request) · 12 unmodified lines | ||
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | // Validate request signature. |
| 844 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 844 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 845 | 845 | if adminAPIErr != ErrNone { |
| 846 | 846 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 847 | 847 | return |
| @@ -864,8 +864,7 @@ func (a adminAPIHandlers) SetUserStatus(w http.ResponseWriter, r *http.Request) · 16 unmodified lines | ||
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | if err := globalIAMSys.SetUserStatus(accessKey, madmin.AccountStatus(status)); err != nil { |
| 867 | − logger.LogIf(ctx, err) | |
| 868 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 867 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 869 | 868 | return |
| 870 | 869 | } |
| 871 | 870 | } |
| @@ -882,7 +881,7 @@ func (a adminAPIHandlers) AddUser(w http.ResponseWriter, r *http.Request) { · 10 unmodified lines | ||
| 882 | 881 | } |
| 883 | 882 | |
| 884 | 883 | // Validate request signature. |
| 885 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 884 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 886 | 885 | if adminAPIErr != ErrNone { |
| 887 | 886 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 888 | 887 | return |
| @@ -925,8 +924,7 @@ func (a adminAPIHandlers) AddUser(w http.ResponseWriter, r *http.Request) { · 36 unmodified lines | ||
| 925 | 924 | } |
| 926 | 925 | |
| 927 | 926 | if err = globalIAMSys.SetUser(accessKey, uinfo); err != nil { |
| 928 | − logger.LogIf(ctx, err) | |
| 929 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 927 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 930 | 928 | return |
| 931 | 929 | } |
| 932 | 930 | } |
| @@ -943,7 +941,7 @@ func (a adminAPIHandlers) ListCannedPolicies(w http.ResponseWriter, r *http.Requ · 10 unmodified lines | ||
| 943 | 941 | } |
| 944 | 942 | |
| 945 | 943 | // Validate request signature. |
| 946 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 944 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 947 | 945 | if adminAPIErr != ErrNone { |
| 948 | 946 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 949 | 947 | return |
| @@ -951,14 +949,12 @@ func (a adminAPIHandlers) ListCannedPolicies(w http.ResponseWriter, r *http.Requ · 1 unmodified line | ||
| 951 | 949 | |
| 952 | 950 | policies, err := globalIAMSys.ListCannedPolicies() |
| 953 | 951 | if err != nil { |
| 954 | − logger.LogIf(ctx, err) | |
| 955 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 952 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 956 | 953 | return |
| 957 | 954 | } |
| 958 | 955 | |
| 959 | 956 | if err = json.NewEncoder(w).Encode(policies); err != nil { |
| 960 | − logger.LogIf(ctx, err) | |
| 961 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 957 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 962 | 958 | return |
| 963 | 959 | } |
| 964 | 960 | |
| @@ -980,7 +976,7 @@ func (a adminAPIHandlers) RemoveCannedPolicy(w http.ResponseWriter, r *http.Requ · 15 unmodified lines | ||
| 980 | 976 | policyName := vars["name"] |
| 981 | 977 | |
| 982 | 978 | // Validate request signature. |
| 983 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 979 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 984 | 980 | if adminAPIErr != ErrNone { |
| 985 | 981 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 986 | 982 | return |
| @@ -993,8 +989,7 @@ func (a adminAPIHandlers) RemoveCannedPolicy(w http.ResponseWriter, r *http.Requ · 6 unmodified lines | ||
| 993 | 989 | } |
| 994 | 990 | |
| 995 | 991 | if err := globalIAMSys.DeleteCannedPolicy(policyName); err != nil { |
| 996 | − logger.LogIf(ctx, err) | |
| 997 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 992 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 998 | 993 | return |
| 999 | 994 | } |
| 1000 | 995 | } |
| @@ -1014,7 +1009,7 @@ func (a adminAPIHandlers) AddCannedPolicy(w http.ResponseWriter, r *http.Request · 13 unmodified lines | ||
| 1014 | 1009 | policyName := vars["name"] |
| 1015 | 1010 | |
| 1016 | 1011 | // Validate request signature. |
| 1017 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 1012 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 1018 | 1013 | if adminAPIErr != ErrNone { |
| 1019 | 1014 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 1020 | 1015 | return |
| @@ -1051,8 +1046,7 @@ func (a adminAPIHandlers) AddCannedPolicy(w http.ResponseWriter, r *http.Request · 30 unmodified lines | ||
| 1051 | 1046 | } |
| 1052 | 1047 | |
| 1053 | 1048 | if err = globalIAMSys.SetCannedPolicy(policyName, *iamPolicy); err != nil { |
| 1054 | − logger.LogIf(ctx, err) | |
| 1055 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1049 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1056 | 1050 | return |
| 1057 | 1051 | } |
| 1058 | 1052 | } |
| @@ -1073,7 +1067,7 @@ func (a adminAPIHandlers) SetUserPolicy(w http.ResponseWriter, r *http.Request) · 14 unmodified lines | ||
| 1073 | 1067 | policyName := vars["name"] |
| 1074 | 1068 | |
| 1075 | 1069 | // Validate request signature. |
| 1076 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 1070 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 1077 | 1071 | if adminAPIErr != ErrNone { |
| 1078 | 1072 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 1079 | 1073 | return |
| @@ -1092,8 +1086,7 @@ func (a adminAPIHandlers) SetUserPolicy(w http.ResponseWriter, r *http.Request) · 12 unmodified lines | ||
| 1092 | 1086 | } |
| 1093 | 1087 | |
| 1094 | 1088 | if err := globalIAMSys.SetUserPolicy(accessKey, policyName); err != nil { |
| 1095 | − logger.LogIf(ctx, err) | |
| 1096 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1089 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1097 | 1090 | } |
| 1098 | 1091 | } |
| 1099 | 1092 | |
| @@ -1109,7 +1102,7 @@ func (a adminAPIHandlers) SetConfigHandler(w http.ResponseWriter, r *http.Reques · 9 unmodified lines | ||
| 1109 | 1102 | } |
| 1110 | 1103 | |
| 1111 | 1104 | // Validate request signature. |
| 1112 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 1105 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 1113 | 1106 | if adminAPIErr != ErrNone { |
| 1114 | 1107 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 1115 | 1108 | return |
| @@ -1172,7 +1165,7 @@ func (a adminAPIHandlers) SetConfigHandler(w http.ResponseWriter, r *http.Reques · 56 unmodified lines | ||
| 1172 | 1165 | } |
| 1173 | 1166 | |
| 1174 | 1167 | if err = saveServerConfig(ctx, objectAPI, &config); err != nil { |
| 1175 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1168 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1176 | 1169 | return |
| 1177 | 1170 | } |
| 1178 | 1171 | |
| @@ -1214,7 +1207,7 @@ func (a adminAPIHandlers) SetConfigKeysHandler(w http.ResponseWriter, r *http.Re · 35 unmodified lines | ||
| 1214 | 1207 | } |
| 1215 | 1208 | |
| 1216 | 1209 | // Validate request signature. |
| 1217 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 1210 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 1218 | 1211 | if adminAPIErr != ErrNone { |
| 1219 | 1212 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 1220 | 1213 | return |
| @@ -1223,15 +1216,14 @@ func (a adminAPIHandlers) SetConfigKeysHandler(w http.ResponseWriter, r *http.Re · 2 unmodified lines | ||
| 1223 | 1216 | // Load config |
| 1224 | 1217 | configStruct, err := readServerConfig(ctx, objectAPI) |
| 1225 | 1218 | if err != nil { |
| 1226 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1219 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1227 | 1220 | return |
| 1228 | 1221 | } |
| 1229 | 1222 | |
| 1230 | 1223 | // Convert config to json bytes |
| 1231 | 1224 | configBytes, err := json.Marshal(configStruct) |
| 1232 | 1225 | if err != nil { |
| 1233 | − logger.LogIf(ctx, err) | |
| 1234 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1226 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1235 | 1227 | return |
| 1236 | 1228 | } |
| 1237 | 1229 | |
| @@ -1303,7 +1295,7 @@ func (a adminAPIHandlers) SetConfigKeysHandler(w http.ResponseWriter, r *http.Re · 65 unmodified lines | ||
| 1303 | 1295 | } |
| 1304 | 1296 | |
| 1305 | 1297 | if err = saveServerConfig(ctx, objectAPI, &config); err != nil { |
| 1306 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1298 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1307 | 1299 | return |
| 1308 | 1300 | } |
| 1309 | 1301 | |
| @@ -1334,7 +1326,7 @@ func (a adminAPIHandlers) UpdateAdminCredentialsHandler(w http.ResponseWriter, · 24 unmodified lines | ||
| 1334 | 1326 | } |
| 1335 | 1327 | |
| 1336 | 1328 | // Authenticate request |
| 1337 | − adminAPIErr := checkAdminRequestAuthType(r, "") | |
| 1329 | + adminAPIErr := checkAdminRequestAuthType(ctx, r, "") | |
| 1338 | 1330 | if adminAPIErr != ErrNone { |
| 1339 | 1331 | writeErrorResponseJSON(w, adminAPIErr, r.URL) |
| 1340 | 1332 | return |
| @@ -1364,7 +1356,7 @@ func (a adminAPIHandlers) UpdateAdminCredentialsHandler(w http.ResponseWriter, · 23 unmodified lines | ||
| 1364 | 1356 | |
| 1365 | 1357 | creds, err := auth.CreateCredentials(req.AccessKey, req.SecretKey) |
| 1366 | 1358 | if err != nil { |
| 1367 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1359 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1368 | 1360 | return |
| 1369 | 1361 | } |
| 1370 | 1362 | |
| @@ -1379,7 +1371,7 @@ func (a adminAPIHandlers) UpdateAdminCredentialsHandler(w http.ResponseWriter, · 8 unmodified lines | ||
| 1379 | 1371 | globalActiveCred = creds |
| 1380 | 1372 | |
| 1381 | 1373 | if err = saveServerConfig(ctx, objectAPI, globalServerConfig); err != nil { |
| 1382 | − writeErrorResponseJSON(w, toAdminAPIErrCode(err), r.URL) | |
| 1374 | + writeErrorResponseJSON(w, toAdminAPIErrCode(ctx, err), r.URL) | |
| 1383 | 1375 | return |
| 1384 | 1376 | } |
| 1385 | 1377 | |
| @@ -867,12 +867,12 @@ func TestToAdminAPIErr(t *testing.T) { · 866 unmodified lines | ||
| 867 | 867 | // 3. Non-admin API specific error. |
| 868 | 868 | { |
| 869 | 869 | err: errDiskNotFound, |
| 870 | − expectedAPIErr: toAPIErrorCode(errDiskNotFound), | |
| 870 | + expectedAPIErr: toAPIErrorCode(context.Background(), errDiskNotFound), | |
| 871 | 871 | }, |
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | for i, test := range testCases { |
| 875 | − actualErr := toAdminAPIErrCode(test.err) | |
| 875 | + actualErr := toAdminAPIErrCode(context.Background(), test.err) | |
| 876 | 876 | if actualErr != test.expectedAPIErr { |
| 877 | 877 | t.Errorf("Test %d: Expected %v but received %v", |
| 878 | 878 | i+1, test.expectedAPIErr, actualErr) |
| @@ -62,8 +62,8 @@ var ( · 61 unmodified lines | ||
| 62 | 62 | errHealPushStopNDiscard = fmt.Errorf("heal push stopped due to heal stop signal") |
| 63 | 63 | errHealStopSignalled = fmt.Errorf("heal stop signaled") |
| 64 | 64 | |
| 65 | − errFnHealFromAPIErr = func(err error) error { | |
| 66 | − errCode := toAPIErrorCode(err) | |
| 65 | + errFnHealFromAPIErr = func(ctx context.Context, err error) error { | |
| 66 | + errCode := toAPIErrorCode(ctx, err) | |
| 67 | 67 | apiErr := getAPIError(errCode) |
| 68 | 68 | return fmt.Errorf("Heal internal error: %s: %s", |
| 69 | 69 | apiErr.Code, apiErr.Description) |
| @@ -150,7 +150,7 @@ func (ahs *allHealState) stopHealSequence(path string) ([]byte, APIErrorCode) { · 80 unmodified lines | ||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | b, err := json.Marshal(&hsp) |
| 153 | − return b, toAdminAPIErrCode(err) | |
| 153 | + return b, toAdminAPIErrCode(context.Background(), err) | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // LaunchNewHealSequence - launches a background routine that performs |
| @@ -254,7 +254,7 @@ func (ahs *allHealState) LaunchNewHealSequence(h *healSequence) ( · 97 unmodified lines | ||
| 254 | 254 | StartTime: h.startTime, |
| 255 | 255 | }) |
| 256 | 256 | if err != nil { |
| 257 | − logger.LogIf(context.Background(), err) | |
| 257 | + logger.LogIf(h.ctx, err) | |
| 258 | 258 | return nil, ErrInternalError, "" |
| 259 | 259 | } |
| 260 | 260 | return b, ErrNone, "" |
| @@ -302,7 +302,7 @@ func (ahs *allHealState) PopHealStatusJSON(path string, · 41 unmodified lines | ||
| 302 | 302 | |
| 303 | 303 | jbytes, err := json.Marshal(h.currentStatus) |
| 304 | 304 | if err != nil { |
| 305 | − logger.LogIf(context.Background(), err) | |
| 305 | + logger.LogIf(h.ctx, err) | |
| 306 | 306 | return nil, ErrInternalError |
| 307 | 307 | } |
| 308 | 308 | |
| @@ -592,7 +592,7 @@ func (h *healSequence) healConfig() error { · 283 unmodified lines | ||
| 592 | 592 | objectInfos, err := objectAPI.ListObjectsHeal(h.ctx, minioMetaBucket, minioConfigPrefix, |
| 593 | 593 | marker, "", 1000) |
| 594 | 594 | if err != nil { |
| 595 | − return errFnHealFromAPIErr(err) | |
| 595 | + return errFnHealFromAPIErr(h.ctx, err) | |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | for index := range objectInfos.Objects { |
| @@ -639,7 +639,7 @@ func (h *healSequence) healDiskFormat() error { · 40 unmodified lines | ||
| 639 | 639 | // return any error, ignore error returned when disks have |
| 640 | 640 | // already healed. |
| 641 | 641 | if err != nil && err != errNoHealRequired { |
| 642 | − return errFnHealFromAPIErr(err) | |
| 642 | + return errFnHealFromAPIErr(h.ctx, err) | |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | // Healing succeeded notify the peers to reload format and re-initialize disks. |
| @@ -671,7 +671,7 @@ func (h *healSequence) healBuckets() error { · 25 unmodified lines | ||
| 671 | 671 | |
| 672 | 672 | buckets, err := objectAPI.ListBucketsHeal(h.ctx) |
| 673 | 673 | if err != nil { |
| 674 | − return errFnHealFromAPIErr(err) | |
| 674 | + return errFnHealFromAPIErr(h.ctx, err) | |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | for _, bucket := range buckets { |
| @@ -738,7 +738,7 @@ func (h *healSequence) healBucket(bucket string) error { · 60 unmodified lines | ||
| 738 | 738 | objectInfos, err := objectAPI.ListObjectsHeal(h.ctx, bucket, |
| 739 | 739 | h.objPrefix, marker, "", entries) |
| 740 | 740 | if err != nil { |
| 741 | − return errFnHealFromAPIErr(err) | |
| 741 | + return errFnHealFromAPIErr(h.ctx, err) | |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | g := errgroup.WithNErrs(len(objectInfos.Objects)) |
| @@ -23,6 +23,7 @@ import ( · 22 unmodified lines | ||
| 23 | 23 | "net/http" |
| 24 | 24 | |
| 25 | 25 | "github.com/minio/minio/cmd/crypto" |
| 26 | + "github.com/minio/minio/cmd/logger" | |
| 26 | 27 | "github.com/minio/minio/pkg/auth" |
| 27 | 28 | "github.com/minio/minio/pkg/dns" |
| 28 | 29 | "github.com/minio/minio/pkg/event" |
| @@ -1440,7 +1441,7 @@ var errorCodeResponse = map[APIErrorCode]APIError{ · 1411 unmodified lines | ||
| 1440 | 1441 | // toAPIErrorCode - Converts embedded errors. Convenience |
| 1441 | 1442 | // function written to handle all cases where we have known types of |
| 1442 | 1443 | // errors returned by underlying layers. |
| 1443 | −func toAPIErrorCode(err error) (apiErr APIErrorCode) { | |
| 1444 | +func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) { | |
| 1444 | 1445 | if err == nil { |
| 1445 | 1446 | return ErrNone |
| 1446 | 1447 | } |
| @@ -1767,6 +1768,10 @@ func toAPIErrorCode(err error) (apiErr APIErrorCode) { · 320 unmodified lines | ||
| 1767 | 1768 | apiErr = ErrObjectTampered |
| 1768 | 1769 | default: |
| 1769 | 1770 | apiErr = ErrInternalError |
| 1771 | + // Make sure to log the errors which we cannot translate | |
| 1772 | + // to a meaningful S3 API errors. This is added to aid in | |
| 1773 | + // debugging unexpected/unhandled errors. | |
| 1774 | + logger.LogIf(ctx, err) | |
| 1770 | 1775 | } |
| 1771 | 1776 | |
| 1772 | 1777 | return apiErr |
| @@ -17,6 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | package cmd |
| 18 | 18 | |
| 19 | 19 | import ( |
| 20 | + "context" | |
| 20 | 21 | "errors" |
| 21 | 22 | "testing" |
| 22 | 23 | |
| @@ -64,8 +65,9 @@ var toAPIErrorCodeTests = []struct { · 41 unmodified lines | ||
| 64 | 65 | } |
| 65 | 66 | |
| 66 | 67 | func TestAPIErrCode(t *testing.T) { |
| 68 | + ctx := context.Background() | |
| 67 | 69 | for i, testCase := range toAPIErrorCodeTests { |
| 68 | − errCode := toAPIErrorCode(testCase.err) | |
| 70 | + errCode := toAPIErrorCode(ctx, testCase.err) | |
| 69 | 71 | if errCode != testCase.errCode { |
| 70 | 72 | t.Errorf("Test %d: Expected error code %d, got %d", i+1, testCase.errCode, errCode) |
| 71 | 73 | } |
| @@ -16,7 +16,10 @@ · 15 unmodified lines | ||
| 16 | 16 | |
| 17 | 17 | package cmd |
| 18 | 18 | |
| 19 | −import "net/http" | |
| 19 | +import ( | |
| 20 | + "context" | |
| 21 | + "net/http" | |
| 22 | +) | |
| 20 | 23 | |
| 21 | 24 | // Represents additional fields necessary for ErrPartTooSmall S3 error. |
| 22 | 25 | type completeMultipartAPIError struct { |
| @@ -42,7 +45,7 @@ type completeMultipartAPIError struct { · 19 unmodified lines | ||
| 42 | 45 | // of this function. |
| 43 | 46 | func writePartSmallErrorResponse(w http.ResponseWriter, r *http.Request, err PartTooSmall) { |
| 44 | 47 | |
| 45 | − apiError := getAPIError(toAPIErrorCode(err)) | |
| 48 | + apiError := getAPIError(toAPIErrorCode(context.Background(), err)) | |
| 46 | 49 | // Generate complete multipart error response. |
| 47 | 50 | errorResponse := getAPIErrorResponse(apiError, r.URL.Path, w.Header().Get(responseRequestIDKey)) |
| 48 | 51 | cmpErrResp := completeMultipartAPIError{err.PartSize, int64(5242880), err.PartNumber, err.PartETag, errorResponse} |
| @@ -119,7 +119,7 @@ func getRequestAuthType(r *http.Request) authType { · 118 unmodified lines | ||
| 119 | 119 | |
| 120 | 120 | // checkAdminRequestAuthType checks whether the request is a valid signature V2 or V4 request. |
| 121 | 121 | // It does not accept presigned or JWT or anonymous requests. |
| 122 | −func checkAdminRequestAuthType(r *http.Request, region string) APIErrorCode { | |
| 122 | +func checkAdminRequestAuthType(ctx context.Context, r *http.Request, region string) APIErrorCode { | |
| 123 | 123 | s3Err := ErrAccessDenied |
| 124 | 124 | if _, ok := r.Header["X-Amz-Content-Sha256"]; ok && |
| 125 | 125 | getRequestAuthType(r) == authTypeSigned && !skipContentSha256Cksum(r) { |
| @@ -136,11 +136,11 @@ func checkAdminRequestAuthType(r *http.Request, region string) APIErrorCode { · 10 unmodified lines | ||
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // we only support V4 (no presign) with auth body |
| 139 | − s3Err = isReqAuthenticated(r, region) | |
| 139 | + s3Err = isReqAuthenticated(ctx, r, region) | |
| 140 | 140 | } |
| 141 | 141 | if s3Err != ErrNone { |
| 142 | 142 | reqInfo := (&logger.ReqInfo{}).AppendTags("requestHeaders", dumpRequest(r)) |
| 143 | − ctx := logger.SetReqInfo(context.Background(), reqInfo) | |
| 143 | + ctx := logger.SetReqInfo(ctx, reqInfo) | |
| 144 | 144 | logger.LogIf(ctx, errors.New(getAPIError(s3Err).Description)) |
| 145 | 145 | } |
| 146 | 146 | return s3Err |
| @@ -194,10 +194,10 @@ func getClaimsFromToken(r *http.Request, cred auth.Credentials) (map[string]inte · 47 unmodified lines | ||
| 194 | 194 | p := &jwtgo.Parser{} |
| 195 | 195 | jtoken, err := p.ParseWithClaims(token, jwtgo.MapClaims(claims), stsTokenCallback) |
| 196 | 196 | if err != nil { |
| 197 | − return nil, toAPIErrorCode(errAuthentication) | |
| 197 | + return nil, toAPIErrorCode(context.Background(), errAuthentication) | |
| 198 | 198 | } |
| 199 | 199 | if !jtoken.Valid { |
| 200 | − return nil, toAPIErrorCode(errAuthentication) | |
| 200 | + return nil, toAPIErrorCode(context.Background(), errAuthentication) | |
| 201 | 201 | } |
| 202 | 202 | return claims, ErrNone |
| 203 | 203 | } |
| @@ -224,7 +224,7 @@ func checkRequestAuthType(ctx context.Context, r *http.Request, action policy.Ac · 20 unmodified lines | ||
| 224 | 224 | case policy.GetBucketLocationAction, policy.ListAllMyBucketsAction: |
| 225 | 225 | region = "" |
| 226 | 226 | } |
| 227 | − if s3Err = isReqAuthenticated(r, region); s3Err != ErrNone { | |
| 227 | + if s3Err = isReqAuthenticated(ctx, r, region); s3Err != ErrNone { | |
| 228 | 228 | return s3Err |
| 229 | 229 | } |
| 230 | 230 | cred, owner, s3Err = getReqAccessKeyV4(r, region) |
| @@ -310,7 +310,7 @@ func reqSignatureV4Verify(r *http.Request, region string) (s3Error APIErrorCode) · 79 unmodified lines | ||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // Verify if request has valid AWS Signature Version '4'. |
| 313 | −func isReqAuthenticated(r *http.Request, region string) (s3Error APIErrorCode) { | |
| 313 | +func isReqAuthenticated(ctx context.Context, r *http.Request, region string) (s3Error APIErrorCode) { | |
| 314 | 314 | if errCode := reqSignatureV4Verify(r, region); errCode != ErrNone { |
| 315 | 315 | return errCode |
| 316 | 316 | } |
| @@ -347,7 +347,7 @@ func isReqAuthenticated(r *http.Request, region string) (s3Error APIErrorCode) { · 30 unmodified lines | ||
| 347 | 347 | // The verification happens implicit during reading. |
| 348 | 348 | reader, err := hash.NewReader(r.Body, -1, hex.EncodeToString(contentMD5), hex.EncodeToString(contentSHA256), -1) |
| 349 | 349 | if err != nil { |
| 350 | − return toAPIErrorCode(err) | |
| 350 | + return toAPIErrorCode(ctx, err) | |
| 351 | 351 | } |
| 352 | 352 | r.Body = ioutil.NopCloser(reader) |
| 353 | 353 | return ErrNone |
| @@ -18,6 +18,7 @@ package cmd · 17 unmodified lines | ||
| 18 | 18 | |
| 19 | 19 | import ( |
| 20 | 20 | "bytes" |
| 21 | + "context" | |
| 21 | 22 | "io" |
| 22 | 23 | "io/ioutil" |
| 23 | 24 | "net/http" |
| @@ -377,11 +378,12 @@ func TestIsReqAuthenticated(t *testing.T) { · 353 unmodified lines | ||
| 377 | 378 | {mustNewSignedRequest("GET", "http://127.0.0.1:9000", 0, nil, t), ErrNone}, |
| 378 | 379 | } |
| 379 | 380 | |
| 381 | + ctx := context.Background() | |
| 380 | 382 | // Validates all testcases. |
| 381 | 383 | for i, testCase := range testCases { |
| 382 | − if s3Error := isReqAuthenticated(testCase.req, globalServerConfig.GetRegion()); s3Error != testCase.s3Error { | |
| 383 | − if _, err := ioutil.ReadAll(testCase.req.Body); toAPIErrorCode(err) != testCase.s3Error { | |
| 384 | − t.Fatalf("Test %d: Unexpected S3 error: want %d - got %d (got after reading request %d)", i, testCase.s3Error, s3Error, toAPIErrorCode(err)) | |
| 384 | + if s3Error := isReqAuthenticated(ctx, testCase.req, globalServerConfig.GetRegion()); s3Error != testCase.s3Error { | |
| 385 | + if _, err := ioutil.ReadAll(testCase.req.Body); toAPIErrorCode(ctx, err) != testCase.s3Error { | |
| 386 | + t.Fatalf("Test %d: Unexpected S3 error: want %d - got %d (got after reading request %d)", i, testCase.s3Error, s3Error, toAPIErrorCode(ctx, err)) | |
| 385 | 387 | } |
| 386 | 388 | } |
| 387 | 389 | } |
| @@ -413,8 +415,9 @@ func TestCheckAdminRequestAuthType(t *testing.T) { · 25 unmodified lines | ||
| 413 | 415 | {Request: mustNewPresignedV2Request("GET", "http://127.0.0.1:9000", 0, nil, t), ErrCode: ErrAccessDenied}, |
| 414 | 416 | {Request: mustNewPresignedRequest("GET", "http://127.0.0.1:9000", 0, nil, t), ErrCode: ErrAccessDenied}, |
| 415 | 417 | } |
| 418 | + ctx := context.Background() | |
| 416 | 419 | for i, testCase := range testCases { |
| 417 | − if s3Error := checkAdminRequestAuthType(testCase.Request, globalServerConfig.GetRegion()); s3Error != testCase.ErrCode { | |
| 420 | + if s3Error := checkAdminRequestAuthType(ctx, testCase.Request, globalServerConfig.GetRegion()); s3Error != testCase.ErrCode { | |
| 418 | 421 | t.Errorf("Test %d: Unexpected s3error returned wanted %d, got %d", i, testCase.ErrCode, s3Error) |
| 419 | 422 | } |
| 420 | 423 | } |
| @@ -100,7 +100,7 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http · 99 unmodified lines | ||
| 100 | 100 | // marshaled into S3 compatible XML header. |
| 101 | 101 | listObjectsV2Info, err := listObjectsV2(ctx, bucket, prefix, token, delimiter, maxKeys, fetchOwner, startAfter) |
| 102 | 102 | if err != nil { |
| 103 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 103 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 104 | 104 | return |
| 105 | 105 | } |
| 106 | 106 | |
| @@ -118,7 +118,7 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http · 11 unmodified lines | ||
| 118 | 118 | } else if crypto.IsEncrypted(listObjectsV2Info.Objects[i].UserDefined) { |
| 119 | 119 | listObjectsV2Info.Objects[i].Size, err = listObjectsV2Info.Objects[i].DecryptedSize() |
| 120 | 120 | if err != nil { |
| 121 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 121 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 122 | 122 | return |
| 123 | 123 | } |
| 124 | 124 | } |
| @@ -182,7 +182,7 @@ func (api objectAPIHandlers) ListObjectsV1Handler(w http.ResponseWriter, r *http · 57 unmodified lines | ||
| 182 | 182 | // marshaled into S3 compatible XML header. |
| 183 | 183 | listObjectsInfo, err := listObjects(ctx, bucket, prefix, marker, delimiter, maxKeys) |
| 184 | 184 | if err != nil { |
| 185 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 185 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 186 | 186 | return |
| 187 | 187 | } |
| 188 | 188 | |
| @@ -200,7 +200,7 @@ func (api objectAPIHandlers) ListObjectsV1Handler(w http.ResponseWriter, r *http · 11 unmodified lines | ||
| 200 | 200 | } else if crypto.IsEncrypted(listObjectsInfo.Objects[i].UserDefined) { |
| 201 | 201 | listObjectsInfo.Objects[i].Size, err = listObjectsInfo.Objects[i].DecryptedSize() |
| 202 | 202 | if err != nil { |
| 203 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 203 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 204 | 204 | return |
| 205 | 205 | } |
| 206 | 206 | } |
| @@ -110,7 +110,7 @@ func (api objectAPIHandlers) GetBucketLocationHandler(w http.ResponseWriter, r * · 109 unmodified lines | ||
| 110 | 110 | getBucketInfo = api.CacheAPI().GetBucketInfo |
| 111 | 111 | } |
| 112 | 112 | if _, err := getBucketInfo(ctx, bucket); err != nil { |
| 113 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 113 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 114 | 114 | return |
| 115 | 115 | } |
| 116 | 116 | |
| @@ -174,7 +174,7 @@ func (api objectAPIHandlers) ListMultipartUploadsHandler(w http.ResponseWriter, · 57 unmodified lines | ||
| 174 | 174 | |
| 175 | 175 | listMultipartsInfo, err := objectAPI.ListMultipartUploads(ctx, bucket, prefix, keyMarker, uploadIDMarker, delimiter, maxUploads) |
| 176 | 176 | if err != nil { |
| 177 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 177 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 178 | 178 | return |
| 179 | 179 | } |
| 180 | 180 | // generate response |
| @@ -214,7 +214,7 @@ func (api objectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.R · 33 unmodified lines | ||
| 214 | 214 | if globalDNSConfig != nil { |
| 215 | 215 | dnsBuckets, err := globalDNSConfig.List() |
| 216 | 216 | if err != nil && err != dns.ErrNoEntriesFound { |
| 217 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 217 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 218 | 218 | return |
| 219 | 219 | } |
| 220 | 220 | bucketSet := set.NewStringSet() |
| @@ -233,7 +233,7 @@ func (api objectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.R · 12 unmodified lines | ||
| 233 | 233 | var err error |
| 234 | 234 | bucketsInfo, err = listBuckets(ctx) |
| 235 | 235 | if err != nil { |
| 236 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 236 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 237 | 237 | return |
| 238 | 238 | } |
| 239 | 239 | } |
| @@ -354,8 +354,8 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, · 114 unmodified lines | ||
| 354 | 354 | } |
| 355 | 355 | // Error during delete should be collected separately. |
| 356 | 356 | deleteErrors = append(deleteErrors, DeleteError{ |
| 357 | − Code: errorCodeResponse[toAPIErrorCode(err)].Code, | |
| 358 | − Message: errorCodeResponse[toAPIErrorCode(err)].Description, | |
| 357 | + Code: errorCodeResponse[toAPIErrorCode(ctx, err)].Code, | |
| 358 | + Message: errorCodeResponse[toAPIErrorCode(ctx, err)].Description, | |
| 359 | 359 | Key: object.ObjectName, |
| 360 | 360 | }) |
| 361 | 361 | } |
| @@ -432,12 +432,12 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req · 70 unmodified lines | ||
| 432 | 432 | if err == dns.ErrNoEntriesFound { |
| 433 | 433 | // Proceed to creating a bucket. |
| 434 | 434 | if err = objectAPI.MakeBucketWithLocation(ctx, bucket, location); err != nil { |
| 435 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 435 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 436 | 436 | return |
| 437 | 437 | } |
| 438 | 438 | if err = globalDNSConfig.Put(bucket); err != nil { |
| 439 | 439 | objectAPI.DeleteBucket(ctx, bucket) |
| 440 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 440 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 441 | 441 | return |
| 442 | 442 | } |
| 443 | 443 | |
| @@ -447,7 +447,7 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req · 3 unmodified lines | ||
| 447 | 447 | writeSuccessResponseHeadersOnly(w) |
| 448 | 448 | return |
| 449 | 449 | } |
| 450 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 450 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 451 | 451 | return |
| 452 | 452 | |
| 453 | 453 | } |
| @@ -458,7 +458,7 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req · 4 unmodified lines | ||
| 458 | 458 | // Proceed to creating a bucket. |
| 459 | 459 | err := objectAPI.MakeBucketWithLocation(ctx, bucket, location) |
| 460 | 460 | if err != nil { |
| 461 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 461 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 462 | 462 | return |
| 463 | 463 | } |
| 464 | 464 | |
| @@ -589,12 +589,12 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h · 124 unmodified lines | ||
| 589 | 589 | lengthRange := postPolicyForm.Conditions.ContentLengthRange |
| 590 | 590 | if lengthRange.Valid { |
| 591 | 591 | if fileSize < lengthRange.Min { |
| 592 | − writeErrorResponse(w, toAPIErrorCode(errDataTooSmall), r.URL) | |
| 592 | + writeErrorResponse(w, toAPIErrorCode(ctx, errDataTooSmall), r.URL) | |
| 593 | 593 | return |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | if fileSize > lengthRange.Max || isMaxObjectSize(fileSize) { |
| 597 | − writeErrorResponse(w, toAPIErrorCode(errDataTooLarge), r.URL) | |
| 597 | + writeErrorResponse(w, toAPIErrorCode(ctx, errDataTooLarge), r.URL) | |
| 598 | 598 | return |
| 599 | 599 | } |
| 600 | 600 | } |
| @@ -610,7 +610,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h · 9 unmodified lines | ||
| 610 | 610 | hashReader, err := hash.NewReader(fileBody, fileSize, "", "", fileSize) |
| 611 | 611 | if err != nil { |
| 612 | 612 | logger.LogIf(ctx, err) |
| 613 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 613 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 614 | 614 | return |
| 615 | 615 | } |
| 616 | 616 | |
| @@ -621,19 +621,19 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h · 4 unmodified lines | ||
| 621 | 621 | if crypto.SSEC.IsRequested(formValues) { |
| 622 | 622 | key, err = ParseSSECustomerHeader(formValues) |
| 623 | 623 | if err != nil { |
| 624 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 624 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 625 | 625 | return |
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | reader, err = newEncryptReader(hashReader, key, bucket, object, metadata, crypto.S3.IsRequested(formValues)) |
| 629 | 629 | if err != nil { |
| 630 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 630 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 631 | 631 | return |
| 632 | 632 | } |
| 633 | 633 | info := ObjectInfo{Size: fileSize} |
| 634 | 634 | hashReader, err = hash.NewReader(reader, info.EncryptedSize(), "", "", fileSize) // do not try to verify encrypted content |
| 635 | 635 | if err != nil { |
| 636 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 636 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 637 | 637 | return |
| 638 | 638 | } |
| 639 | 639 | } |
| @@ -641,7 +641,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h · 1 unmodified line | ||
| 641 | 641 | |
| 642 | 642 | objInfo, err := objectAPI.PutObject(ctx, bucket, object, hashReader, metadata, ObjectOptions{}) |
| 643 | 643 | if err != nil { |
| 644 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 644 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 645 | 645 | return |
| 646 | 646 | } |
| 647 | 647 | |
| @@ -721,7 +721,7 @@ func (api objectAPIHandlers) HeadBucketHandler(w http.ResponseWriter, r *http.Re · 73 unmodified lines | ||
| 721 | 721 | getBucketInfo = api.CacheAPI().GetBucketInfo |
| 722 | 722 | } |
| 723 | 723 | if _, err := getBucketInfo(ctx, bucket); err != nil { |
| 724 | − writeErrorResponseHeadersOnly(w, toAPIErrorCode(err)) | |
| 724 | + writeErrorResponseHeadersOnly(w, toAPIErrorCode(ctx, err)) | |
| 725 | 725 | return |
| 726 | 726 | } |
| 727 | 727 | |
| @@ -754,7 +754,7 @@ func (api objectAPIHandlers) DeleteBucketHandler(w http.ResponseWriter, r *http. · 26 unmodified lines | ||
| 754 | 754 | } |
| 755 | 755 | // Attempt to delete bucket. |
| 756 | 756 | if err := deleteBucket(ctx, bucket); err != nil { |
| 757 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 757 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 758 | 758 | return |
| 759 | 759 | } |
| 760 | 760 | |
| @@ -766,7 +766,7 @@ func (api objectAPIHandlers) DeleteBucketHandler(w http.ResponseWriter, r *http. · 5 unmodified lines | ||
| 766 | 766 | if err := globalDNSConfig.Delete(bucket); err != nil { |
| 767 | 767 | // Deleting DNS entry failed, attempt to create the bucket again. |
| 768 | 768 | objectAPI.MakeBucketWithLocation(ctx, bucket, "") |
| 769 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 769 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 770 | 770 | return |
| 771 | 771 | } |
| 772 | 772 | } |
| @@ -67,7 +67,7 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter, · 66 unmodified lines | ||
| 67 | 67 | |
| 68 | 68 | _, err := objAPI.GetBucketInfo(ctx, bucketName) |
| 69 | 69 | if err != nil { |
| 70 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 70 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 71 | 71 | return |
| 72 | 72 | } |
| 73 | 73 | |
| @@ -76,7 +76,7 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter, · 2 unmodified lines | ||
| 76 | 76 | if err != nil { |
| 77 | 77 | // Ignore errNoSuchNotifications to comply with AWS S3. |
| 78 | 78 | if err != errNoSuchNotifications { |
| 79 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 79 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 80 | 80 | return |
| 81 | 81 | } |
| 82 | 82 | |
| @@ -90,8 +90,7 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter, · 7 unmodified lines | ||
| 90 | 90 | |
| 91 | 91 | notificationBytes, err := xml.Marshal(nConfig) |
| 92 | 92 | if err != nil { |
| 93 | − logger.LogIf(ctx, err) | |
| 94 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 93 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 95 | 94 | return |
| 96 | 95 | } |
| 97 | 96 | |
| @@ -126,7 +125,7 @@ func (api objectAPIHandlers) PutBucketNotificationHandler(w http.ResponseWriter, · 28 unmodified lines | ||
| 126 | 125 | |
| 127 | 126 | _, err := objectAPI.GetBucketInfo(ctx, bucketName) |
| 128 | 127 | if err != nil { |
| 129 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 128 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 130 | 129 | return |
| 131 | 130 | } |
| 132 | 131 | |
| @@ -141,7 +140,7 @@ func (api objectAPIHandlers) PutBucketNotificationHandler(w http.ResponseWriter, · 8 unmodified lines | ||
| 141 | 140 | if err != nil { |
| 142 | 141 | apiErr := ErrMalformedXML |
| 143 | 142 | if event.IsEventError(err) { |
| 144 | − apiErr = toAPIErrorCode(err) | |
| 143 | + apiErr = toAPIErrorCode(ctx, err) | |
| 145 | 144 | } |
| 146 | 145 | |
| 147 | 146 | writeErrorResponse(w, apiErr, r.URL) |
| @@ -149,7 +148,7 @@ func (api objectAPIHandlers) PutBucketNotificationHandler(w http.ResponseWriter, · 1 unmodified line | ||
| 149 | 148 | } |
| 150 | 149 | |
| 151 | 150 | if err = saveNotificationConfig(ctx, objectAPI, bucketName, config); err != nil { |
| 152 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 151 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 153 | 152 | return |
| 154 | 153 | } |
| 155 | 154 | |
| @@ -194,7 +193,7 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit · 38 unmodified lines | ||
| 194 | 193 | } |
| 195 | 194 | if len(values["prefix"]) == 1 { |
| 196 | 195 | if err := event.ValidateFilterRuleValue(values["prefix"][0]); err != nil { |
| 197 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 196 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 198 | 197 | return |
| 199 | 198 | } |
| 200 | 199 | |
| @@ -207,7 +206,7 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit · 6 unmodified lines | ||
| 207 | 206 | } |
| 208 | 207 | if len(values["suffix"]) == 1 { |
| 209 | 208 | if err := event.ValidateFilterRuleValue(values["suffix"][0]); err != nil { |
| 210 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 209 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 211 | 210 | return |
| 212 | 211 | } |
| 213 | 212 | |
| @@ -220,7 +219,7 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit · 6 unmodified lines | ||
| 220 | 219 | for _, s := range values["events"] { |
| 221 | 220 | eventName, err := event.ParseName(s) |
| 222 | 221 | if err != nil { |
| 223 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 222 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 224 | 223 | return |
| 225 | 224 | } |
| 226 | 225 | |
| @@ -228,19 +227,19 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit · 1 unmodified line | ||
| 228 | 227 | } |
| 229 | 228 | |
| 230 | 229 | if _, err := objAPI.GetBucketInfo(ctx, bucketName); err != nil { |
| 231 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 230 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 232 | 231 | return |
| 233 | 232 | } |
| 234 | 233 | |
| 235 | 234 | host, err := xnet.ParseHost(r.RemoteAddr) |
| 236 | 235 | if err != nil { |
| 237 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 236 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 238 | 237 | return |
| 239 | 238 | } |
| 240 | 239 | |
| 241 | 240 | target, err := target.NewHTTPClientTarget(*host, w) |
| 242 | 241 | if err != nil { |
| 243 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 242 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 244 | 243 | return |
| 245 | 244 | } |
| 246 | 245 | |
| @@ -248,8 +247,7 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit · 1 unmodified line | ||
| 248 | 247 | |
| 249 | 248 | if err = globalNotificationSys.AddRemoteTarget(bucketName, target, rulesMap); err != nil { |
| 250 | 249 | logger.GetReqInfo(ctx).AppendTags("target", target.ID().Name) |
| 251 | − logger.LogIf(ctx, err) | |
| 252 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 250 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 253 | 251 | return |
| 254 | 252 | } |
| 255 | 253 | defer globalNotificationSys.RemoveRemoteTarget(bucketName, target.ID()) |
| @@ -257,14 +255,13 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit · 1 unmodified line | ||
| 257 | 255 | |
| 258 | 256 | thisAddr, err := xnet.ParseHost(GetLocalPeer(globalEndpoints)) |
| 259 | 257 | if err != nil { |
| 260 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 258 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 261 | 259 | return |
| 262 | 260 | } |
| 263 | 261 | |
| 264 | 262 | if err = SaveListener(objAPI, bucketName, eventNames, pattern, target.ID(), *thisAddr); err != nil { |
| 265 | 263 | logger.GetReqInfo(ctx).AppendTags("target", target.ID().Name) |
| 266 | − logger.LogIf(ctx, err) | |
| 267 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 264 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 268 | 265 | return |
| 269 | 266 | } |
| 270 | 267 | |
| @@ -274,8 +271,7 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit · 3 unmodified lines | ||
| 274 | 271 | |
| 275 | 272 | if err = RemoveListener(objAPI, bucketName, target.ID(), *thisAddr); err != nil { |
| 276 | 273 | logger.GetReqInfo(ctx).AppendTags("target", target.ID().Name) |
| 277 | − logger.LogIf(ctx, err) | |
| 278 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 274 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 279 | 275 | return |
| 280 | 276 | } |
| 281 | 277 | } |
| @@ -58,7 +58,7 @@ func (api objectAPIHandlers) PutBucketPolicyHandler(w http.ResponseWriter, r *ht · 57 unmodified lines | ||
| 58 | 58 | |
| 59 | 59 | // Check if bucket exists. |
| 60 | 60 | if _, err := objAPI.GetBucketInfo(ctx, bucket); err != nil { |
| 61 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 61 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 62 | 62 | return |
| 63 | 63 | } |
| 64 | 64 | |
| @@ -88,7 +88,7 @@ func (api objectAPIHandlers) PutBucketPolicyHandler(w http.ResponseWriter, r *ht · 23 unmodified lines | ||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | if err = objAPI.SetBucketPolicy(ctx, bucket, bucketPolicy); err != nil { |
| 91 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 91 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 92 | 92 | return |
| 93 | 93 | } |
| 94 | 94 | |
| @@ -121,12 +121,12 @@ func (api objectAPIHandlers) DeleteBucketPolicyHandler(w http.ResponseWriter, r · 26 unmodified lines | ||
| 121 | 121 | |
| 122 | 122 | // Check if bucket exists. |
| 123 | 123 | if _, err := objAPI.GetBucketInfo(ctx, bucket); err != nil { |
| 124 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 124 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 125 | 125 | return |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if err := objAPI.DeleteBucketPolicy(ctx, bucket); err != nil { |
| 129 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 129 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 130 | 130 | return |
| 131 | 131 | } |
| 132 | 132 | |
| @@ -159,21 +159,20 @@ func (api objectAPIHandlers) GetBucketPolicyHandler(w http.ResponseWriter, r *ht · 26 unmodified lines | ||
| 159 | 159 | |
| 160 | 160 | // Check if bucket exists. |
| 161 | 161 | if _, err := objAPI.GetBucketInfo(ctx, bucket); err != nil { |
| 162 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 162 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 163 | 163 | return |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Read bucket access policy. |
| 167 | 167 | bucketPolicy, err := objAPI.GetBucketPolicy(ctx, bucket) |
| 168 | 168 | if err != nil { |
| 169 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 169 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 170 | 170 | return |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | policyData, err := json.Marshal(bucketPolicy) |
| 174 | 174 | if err != nil { |
| 175 | − logger.LogIf(ctx, err) | |
| 176 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 175 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 177 | 176 | return |
| 178 | 177 | } |
| 179 | 178 | |
| @@ -1062,7 +1062,7 @@ func DecryptCopyObjectInfo(info *ObjectInfo, headers http.Header) (apiErr APIErr · 1061 unmodified lines | ||
| 1062 | 1062 | } |
| 1063 | 1063 | var err error |
| 1064 | 1064 | if info.Size, err = info.DecryptedSize(); err != nil { |
| 1065 | − apiErr = toAPIErrorCode(err) | |
| 1065 | + apiErr = toAPIErrorCode(context.Background(), err) | |
| 1066 | 1066 | } |
| 1067 | 1067 | } |
| 1068 | 1068 | return |
| @@ -655,7 +655,7 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques · 654 unmodified lines | ||
| 655 | 655 | if err == dns.ErrNoEntriesFound { |
| 656 | 656 | writeErrorResponse(w, ErrNoSuchBucket, r.URL) |
| 657 | 657 | } else { |
| 658 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 658 | + writeErrorResponse(w, toAPIErrorCode(context.Background(), err), r.URL) | |
| 659 | 659 | } |
| 660 | 660 | return |
| 661 | 661 | } |
| @@ -124,7 +124,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r · 123 unmodified lines | ||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | _, err := getObjectInfo(ctx, bucket, object, ObjectOptions{}) |
| 127 | − if toAPIErrorCode(err) == ErrNoSuchKey { | |
| 127 | + if toAPIErrorCode(ctx, err) == ErrNoSuchKey { | |
| 128 | 128 | s3Error = ErrNoSuchKey |
| 129 | 129 | } |
| 130 | 130 | } |
| @@ -166,7 +166,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r · 35 unmodified lines | ||
| 166 | 166 | |
| 167 | 167 | gr, err := getObjectNInfo(ctx, bucket, object, nil, r.Header, readLock, ObjectOptions{}) |
| 168 | 168 | if err != nil { |
| 169 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 169 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 170 | 170 | return |
| 171 | 171 | } |
| 172 | 172 | defer gr.Close() |
| @@ -257,14 +257,14 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r · 84 unmodified lines | ||
| 257 | 257 | |
| 258 | 258 | s3s, err := s3select.New(reader, objInfo.GetActualSize(), selectReq) |
| 259 | 259 | if err != nil { |
| 260 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 260 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 261 | 261 | return |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // Parses the select query and checks for an error |
| 265 | 265 | _, _, _, _, _, _, err = s3select.ParseSelect(s3s) |
| 266 | 266 | if err != nil { |
| 267 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 267 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 268 | 268 | return |
| 269 | 269 | } |
| 270 | 270 | |
| @@ -343,7 +343,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req · 72 unmodified lines | ||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | _, err := getObjectInfo(ctx, bucket, object, opts) |
| 346 | − if toAPIErrorCode(err) == ErrNoSuchKey { | |
| 346 | + if toAPIErrorCode(ctx, err) == ErrNoSuchKey { | |
| 347 | 347 | s3Error = ErrNoSuchKey |
| 348 | 348 | } |
| 349 | 349 | } |
| @@ -377,7 +377,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req · 27 unmodified lines | ||
| 377 | 377 | |
| 378 | 378 | gr, err := getObjectNInfo(ctx, bucket, object, rs, r.Header, readLock, opts) |
| 379 | 379 | if err != nil { |
| 380 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 380 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 381 | 381 | return |
| 382 | 382 | } |
| 383 | 383 | defer gr.Close() |
| @@ -386,7 +386,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req · 2 unmodified lines | ||
| 386 | 386 | |
| 387 | 387 | if objectAPI.IsEncryptionSupported() { |
| 388 | 388 | if _, err = DecryptObjectInfo(objInfo, r.Header); err != nil { |
| 389 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 389 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 390 | 390 | return |
| 391 | 391 | } |
| 392 | 392 | } |
| @@ -409,8 +409,8 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req · 16 unmodified lines | ||
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | − if hErr := setObjectHeaders(w, objInfo, rs); hErr != nil { | |
| 413 | − writeErrorResponse(w, toAPIErrorCode(hErr), r.URL) | |
| 412 | + if err = setObjectHeaders(w, objInfo, rs); err != nil { | |
| 413 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 414 | 414 | return |
| 415 | 415 | } |
| 416 | 416 | |
| @@ -426,14 +426,14 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req · 9 unmodified lines | ||
| 426 | 426 | // Write object content to response body |
| 427 | 427 | if _, err = io.Copy(httpWriter, gr); err != nil { |
| 428 | 428 | if !httpWriter.HasWritten() && !statusCodeWritten { // write error response only if no data or headers has been written to client yet |
| 429 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 429 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 430 | 430 | } |
| 431 | 431 | return |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | if err = httpWriter.Close(); err != nil { |
| 435 | 435 | if !httpWriter.HasWritten() && !statusCodeWritten { // write error response only if no data or headers has been written to client yet |
| 436 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 436 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 437 | 437 | return |
| 438 | 438 | } |
| 439 | 439 | } |
| @@ -507,7 +507,7 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re · 67 unmodified lines | ||
| 507 | 507 | IsOwner: false, |
| 508 | 508 | }) { |
| 509 | 509 | _, err := getObjectInfo(ctx, bucket, object, opts) |
| 510 | − if toAPIErrorCode(err) == ErrNoSuchKey { | |
| 510 | + if toAPIErrorCode(ctx, err) == ErrNoSuchKey { | |
| 511 | 511 | s3Error = ErrNoSuchKey |
| 512 | 512 | } |
| 513 | 513 | } |
| @@ -536,13 +536,13 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re · 22 unmodified lines | ||
| 536 | 536 | |
| 537 | 537 | objInfo, err := getObjectInfo(ctx, bucket, object, opts) |
| 538 | 538 | if err != nil { |
| 539 | − writeErrorResponseHeadersOnly(w, toAPIErrorCode(err)) | |
| 539 | + writeErrorResponseHeadersOnly(w, toAPIErrorCode(ctx, err)) | |
| 540 | 540 | return |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | if objectAPI.IsEncryptionSupported() { |
| 544 | 544 | if _, err = DecryptObjectInfo(objInfo, r.Header); err != nil { |
| 545 | − writeErrorResponseHeadersOnly(w, toAPIErrorCode(err)) | |
| 545 | + writeErrorResponseHeadersOnly(w, toAPIErrorCode(ctx, err)) | |
| 546 | 546 | return |
| 547 | 547 | } |
| 548 | 548 | } |
| @@ -556,7 +556,7 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re · 7 unmodified lines | ||
| 556 | 556 | case crypto.SSEC.IsEncrypted(objInfo.UserDefined): |
| 557 | 557 | // Validate the SSE-C Key set in the header. |
| 558 | 558 | if _, err = crypto.SSEC.UnsealObjectKey(r.Header, objInfo.UserDefined, bucket, object); err != nil { |
| 559 | − writeErrorResponseHeadersOnly(w, toAPIErrorCode(err)) | |
| 559 | + writeErrorResponseHeadersOnly(w, toAPIErrorCode(ctx, err)) | |
| 560 | 560 | return |
| 561 | 561 | } |
| 562 | 562 | w.Header().Set(crypto.SSECAlgorithm, r.Header.Get(crypto.SSECAlgorithm)) |
| @@ -571,8 +571,8 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re · 8 unmodified lines | ||
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // Set standard object headers. |
| 574 | − if hErr := setObjectHeaders(w, objInfo, rs); hErr != nil { | |
| 575 | − writeErrorResponseHeadersOnly(w, toAPIErrorCode(hErr)) | |
| 574 | + if err = setObjectHeaders(w, objInfo, rs); err != nil { | |
| 575 | + writeErrorResponseHeadersOnly(w, toAPIErrorCode(ctx, err)) | |
| 576 | 576 | return |
| 577 | 577 | } |
| 578 | 578 | |
| @@ -716,7 +716,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 137 unmodified lines | ||
| 716 | 716 | var rs *HTTPRangeSpec |
| 717 | 717 | gr, err := getObjectNInfo(ctx, srcBucket, srcObject, rs, r.Header, lock, srcOpts) |
| 718 | 718 | if err != nil { |
| 719 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 719 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 720 | 720 | return |
| 721 | 721 | } |
| 722 | 722 | defer gr.Close() |
| @@ -758,7 +758,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 35 unmodified lines | ||
| 758 | 758 | if crypto.IsEncrypted(srcInfo.UserDefined) { |
| 759 | 759 | actualSize, err = srcInfo.DecryptedSize() |
| 760 | 760 | if err != nil { |
| 761 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 761 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 762 | 762 | return |
| 763 | 763 | } |
| 764 | 764 | } |
| @@ -797,7 +797,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 32 unmodified lines | ||
| 797 | 797 | |
| 798 | 798 | srcInfo.Reader, err = hash.NewReader(reader, length, "", "", actualSize) |
| 799 | 799 | if err != nil { |
| 800 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 800 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 801 | 801 | return |
| 802 | 802 | } |
| 803 | 803 | |
| @@ -805,7 +805,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 1 unmodified line | ||
| 805 | 805 | if objectAPI.IsEncryptionSupported() && !isCompressed { |
| 806 | 806 | // Encryption parameters not applicable for this object. |
| 807 | 807 | if !crypto.IsEncrypted(srcInfo.UserDefined) && crypto.SSECopy.IsRequested(r.Header) { |
| 808 | − writeErrorResponse(w, toAPIErrorCode(errInvalidEncryptionParameters), r.URL) | |
| 808 | + writeErrorResponse(w, toAPIErrorCode(ctx, errInvalidEncryptionParameters), r.URL) | |
| 809 | 809 | return |
| 810 | 810 | } |
| 811 | 811 | // Encryption parameters not present for this object. |
| @@ -825,7 +825,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 13 unmodified lines | ||
| 825 | 825 | if sseC { |
| 826 | 826 | newKey, err = ParseSSECustomerRequest(r) |
| 827 | 827 | if err != nil { |
| 828 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 828 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 829 | 829 | return |
| 830 | 830 | } |
| 831 | 831 | } |
| @@ -838,7 +838,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 6 unmodified lines | ||
| 838 | 838 | if sseCopyC && sseC { |
| 839 | 839 | oldKey, err = ParseSSECopyCustomerRequest(r.Header, srcInfo.UserDefined) |
| 840 | 840 | if err != nil { |
| 841 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 841 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 842 | 842 | return |
| 843 | 843 | } |
| 844 | 844 | } |
| @@ -848,7 +848,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 3 unmodified lines | ||
| 848 | 848 | |
| 849 | 849 | // In case of SSE-S3 oldKey and newKey aren't used - the KMS manages the keys. |
| 850 | 850 | if err = rotateKey(oldKey, newKey, srcBucket, srcObject, encMetadata); err != nil { |
| 851 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 851 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 852 | 852 | return |
| 853 | 853 | } |
| 854 | 854 | |
| @@ -880,7 +880,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 25 unmodified lines | ||
| 880 | 880 | if isTargetEncrypted { |
| 881 | 881 | reader, err = newEncryptReader(reader, newKey, dstBucket, dstObject, encMetadata, sseS3) |
| 882 | 882 | if err != nil { |
| 883 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 883 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 884 | 884 | return |
| 885 | 885 | } |
| 886 | 886 | } |
| @@ -893,7 +893,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 6 unmodified lines | ||
| 893 | 893 | |
| 894 | 894 | srcInfo.Reader, err = hash.NewReader(reader, targetSize, "", "", targetSize) // do not try to verify encrypted content |
| 895 | 895 | if err != nil { |
| 896 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 896 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 897 | 897 | return |
| 898 | 898 | } |
| 899 | 899 | } |
| @@ -966,7 +966,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re · 66 unmodified lines | ||
| 966 | 966 | // object is same then only metadata is updated. |
| 967 | 967 | objInfo, err = objectAPI.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo, srcOpts, dstOpts) |
| 968 | 968 | if err != nil { |
| 969 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 969 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 970 | 970 | return |
| 971 | 971 | } |
| 972 | 972 | } |
| @@ -1059,7 +1059,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req · 86 unmodified lines | ||
| 1059 | 1059 | } |
| 1060 | 1060 | size, err = strconv.ParseInt(sizeStr[0], 10, 64) |
| 1061 | 1061 | if err != nil { |
| 1062 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1062 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1063 | 1063 | return |
| 1064 | 1064 | } |
| 1065 | 1065 | } |
| @@ -1154,7 +1154,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req · 88 unmodified lines | ||
| 1154 | 1154 | var actualReader *hash.Reader |
| 1155 | 1155 | actualReader, err = hash.NewReader(reader, size, md5hex, sha256hex, actualSize) |
| 1156 | 1156 | if err != nil { |
| 1157 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1157 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1158 | 1158 | return |
| 1159 | 1159 | } |
| 1160 | 1160 | |
| @@ -1174,7 +1174,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req · 13 unmodified lines | ||
| 1174 | 1174 | |
| 1175 | 1175 | hashReader, err := hash.NewReader(reader, size, md5hex, sha256hex, actualSize) |
| 1176 | 1176 | if err != nil { |
| 1177 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1177 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1178 | 1178 | return |
| 1179 | 1179 | } |
| 1180 | 1180 | opts := ObjectOptions{} |
| @@ -1190,13 +1190,13 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req · 9 unmodified lines | ||
| 1190 | 1190 | if hasServerSideEncryptionHeader(r.Header) && !hasSuffix(object, slashSeparator) { // handle SSE requests |
| 1191 | 1191 | reader, err = EncryptRequest(hashReader, r, bucket, object, metadata) |
| 1192 | 1192 | if err != nil { |
| 1193 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1193 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1194 | 1194 | return |
| 1195 | 1195 | } |
| 1196 | 1196 | info := ObjectInfo{Size: size} |
| 1197 | 1197 | hashReader, err = hash.NewReader(reader, info.EncryptedSize(), "", "", size) // do not try to verify encrypted content |
| 1198 | 1198 | if err != nil { |
| 1199 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1199 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1200 | 1200 | return |
| 1201 | 1201 | } |
| 1202 | 1202 | } |
| @@ -1212,7 +1212,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req · 9 unmodified lines | ||
| 1212 | 1212 | // Create the object.. |
| 1213 | 1213 | objInfo, err := putObject(ctx, bucket, object, hashReader, metadata, opts) |
| 1214 | 1214 | if err != nil { |
| 1215 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1215 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1216 | 1216 | return |
| 1217 | 1217 | } |
| 1218 | 1218 | |
| @@ -1309,7 +1309,7 @@ func (api objectAPIHandlers) NewMultipartUploadHandler(w http.ResponseWriter, r · 90 unmodified lines | ||
| 1309 | 1309 | if objectAPI.IsEncryptionSupported() { |
| 1310 | 1310 | if hasServerSideEncryptionHeader(r.Header) { |
| 1311 | 1311 | if err := setEncryptionMetadata(r, bucket, object, encMetadata); err != nil { |
| 1312 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1312 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1313 | 1313 | return |
| 1314 | 1314 | } |
| 1315 | 1315 | // Set this for multipart only operations, we need to differentiate during |
| @@ -1345,7 +1345,7 @@ func (api objectAPIHandlers) NewMultipartUploadHandler(w http.ResponseWriter, r · 29 unmodified lines | ||
| 1345 | 1345 | } |
| 1346 | 1346 | uploadID, err := newMultipartUpload(ctx, bucket, object, metadata, opts) |
| 1347 | 1347 | if err != nil { |
| 1348 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1348 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1349 | 1349 | return |
| 1350 | 1350 | } |
| 1351 | 1351 | |
| @@ -1447,7 +1447,7 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 95 unmodified lines | ||
| 1447 | 1447 | |
| 1448 | 1448 | gr, err := getObjectNInfo(ctx, srcBucket, srcObject, rs, r.Header, readLock, srcOpts) |
| 1449 | 1449 | if err != nil { |
| 1450 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1450 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1451 | 1451 | return |
| 1452 | 1452 | } |
| 1453 | 1453 | defer gr.Close() |
| @@ -1457,7 +1457,7 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 3 unmodified lines | ||
| 1457 | 1457 | if crypto.IsEncrypted(srcInfo.UserDefined) { |
| 1458 | 1458 | actualPartSize, err = srcInfo.DecryptedSize() |
| 1459 | 1459 | if err != nil { |
| 1460 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1460 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1461 | 1461 | return |
| 1462 | 1462 | } |
| 1463 | 1463 | } |
| @@ -1476,7 +1476,7 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 12 unmodified lines | ||
| 1476 | 1476 | // Get the object offset & length |
| 1477 | 1477 | startOffset, length, err := rs.GetOffsetLength(actualPartSize) |
| 1478 | 1478 | if err != nil { |
| 1479 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1479 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1480 | 1480 | return |
| 1481 | 1481 | } |
| 1482 | 1482 | |
| @@ -1492,7 +1492,7 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 9 unmodified lines | ||
| 1492 | 1492 | var li ListPartsInfo |
| 1493 | 1493 | li, err = objectAPI.ListObjectParts(ctx, dstBucket, dstObject, uploadID, 0, 1) |
| 1494 | 1494 | if err != nil { |
| 1495 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1495 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1496 | 1496 | return |
| 1497 | 1497 | } |
| 1498 | 1498 | |
| @@ -1522,7 +1522,7 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 23 unmodified lines | ||
| 1522 | 1522 | |
| 1523 | 1523 | srcInfo.Reader, err = hash.NewReader(reader, length, "", "", actualPartSize) |
| 1524 | 1524 | if err != nil { |
| 1525 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1525 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1526 | 1526 | return |
| 1527 | 1527 | } |
| 1528 | 1528 | |
| @@ -1540,14 +1540,14 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 11 unmodified lines | ||
| 1540 | 1540 | if crypto.SSEC.IsRequested(r.Header) { |
| 1541 | 1541 | key, err = ParseSSECustomerRequest(r) |
| 1542 | 1542 | if err != nil { |
| 1543 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1543 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1544 | 1544 | return |
| 1545 | 1545 | } |
| 1546 | 1546 | } |
| 1547 | 1547 | var objectEncryptionKey []byte |
| 1548 | 1548 | objectEncryptionKey, err = decryptObjectInfo(key, dstBucket, dstObject, li.UserDefined) |
| 1549 | 1549 | if err != nil { |
| 1550 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1550 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1551 | 1551 | return |
| 1552 | 1552 | } |
| 1553 | 1553 | |
| @@ -1559,14 +1559,14 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 5 unmodified lines | ||
| 1559 | 1559 | partEncryptionKey := mac.Sum(nil) |
| 1560 | 1560 | reader, err = sio.EncryptReader(reader, sio.Config{Key: partEncryptionKey}) |
| 1561 | 1561 | if err != nil { |
| 1562 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1562 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1563 | 1563 | return |
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | 1566 | info := ObjectInfo{Size: length} |
| 1567 | 1567 | srcInfo.Reader, err = hash.NewReader(reader, info.EncryptedSize(), "", "", length) |
| 1568 | 1568 | if err != nil { |
| 1569 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1569 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1570 | 1570 | return |
| 1571 | 1571 | } |
| 1572 | 1572 | } |
| @@ -1577,7 +1577,7 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt · 4 unmodified lines | ||
| 1577 | 1577 | partInfo, err := objectAPI.CopyObjectPart(ctx, srcBucket, srcObject, dstBucket, dstObject, uploadID, partID, |
| 1578 | 1578 | startOffset, length, srcInfo, srcOpts, dstOpts) |
| 1579 | 1579 | if err != nil { |
| 1580 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1580 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1581 | 1581 | return |
| 1582 | 1582 | } |
| 1583 | 1583 | |
| @@ -1634,7 +1634,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 50 unmodified lines | ||
| 1634 | 1634 | } |
| 1635 | 1635 | size, err = strconv.ParseInt(sizeStr[0], 10, 64) |
| 1636 | 1636 | if err != nil { |
| 1637 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1637 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1638 | 1638 | return |
| 1639 | 1639 | } |
| 1640 | 1640 | } |
| @@ -1709,7 +1709,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 68 unmodified lines | ||
| 1709 | 1709 | var li ListPartsInfo |
| 1710 | 1710 | li, err = objectAPI.ListObjectParts(ctx, bucket, object, uploadID, 0, 1) |
| 1711 | 1711 | if err != nil { |
| 1712 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1712 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1713 | 1713 | return |
| 1714 | 1714 | } |
| 1715 | 1715 | // Read compression metadata preserved in the init multipart for the decision. |
| @@ -1723,7 +1723,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 7 unmodified lines | ||
| 1723 | 1723 | var actualReader *hash.Reader |
| 1724 | 1724 | actualReader, err = hash.NewReader(reader, size, md5hex, sha256hex, actualSize) |
| 1725 | 1725 | if err != nil { |
| 1726 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1726 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1727 | 1727 | return |
| 1728 | 1728 | } |
| 1729 | 1729 | |
| @@ -1744,7 +1744,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 14 unmodified lines | ||
| 1744 | 1744 | |
| 1745 | 1745 | hashReader, err := hash.NewReader(reader, size, md5hex, sha256hex, actualSize) |
| 1746 | 1746 | if err != nil { |
| 1747 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1747 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1748 | 1748 | return |
| 1749 | 1749 | } |
| 1750 | 1750 | |
| @@ -1762,7 +1762,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 11 unmodified lines | ||
| 1762 | 1762 | var li ListPartsInfo |
| 1763 | 1763 | li, err = objectAPI.ListObjectParts(ctx, bucket, object, uploadID, 0, 1) |
| 1764 | 1764 | if err != nil { |
| 1765 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1765 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1766 | 1766 | return |
| 1767 | 1767 | } |
| 1768 | 1768 | if crypto.IsEncrypted(li.UserDefined) { |
| @@ -1775,7 +1775,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 6 unmodified lines | ||
| 1775 | 1775 | if crypto.SSEC.IsRequested(r.Header) { |
| 1776 | 1776 | key, err = ParseSSECustomerRequest(r) |
| 1777 | 1777 | if err != nil { |
| 1778 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1778 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1779 | 1779 | return |
| 1780 | 1780 | } |
| 1781 | 1781 | } |
| @@ -1784,7 +1784,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 2 unmodified lines | ||
| 1784 | 1784 | var objectEncryptionKey []byte |
| 1785 | 1785 | objectEncryptionKey, err = decryptObjectInfo(key, bucket, object, li.UserDefined) |
| 1786 | 1786 | if err != nil { |
| 1787 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1787 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1788 | 1788 | return |
| 1789 | 1789 | } |
| 1790 | 1790 | |
| @@ -1797,14 +1797,14 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 6 unmodified lines | ||
| 1797 | 1797 | |
| 1798 | 1798 | reader, err = sio.EncryptReader(hashReader, sio.Config{Key: partEncryptionKey}) |
| 1799 | 1799 | if err != nil { |
| 1800 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1800 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1801 | 1801 | return |
| 1802 | 1802 | } |
| 1803 | 1803 | |
| 1804 | 1804 | info := ObjectInfo{Size: size} |
| 1805 | 1805 | hashReader, err = hash.NewReader(reader, info.EncryptedSize(), "", "", size) // do not try to verify encrypted content |
| 1806 | 1806 | if err != nil { |
| 1807 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1807 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1808 | 1808 | return |
| 1809 | 1809 | } |
| 1810 | 1810 | } |
| @@ -1817,7 +1817,7 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http · 6 unmodified lines | ||
| 1817 | 1817 | partInfo, err := putObjectPart(ctx, bucket, object, uploadID, partID, hashReader, opts) |
| 1818 | 1818 | if err != nil { |
| 1819 | 1819 | // Verify if the underlying error is signature mismatch. |
| 1820 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1820 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1821 | 1821 | return |
| 1822 | 1822 | } |
| 1823 | 1823 | if isCompressed { |
| @@ -1871,7 +1871,7 @@ func (api objectAPIHandlers) AbortMultipartUploadHandler(w http.ResponseWriter, · 47 unmodified lines | ||
| 1871 | 1871 | return |
| 1872 | 1872 | } |
| 1873 | 1873 | if err := abortMultipartUpload(ctx, bucket, object, uploadID); err != nil { |
| 1874 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1874 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1875 | 1875 | return |
| 1876 | 1876 | } |
| 1877 | 1877 | |
| @@ -1914,7 +1914,7 @@ func (api objectAPIHandlers) ListObjectPartsHandler(w http.ResponseWriter, r *ht · 36 unmodified lines | ||
| 1914 | 1914 | } |
| 1915 | 1915 | listPartsInfo, err := objectAPI.ListObjectParts(ctx, bucket, object, uploadID, partNumberMarker, maxParts) |
| 1916 | 1916 | if err != nil { |
| 1917 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 1917 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 1918 | 1918 | return |
| 1919 | 1919 | } |
| 1920 | 1920 | response := generateListPartsResponse(listPartsInfo) |
| @@ -2003,7 +2003,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite · 82 unmodified lines | ||
| 2003 | 2003 | writePartSmallErrorResponse(w, r, oErr) |
| 2004 | 2004 | default: |
| 2005 | 2005 | // Handle all other generic issues. |
| 2006 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 2006 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 2007 | 2007 | } |
| 2008 | 2008 | return |
| 2009 | 2009 | } |
| @@ -2080,7 +2080,7 @@ func (api objectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http. · 70 unmodified lines | ||
| 2080 | 2080 | if err == dns.ErrNoEntriesFound { |
| 2081 | 2081 | writeErrorResponse(w, ErrNoSuchBucket, r.URL) |
| 2082 | 2082 | } else { |
| 2083 | − writeErrorResponse(w, toAPIErrorCode(err), r.URL) | |
| 2083 | + writeErrorResponse(w, toAPIErrorCode(ctx, err), r.URL) | |
| 2084 | 2084 | } |
| 2085 | 2085 | return |
| 2086 | 2086 | } |
| @@ -2088,7 +2088,7 @@ func (api objectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http. · 1 unmodified line | ||
| 2088 | 2088 | |
| 2089 | 2089 | // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectDELETE.html |
| 2090 | 2090 | if err := deleteObject(ctx, objectAPI, api.CacheAPI(), bucket, object, r); err != nil { |
| 2091 | − switch toAPIErrorCode(err) { | |
| 2091 | + switch toAPIErrorCode(ctx, err) { | |
| 2092 | 2092 | case ErrNoSuchBucket: |
| 2093 | 2093 | // When bucket doesn't exist specially handle it. |
| 2094 | 2094 | writeErrorResponse(w, ErrNoSuchBucket, r.URL) |
| @@ -2533,6 +2533,8 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s · 2532 unmodified lines | ||
| 2533 | 2533 | successResponse := generateCompleteMultpartUploadResponse(bucketName, objectName, getGetObjectURL("", bucketName, objectName), s3MD5) |
| 2534 | 2534 | encodedSuccessResponse := encodeResponse(successResponse) |
| 2535 | 2535 | |
| 2536 | + ctx := context.Background() | |
| 2537 | + | |
| 2536 | 2538 | testCases := []struct { |
| 2537 | 2539 | bucket string |
| 2538 | 2540 | object string |
| @@ -2555,7 +2557,7 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s · 16 unmodified lines | ||
| 2555 | 2557 | accessKey: credentials.AccessKey, |
| 2556 | 2558 | secretKey: credentials.SecretKey, |
| 2557 | 2559 | |
| 2558 | − expectedContent: encodeResponse(getAPIErrorResponse(getAPIError(toAPIErrorCode(InvalidPart{})), | |
| 2560 | + expectedContent: encodeResponse(getAPIErrorResponse(getAPIError(toAPIErrorCode(ctx, InvalidPart{})), | |
| 2559 | 2561 | getGetObjectURL("", bucketName, objectName), "")), |
| 2560 | 2562 | expectedRespStatus: http.StatusBadRequest, |
| 2561 | 2563 | }, |
| @@ -2585,7 +2587,7 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s · 23 unmodified lines | ||
| 2585 | 2587 | accessKey: credentials.AccessKey, |
| 2586 | 2588 | secretKey: credentials.SecretKey, |
| 2587 | 2589 | |
| 2588 | − expectedContent: encodeResponse(getAPIErrorResponse(getAPIError(toAPIErrorCode(InvalidUploadID{UploadID: "abc"})), | |
| 2590 | + expectedContent: encodeResponse(getAPIErrorResponse(getAPIError(toAPIErrorCode(ctx, InvalidUploadID{UploadID: "abc"})), | |
| 2589 | 2591 | getGetObjectURL("", bucketName, objectName), "")), |
| 2590 | 2592 | expectedRespStatus: http.StatusNotFound, |
| 2591 | 2593 | }, |
| @@ -2600,7 +2602,7 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s · 8 unmodified lines | ||
| 2600 | 2602 | secretKey: credentials.SecretKey, |
| 2601 | 2603 | |
| 2602 | 2604 | expectedContent: encodeResponse(completeMultipartAPIError{int64(4), int64(5242880), 1, "e2fc714c4727ee9395f324cd2e7f331f", |
| 2603 | − getAPIErrorResponse(getAPIError(toAPIErrorCode(PartTooSmall{PartNumber: 1})), | |
| 2605 | + getAPIErrorResponse(getAPIError(toAPIErrorCode(ctx, PartTooSmall{PartNumber: 1})), | |
| 2604 | 2606 | getGetObjectURL("", bucketName, objectName), "")}), |
| 2605 | 2607 | expectedRespStatus: http.StatusBadRequest, |
| 2606 | 2608 | }, |
| @@ -2614,7 +2616,7 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s · 7 unmodified lines | ||
| 2614 | 2616 | accessKey: credentials.AccessKey, |
| 2615 | 2617 | secretKey: credentials.SecretKey, |
| 2616 | 2618 | |
| 2617 | − expectedContent: encodeResponse(getAPIErrorResponse(getAPIError(toAPIErrorCode(InvalidPart{})), | |
| 2619 | + expectedContent: encodeResponse(getAPIErrorResponse(getAPIError(toAPIErrorCode(ctx, InvalidPart{})), | |
| 2618 | 2620 | getGetObjectURL("", bucketName, objectName), "")), |
| 2619 | 2621 | expectedRespStatus: http.StatusBadRequest, |
| 2620 | 2622 | }, |
| @@ -2354,8 +2354,9 @@ func TestToErrIsNil(t *testing.T) { · 2353 unmodified lines | ||
| 2354 | 2354 | if toStorageErr(nil) != nil { |
| 2355 | 2355 | t.Errorf("Test expected to return nil, failed instead got a non-nil value %s", toStorageErr(nil)) |
| 2356 | 2356 | } |
| 2357 | − if toAPIErrorCode(nil) != ErrNone { | |
| 2358 | − t.Errorf("Test expected error code to be ErrNone, failed instead provided %d", toAPIErrorCode(nil)) | |
| 2357 | + ctx := context.Background() | |
| 2358 | + if toAPIErrorCode(ctx, nil) != ErrNone { | |
| 2359 | + t.Errorf("Test expected error code to be ErrNone, failed instead provided %d", toAPIErrorCode(ctx, nil)) | |
| 2359 | 2360 | } |
| 2360 | 2361 | } |
| 2361 | 2362 | |