Fix: Add X-Amz-Security-Token to presigned url (#4)
Include the x-amz-security-token if signed with temporary credentials. Ref:https://stackoverflow.com/questions/49306621/how-secret-is-the-session-token-in-aws-temporary-security-credentials/49344291#49344291
This commit is contained in:
+11
@@ -30,6 +30,7 @@ type S3 struct {
|
||||
Region string
|
||||
Client *http.Client
|
||||
|
||||
Token string
|
||||
Endpoint string
|
||||
URIFormat string
|
||||
}
|
||||
@@ -139,6 +140,7 @@ func newUsingIAMImpl(baseURL, region string) (*S3, error) {
|
||||
Region: region,
|
||||
AccessKey: jsonResp.AccessKeyID,
|
||||
SecretKey: jsonResp.SecretAccessKey,
|
||||
Token: jsonResp.Token,
|
||||
|
||||
URIFormat: "https://s3.%s.amazonaws.com/%s",
|
||||
}, nil
|
||||
@@ -173,6 +175,15 @@ func (s3 *S3) SetEndpoint(uri string) *S3 {
|
||||
return s3
|
||||
}
|
||||
|
||||
// SetToken can be used to set a Temporary Security Credential token obtained from
|
||||
// using an IAM role or AWS STS.
|
||||
func (s3 *S3) SetToken(token string) *S3 {
|
||||
if token != "" {
|
||||
s3.Token = token
|
||||
}
|
||||
return s3
|
||||
}
|
||||
|
||||
func detectFileSize(body io.Seeker) (int64, error) {
|
||||
pos, err := body.Seek(0, 1)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user