diff options
Diffstat (limited to 'weed/command/download.go')
| -rw-r--r-- | weed/command/download.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/weed/command/download.go b/weed/command/download.go index 7bbff9448..a64d3f237 100644 --- a/weed/command/download.go +++ b/weed/command/download.go @@ -2,6 +2,8 @@ package command import ( "fmt" + "github.com/chrislusf/seaweedfs/weed/security" + "google.golang.org/grpc" "io" "io/ioutil" "net/http" @@ -43,20 +45,23 @@ var cmdDownload = &Command{ } func runDownload(cmd *Command, args []string) bool { + util.LoadConfiguration("security", false) + grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client") + for _, fid := range args { - if e := downloadToFile(func() string { return *d.server }, fid, util.ResolvePath(*d.dir)); e != nil { + if e := downloadToFile(func() string { return *d.server }, grpcDialOption, fid, util.ResolvePath(*d.dir)); e != nil { fmt.Println("Download Error: ", fid, e) } } return true } -func downloadToFile(masterFn operation.GetMasterFn, fileId, saveDir string) error { - fileUrl, lookupError := operation.LookupFileId(masterFn, fileId) +func downloadToFile(masterFn operation.GetMasterFn, grpcDialOption grpc.DialOption, fileId, saveDir string) error { + fileUrl, jwt, lookupError := operation.LookupFileId(masterFn, grpcDialOption, fileId) if lookupError != nil { return lookupError } - filename, _, rc, err := util.DownloadFile(fileUrl) + filename, _, rc, err := util.DownloadFile(fileUrl, jwt) if err != nil { return err } @@ -83,7 +88,7 @@ func downloadToFile(masterFn operation.GetMasterFn, fileId, saveDir string) erro fids := strings.Split(string(content), "\n") for _, partId := range fids { var n int - _, part, err := fetchContent(masterFn, partId) + _, part, err := fetchContent(masterFn, grpcDialOption, partId) if err == nil { n, err = f.Write(part) } @@ -103,13 +108,13 @@ func downloadToFile(masterFn operation.GetMasterFn, fileId, saveDir string) erro return nil } -func fetchContent(masterFn operation.GetMasterFn, fileId string) (filename string, content []byte, e error) { - fileUrl, lookupError := operation.LookupFileId(masterFn, fileId) +func fetchContent(masterFn operation.GetMasterFn, grpcDialOption grpc.DialOption, fileId string) (filename string, content []byte, e error) { + fileUrl, jwt, lookupError := operation.LookupFileId(masterFn, grpcDialOption, fileId) if lookupError != nil { return "", nil, lookupError } var rc *http.Response - if filename, _, rc, e = util.DownloadFile(fileUrl); e != nil { + if filename, _, rc, e = util.DownloadFile(fileUrl, jwt); e != nil { return "", nil, e } defer util.CloseResponse(rc) |
