diff --git a/builtin/filedownloader/downloader/downloader.go b/builtin/filedownloader/downloader/downloader.go new file mode 100644 index 000000000..cf72b7892 --- /dev/null +++ b/builtin/filedownloader/downloader/downloader.go @@ -0,0 +1,45 @@ +package downloader + +import ( + "net/http" + "time" + + "github.com/hashicorp/go-getter" + "github.com/hashicorp/vagrant-plugin-sdk/component" +) + +type Downloader struct { + config DownloaderConfig +} + +type DownloaderConfig struct { + src string + dest string + headers http.Header +} + +func (d *Downloader) DownloadFunc() interface{} { + return d.Download +} + +func (d *Downloader) Download() (err error) { + err = getter.Get(d.config.dest, d.config.src, getter.WithGetters( + map[string]getter.Getter{ + "http": &getter.HttpGetter{ + Netrc: false, + HeadFirstTimeout: 10 * time.Second, + Header: d.config.headers, + ReadTimeout: 30 * time.Second, + MaxBytes: 500000000, // 500 MB + }, + "file": &getter.FileGetter{ + Copy: true, + }, + }, + )) + return +} + +var ( + _ component.Downloader = (*Downloader)(nil) +) diff --git a/builtin/filedownloader/main.go b/builtin/filedownloader/main.go new file mode 100644 index 000000000..c624ae08c --- /dev/null +++ b/builtin/filedownloader/main.go @@ -0,0 +1,15 @@ +package filedownloader + +import ( + sdk "github.com/hashicorp/vagrant-plugin-sdk" + "github.com/hashicorp/vagrant/builtin/filedownloader/downloader" +) + +//go:generate protoc -I ../../.. --go_opt=plugins=grpc --go_out=../../.. vagrant-ruby/builtin/filedownloader/proto/plugin.proto + +var CommandOptions = []sdk.Option{ + sdk.WithComponents( + &downloader.Downloader{}, + ), + sdk.WithName("filedownloader"), +}