From d1ce109b26feee935abb3866c0b2baf2e1f1b1db Mon Sep 17 00:00:00 2001 From: Amal Thundiyil Date: Tue, 3 May 2022 15:26:44 +0530 Subject: [PATCH] reva: review comments --- cmd/reva/download.go | 13 +++++-------- cmd/reva/main.go | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cmd/reva/download.go b/cmd/reva/download.go index e06cf323f50..b957cc16a44 100644 --- a/cmd/reva/download.go +++ b/cmd/reva/download.go @@ -23,7 +23,6 @@ import ( "io" "net/http" "os" - "time" "github.com/cheggaaa/pb" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" @@ -38,7 +37,7 @@ import ( "github.com/studio-b12/gowebdav" ) -func downloadCommand() *command { +func downloadCommand(httpClient *http.Client) *command { cmd := newCommand("download") cmd.Description = func() string { return "download a remote file to the local filesystem" } cmd.Usage = func() string { return "Usage: download [-flags] " } @@ -102,11 +101,6 @@ func downloadCommand() *command { } httpReq.Header.Set(datagateway.TokenTransportHeader, p.Token) - httpClient := rhttp.GetHTTPClient( - rhttp.Context(ctx), - rhttp.Insecure(insecure), - rhttp.Timeout(time.Duration(timeout*int64(time.Hour))), - ) httpRes, err := httpClient.Do(httpReq) if err != nil { @@ -142,7 +136,10 @@ func downloadCommand() *command { return cmd } -func getDownloadProtocolInfo(protocolInfos []*gateway.FileDownloadProtocol, protocol string) (*gateway.FileDownloadProtocol, error) { +func getDownloadProtocolInfo( + protocolInfos []*gateway.FileDownloadProtocol, + protocol string, +) (*gateway.FileDownloadProtocol, error) { for _, p := range protocolInfos { if p.Protocol == protocol { return p, nil diff --git a/cmd/reva/main.go b/cmd/reva/main.go index d9eb75a7d70..5b55945135e 100644 --- a/cmd/reva/main.go +++ b/cmd/reva/main.go @@ -51,7 +51,7 @@ var ( lsCommand(), statCommand(), uploadCommand(), - downloadCommand(), + downloadCommand(client), rmCommand(), moveCommand(), mkdirCommand(), @@ -97,8 +97,18 @@ var ( func init() { flag.StringVar(&host, "host", "", "address of the GRPC gateway host") flag.BoolVar(&insecure, "insecure", false, "disables grpc transport security") - flag.BoolVar(&insecuredatagateway, "insecure-data-gateway", false, "disables grpc transport security for data gateway service") - flag.BoolVar(&skipverify, "skip-verify", false, "whether to skip verifying the server's certificate chain and host name") + flag.BoolVar( + &insecuredatagateway, + "insecure-data-gateway", + false, + "disables grpc transport security for data gateway service", + ) + flag.BoolVar( + &skipverify, + "skip-verify", + false, + "whether to skip verifying the server's certificate chain and host name", + ) flag.BoolVar(&disableargprompt, "disable-arg-prompt", false, "whether to disable prompts for command arguments") flag.Int64Var(&timeout, "timeout", -1, "the timeout in seconds for executing the commands, -1 means no timeout") flag.Parse() @@ -152,6 +162,11 @@ func generateMainUsage() { helpCommandOutput = "Command line interface to REVA:\n" for _, cmd := range commands { - helpCommandOutput += fmt.Sprintf("%s%s%s\n", cmd.Name, strings.Repeat(" ", 4+(n-len(cmd.Name))), cmd.Description()) + helpCommandOutput += fmt.Sprintf( + "%s%s%s\n", + cmd.Name, + strings.Repeat(" ", 4+(n-len(cmd.Name))), + cmd.Description(), + ) } }