use grpc and jwt

This commit is contained in:
Chris Lu
2021-08-12 21:40:33 -07:00
parent 6238644c35
commit 5a0f92423e
15 changed files with 453 additions and 453 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/chrislusf/raft"
"reflect"
"strings"
"sync"
"time"
@@ -69,7 +70,7 @@ func (ms *MasterServer) ProcessGrowRequest() {
func (ms *MasterServer) LookupVolume(ctx context.Context, req *master_pb.LookupVolumeRequest) (*master_pb.LookupVolumeResponse, error) {
resp := &master_pb.LookupVolumeResponse{}
volumeLocations := ms.lookupVolumeId(req.VolumeIds, req.Collection)
volumeLocations := ms.lookupVolumeId(req.VolumeOrFileIds, req.Collection)
for _, result := range volumeLocations {
var locations []*master_pb.Location
@@ -79,10 +80,15 @@ func (ms *MasterServer) LookupVolume(ctx context.Context, req *master_pb.LookupV
PublicUrl: loc.PublicUrl,
})
}
var auth string
if strings.Contains(result.VolumeOrFileId, ",") { // this is a file id
auth = string(security.GenJwt(ms.guard.SigningKey, ms.guard.ExpiresAfterSec, result.VolumeOrFileId))
}
resp.VolumeIdLocations = append(resp.VolumeIdLocations, &master_pb.LookupVolumeResponse_VolumeIdLocation{
VolumeId: result.VolumeId,
Locations: locations,
Error: result.Error,
VolumeOrFileId: result.VolumeOrFileId,
Locations: locations,
Error: result.Error,
Auth: auth,
})
}

View File

@@ -86,8 +86,8 @@ func (ms *MasterServer) findVolumeLocation(collection, vid string) operation.Loo
err = fmt.Errorf("volume id %s not found", vid)
}
ret := operation.LookupResult{
VolumeId: vid,
Locations: locations,
VolumeOrFileId: vid,
Locations: locations,
}
if err != nil {
ret.Error = err.Error()

View File

@@ -252,7 +252,7 @@ func (vs *VolumeServer) tryHandleChunkedFile(n *needle.Needle, fileName string,
w.Header().Set("X-File-Store", "chunked")
chunkedFileReader := operation.NewChunkedFileReader(chunkManifest.Chunks, vs.GetMaster())
chunkedFileReader := operation.NewChunkedFileReader(chunkManifest.Chunks, vs.GetMaster(), vs.grpcDialOption)
defer chunkedFileReader.Close()
rs := conditionallyResizeImages(chunkedFileReader, ext, r)