mirror of
https://github.com/minio/minio.git
synced 2024-12-27 23:55:56 -05:00
Merge pull request #558 from harshavardhana/pr_out_even_mux_vars_don_t_help_handle_it_by_looking_at_req_url_path
This commit is contained in:
commit
1f3dd2374c
@ -30,7 +30,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/minio-io/minio/pkg/api/config"
|
"github.com/minio-io/minio/pkg/api/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -169,14 +168,30 @@ var subResList = []string{
|
|||||||
"website",
|
"website",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func url2BucketAndObject(url string) (string, string) {
|
||||||
|
var bucketName, objectName string
|
||||||
|
splits := strings.SplitN(url, "/", 3)
|
||||||
|
switch len(splits) {
|
||||||
|
case 0, 1:
|
||||||
|
bucketName = ""
|
||||||
|
objectName = ""
|
||||||
|
case 2:
|
||||||
|
bucketName = splits[1]
|
||||||
|
objectName = ""
|
||||||
|
case 3:
|
||||||
|
bucketName = splits[1]
|
||||||
|
objectName = splits[2]
|
||||||
|
}
|
||||||
|
return bucketName, objectName
|
||||||
|
}
|
||||||
|
|
||||||
// From the Amazon docs:
|
// From the Amazon docs:
|
||||||
//
|
//
|
||||||
// CanonicalizedResource = [ "/" + Bucket ] +
|
// CanonicalizedResource = [ "/" + Bucket ] +
|
||||||
// <HTTP-Request-URI, from the protocol name up to the query string> +
|
// <HTTP-Request-URI, from the protocol name up to the query string> +
|
||||||
// [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"];
|
// [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"];
|
||||||
func writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request) {
|
func writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request) {
|
||||||
vars := mux.Vars(req)
|
bucket, _ := url2BucketAndObject(req.URL.Path)
|
||||||
bucket := vars["bucket"]
|
|
||||||
if bucket != "" {
|
if bucket != "" {
|
||||||
buf.WriteByte('/')
|
buf.WriteByte('/')
|
||||||
buf.WriteString(bucket)
|
buf.WriteString(bucket)
|
||||||
|
@ -113,17 +113,18 @@ func (s *MySuite) TearDownTest(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setAuthHeader(req *http.Request) {
|
func setAuthHeader(req *http.Request) {
|
||||||
|
if date := req.Header.Get("Date"); date == "" {
|
||||||
|
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
|
||||||
|
}
|
||||||
hm := hmac.New(sha1.New, []byte("H+AVh8q5G7hEH2r3WxFP135+Q19Aw8yXWel8IGh/HrEjZyTNx/n4Xw=="))
|
hm := hmac.New(sha1.New, []byte("H+AVh8q5G7hEH2r3WxFP135+Q19Aw8yXWel8IGh/HrEjZyTNx/n4Xw=="))
|
||||||
ss := getStringToSign(req)
|
ss := getStringToSign(req)
|
||||||
io.WriteString(hm, ss)
|
io.WriteString(hm, ss)
|
||||||
|
|
||||||
authHeader := new(bytes.Buffer)
|
authHeader := new(bytes.Buffer)
|
||||||
fmt.Fprintf(authHeader, "AWS %s:", "AC5NH40NQLTL4D2W92PM")
|
fmt.Fprintf(authHeader, "AWS %s:", "AC5NH40NQLTL4D2W92PM")
|
||||||
encoder := base64.NewEncoder(base64.StdEncoding, authHeader)
|
encoder := base64.NewEncoder(base64.StdEncoding, authHeader)
|
||||||
encoder.Write(hm.Sum(nil))
|
encoder.Write(hm.Sum(nil))
|
||||||
encoder.Close()
|
encoder.Close()
|
||||||
req.Header.Set("Authorization", authHeader.String())
|
req.Header.Set("Authorization", authHeader.String())
|
||||||
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestNonExistantBucket(c *C) {
|
func (s *MySuite) TestNonExistantBucket(c *C) {
|
||||||
|
Loading…
Reference in New Issue
Block a user