generate jwt token when looking up needle id

fix https://github.com/seaweedfs/seaweedfs/issues/4577
This commit is contained in:
chrislu
2023-06-17 00:11:23 -07:00
parent 75f7893c11
commit 94fbf02ea2

View File

@@ -82,25 +82,32 @@ func (ms *MasterServer) LookupVolume(ctx context.Context, req *master_pb.LookupV
resp := &master_pb.LookupVolumeResponse{} resp := &master_pb.LookupVolumeResponse{}
volumeLocations := ms.lookupVolumeId(req.VolumeOrFileIds, req.Collection) volumeLocations := ms.lookupVolumeId(req.VolumeOrFileIds, req.Collection)
for _, result := range volumeLocations { for _, volumeOrFileId := range req.VolumeOrFileIds {
var locations []*master_pb.Location vid := volumeOrFileId
for _, loc := range result.Locations { commaSep := strings.Index(vid, ",")
locations = append(locations, &master_pb.Location{ if commaSep > 0 {
Url: loc.Url, vid = vid[0:commaSep]
PublicUrl: loc.PublicUrl, }
DataCenter: loc.DataCenter, if result, found := volumeLocations[vid]; found {
var locations []*master_pb.Location
for _, loc := range result.Locations {
locations = append(locations, &master_pb.Location{
Url: loc.Url,
PublicUrl: loc.PublicUrl,
DataCenter: loc.DataCenter,
})
}
var auth string
if commaSep > 0 { // this is a file id
auth = string(security.GenJwtForVolumeServer(ms.guard.SigningKey, ms.guard.ExpiresAfterSec, result.VolumeOrFileId))
}
resp.VolumeIdLocations = append(resp.VolumeIdLocations, &master_pb.LookupVolumeResponse_VolumeIdLocation{
VolumeOrFileId: result.VolumeOrFileId,
Locations: locations,
Error: result.Error,
Auth: auth,
}) })
} }
var auth string
if strings.Contains(result.VolumeOrFileId, ",") { // this is a file id
auth = string(security.GenJwtForVolumeServer(ms.guard.SigningKey, ms.guard.ExpiresAfterSec, result.VolumeOrFileId))
}
resp.VolumeIdLocations = append(resp.VolumeIdLocations, &master_pb.LookupVolumeResponse_VolumeIdLocation{
VolumeOrFileId: result.VolumeOrFileId,
Locations: locations,
Error: result.Error,
Auth: auth,
})
} }
return resp, nil return resp, nil