Add downloader builtin plugin

This commit is contained in:
sophia 2022-05-24 09:31:06 -05:00
parent 90825f7086
commit 9c234618f3
2 changed files with 60 additions and 0 deletions

View File

@ -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)
)

View File

@ -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"),
}