aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/swarm/download.go
diff options
context:
space:
mode:
authorElad <theman@elad.im>2018-08-15 23:41:52 +0800
committerBalint Gabor <balint.g@gmail.com>2018-08-15 23:41:52 +0800
commite8752f4e9f9be3d2932cd4835a5d72d17ac2338b (patch)
tree73f1514fc0134f2f5ef4b467f1076548b8a18bc3 /cmd/swarm/download.go
parent040aa2bb101e5e602308b24812bfbf2451b21174 (diff)
downloaddexon-e8752f4e9f9be3d2932cd4835a5d72d17ac2338b.tar
dexon-e8752f4e9f9be3d2932cd4835a5d72d17ac2338b.tar.gz
dexon-e8752f4e9f9be3d2932cd4835a5d72d17ac2338b.tar.bz2
dexon-e8752f4e9f9be3d2932cd4835a5d72d17ac2338b.tar.lz
dexon-e8752f4e9f9be3d2932cd4835a5d72d17ac2338b.tar.xz
dexon-e8752f4e9f9be3d2932cd4835a5d72d17ac2338b.tar.zst
dexon-e8752f4e9f9be3d2932cd4835a5d72d17ac2338b.zip
cmd/swarm, swarm: added access control functionality (#17404)
Co-authored-by: Janos Guljas <janos@resenje.org> Co-authored-by: Anton Evangelatov <anton.evangelatov@gmail.com> Co-authored-by: Balint Gabor <balint.g@gmail.com>
Diffstat (limited to 'cmd/swarm/download.go')
-rw-r--r--cmd/swarm/download.go40
1 files changed, 29 insertions, 11 deletions
diff --git a/cmd/swarm/download.go b/cmd/swarm/download.go
index c2418f744..91bc2c93a 100644
--- a/cmd/swarm/download.go
+++ b/cmd/swarm/download.go
@@ -68,18 +68,36 @@ func download(ctx *cli.Context) {
utils.Fatalf("could not parse uri argument: %v", err)
}
- // assume behaviour according to --recursive switch
- if isRecursive {
- if err := client.DownloadDirectory(uri.Addr, uri.Path, dest); err != nil {
- utils.Fatalf("encoutered an error while downloading directory: %v", err)
- }
- } else {
- // we are downloading a file
- log.Debug(fmt.Sprintf("downloading file/path from a manifest. hash: %s, path:%s", uri.Addr, uri.Path))
+ dl := func(credentials string) error {
+ // assume behaviour according to --recursive switch
+ if isRecursive {
+ if err := client.DownloadDirectory(uri.Addr, uri.Path, dest, credentials); err != nil {
+ if err == swarm.ErrUnauthorized {
+ return err
+ }
+ return fmt.Errorf("directory %s: %v", uri.Path, err)
+ }
+ } else {
+ // we are downloading a file
+ log.Debug("downloading file/path from a manifest", "uri.Addr", uri.Addr, "uri.Path", uri.Path)
- err := client.DownloadFile(uri.Addr, uri.Path, dest)
- if err != nil {
- utils.Fatalf("could not download %s from given address: %s. error: %v", uri.Path, uri.Addr, err)
+ err := client.DownloadFile(uri.Addr, uri.Path, dest, credentials)
+ if err != nil {
+ if err == swarm.ErrUnauthorized {
+ return err
+ }
+ return fmt.Errorf("file %s from address: %s: %v", uri.Path, uri.Addr, err)
+ }
}
+ return nil
+ }
+ if passwords := makePasswordList(ctx); passwords != nil {
+ password := getPassPhrase(fmt.Sprintf("Downloading %s is restricted", uri), 0, passwords)
+ err = dl(password)
+ } else {
+ err = dl("")
+ }
+ if err != nil {
+ utils.Fatalf("download: %v", err)
}
}