Add downloader builtin plugin
This commit is contained in:
parent
90825f7086
commit
9c234618f3
45
builtin/filedownloader/downloader/downloader.go
Normal file
45
builtin/filedownloader/downloader/downloader.go
Normal 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)
|
||||
)
|
||||
15
builtin/filedownloader/main.go
Normal file
15
builtin/filedownloader/main.go
Normal 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"),
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user