-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse error responses for STS requests (#1602)
provide more descriptive error messages to the caller instead of just HTTP status
- Loading branch information
1 parent
52ffedf
commit 2ef8cbb
Showing
8 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* MinIO Go Library for Amazon S3 Compatible Cloud Storage | ||
* Copyright 2021 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package credentials | ||
|
||
import ( | ||
"bytes" | ||
"encoding/xml" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
) | ||
|
||
// ErrorResponse - Is the typed error returned. | ||
// ErrorResponse struct should be comparable since it is compared inside | ||
// golang http API (https://github.com/golang/go/issues/29768) | ||
type ErrorResponse struct { | ||
XMLName xml.Name `xml:"Error" json:"-"` | ||
Code string | ||
Message string | ||
RequestID string `xml:"RequestId"` | ||
HostID string `xml:"HostId"` | ||
|
||
// Region where the bucket is located. This header is returned | ||
// only in HEAD bucket and ListObjects response. | ||
Region string | ||
|
||
// Captures the server string returned in response header. | ||
Server string | ||
|
||
// Underlying HTTP status code for the returned error | ||
StatusCode int `xml:"-" json:"-"` | ||
} | ||
|
||
// Error - Returns STS error string. | ||
func (e ErrorResponse) Error() string { | ||
if e.Message == "" { | ||
return fmt.Sprintf("Error response code %s.", e.Code) | ||
} | ||
return e.Message | ||
} | ||
|
||
// xmlDecoder provide decoded value in xml. | ||
func xmlDecoder(body io.Reader, v interface{}) error { | ||
d := xml.NewDecoder(body) | ||
return d.Decode(v) | ||
} | ||
|
||
// xmlDecodeAndBody reads the whole body up to 1MB and | ||
// tries to XML decode it into v. | ||
// The body that was read and any error from reading or decoding is returned. | ||
func xmlDecodeAndBody(bodyReader io.Reader, v interface{}) ([]byte, error) { | ||
// read the whole body (up to 1MB) | ||
const maxBodyLength = 1 << 20 | ||
body, err := ioutil.ReadAll(io.LimitReader(bodyReader, maxBodyLength)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return bytes.TrimSpace(body), xmlDecoder(bytes.NewReader(body), v) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters