benchmark can work in secure mode
This commit is contained in:
@@ -3,9 +3,12 @@ package operation
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/security"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
)
|
||||
|
||||
type VolumeAssignRequest struct {
|
||||
@@ -19,11 +22,12 @@ type VolumeAssignRequest struct {
|
||||
}
|
||||
|
||||
type AssignResult struct {
|
||||
Fid string `json:"fid,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
PublicUrl string `json:"publicUrl,omitempty"`
|
||||
Count uint64 `json:"count,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Fid string `json:"fid,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
PublicUrl string `json:"publicUrl,omitempty"`
|
||||
Count uint64 `json:"count,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Auth security.EncodedJwt `json:"auth,omitempty"`
|
||||
}
|
||||
|
||||
func Assign(server string, primaryRequest *VolumeAssignRequest, alternativeRequests ...*VolumeAssignRequest) (*AssignResult, error) {
|
||||
@@ -63,6 +67,7 @@ func Assign(server string, primaryRequest *VolumeAssignRequest, alternativeReque
|
||||
ret.Url = resp.Url
|
||||
ret.PublicUrl = resp.PublicUrl
|
||||
ret.Error = resp.Error
|
||||
ret.Auth = security.EncodedJwt(resp.Auth)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -81,3 +86,17 @@ func Assign(server string, primaryRequest *VolumeAssignRequest, alternativeReque
|
||||
|
||||
return ret, lastError
|
||||
}
|
||||
|
||||
func LookupJwt(master string, fileId string) security.EncodedJwt {
|
||||
|
||||
tokenStr := ""
|
||||
|
||||
if h, e := util.Head(fmt.Sprintf("http://%s/dir/lookup?fileId=%s", master, fileId)); e == nil {
|
||||
bearer := h.Get("Authorization")
|
||||
if len(bearer) > 7 && strings.ToUpper(bearer[0:6]) == "BEARER" {
|
||||
tokenStr = bearer[7:]
|
||||
}
|
||||
}
|
||||
|
||||
return security.EncodedJwt(tokenStr)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func DeleteFilesWithLookupVolumeId(fileIds []string, lookupFunc func(vid []strin
|
||||
vid, _, err := ParseFileId(fileId)
|
||||
if err != nil {
|
||||
ret = append(ret, &volume_server_pb.DeleteResult{
|
||||
FileId: vid,
|
||||
FileId: fileId,
|
||||
Status: http.StatusBadRequest,
|
||||
Error: err.Error()},
|
||||
)
|
||||
|
||||
@@ -65,7 +65,7 @@ func SubmitFiles(master string, files []FilePart,
|
||||
file.Replication = replication
|
||||
file.Collection = collection
|
||||
file.DataCenter = dataCenter
|
||||
results[index].Size, err = file.Upload(maxMB, master, "")
|
||||
results[index].Size, err = file.Upload(maxMB, master, ret.Auth)
|
||||
if err != nil {
|
||||
results[index].Error = err.Error()
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (fi FilePart) Upload(maxMB int, master string, jwt security.EncodedJwt) (re
|
||||
baseName+"-"+strconv.FormatInt(i+1, 10),
|
||||
io.LimitReader(fi.Reader, chunkSize),
|
||||
master, fileUrl,
|
||||
jwt)
|
||||
ret.Auth)
|
||||
if e != nil {
|
||||
// delete all uploaded chunks
|
||||
cm.DeleteChunks(master)
|
||||
|
||||
@@ -58,9 +58,6 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
|
||||
if isGzipped {
|
||||
h.Set("Content-Encoding", "gzip")
|
||||
}
|
||||
if jwt != "" {
|
||||
h.Set("Authorization", "BEARER "+string(jwt))
|
||||
}
|
||||
|
||||
file_writer, cp_err := body_writer.CreatePart(h)
|
||||
if cp_err != nil {
|
||||
@@ -86,6 +83,9 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error
|
||||
for k, v := range pairMap {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
if jwt != "" {
|
||||
req.Header.Set("Authorization", "BEARER "+string(jwt))
|
||||
}
|
||||
resp, post_err := client.Do(req)
|
||||
if post_err != nil {
|
||||
glog.V(0).Infoln("failing to upload to", uploadUrl, post_err.Error())
|
||||
|
||||
Reference in New Issue
Block a user