aboutsummaryrefslogtreecommitdiff
path: root/weed/operation/assign_file_id.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-08-12 21:40:33 -0700
committerChris Lu <chris.lu@gmail.com>2021-08-12 21:40:33 -0700
commit5a0f92423eb4f89d35b245b1913eb7ba60436742 (patch)
tree433a3ce97451c9800089b8d87abc09480c0dcf78 /weed/operation/assign_file_id.go
parent6238644c35fc5dafcc4eb1722b3d5c9b92c0b031 (diff)
downloadseaweedfs-5a0f92423eb4f89d35b245b1913eb7ba60436742.tar.xz
seaweedfs-5a0f92423eb4f89d35b245b1913eb7ba60436742.zip
use grpc and jwt
Diffstat (limited to 'weed/operation/assign_file_id.go')
-rw-r--r--weed/operation/assign_file_id.go29
1 files changed, 18 insertions, 11 deletions
diff --git a/weed/operation/assign_file_id.go b/weed/operation/assign_file_id.go
index fabc820ff..f441dcb50 100644
--- a/weed/operation/assign_file_id.go
+++ b/weed/operation/assign_file_id.go
@@ -3,14 +3,11 @@ package operation
import (
"context"
"fmt"
- "strings"
-
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"google.golang.org/grpc"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"github.com/chrislusf/seaweedfs/weed/security"
- "github.com/chrislusf/seaweedfs/weed/util"
)
type VolumeAssignRequest struct {
@@ -96,18 +93,28 @@ func Assign(masterFn GetMasterFn, grpcDialOption grpc.DialOption, primaryRequest
return ret, lastError
}
-func LookupJwt(master string, fileId string) security.EncodedJwt {
+func LookupJwt(master string, grpcDialOption grpc.DialOption, fileId string) (token security.EncodedJwt) {
- tokenStr := ""
+ WithMasterServerClient(master, grpcDialOption, func(masterClient master_pb.SeaweedClient) error {
- 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:]
+ resp, grpcErr := masterClient.LookupVolume(context.Background(), &master_pb.LookupVolumeRequest{
+ VolumeOrFileIds: []string{fileId},
+ })
+ if grpcErr != nil {
+ return grpcErr
}
- }
- return security.EncodedJwt(tokenStr)
+ if len(resp.VolumeIdLocations) == 0 {
+ return nil
+ }
+
+ token = security.EncodedJwt(resp.VolumeIdLocations[0].Auth)
+
+ return nil
+
+ })
+
+ return
}
type StorageOption struct {