Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client: Only allow downloading from http/s and git #841

Merged
merged 2 commits into from
Feb 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion client/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,45 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"

gg "github.com/hashicorp/go-getter"
)

var (
// getters is the map of getters suitable for Nomad. It is initialized once
// and the lock is used to guard access to it.
getters map[string]gg.Getter
lock sync.Mutex

// supported is the set of download schemes supported by Nomad
supported = []string{"http", "https", "s3"}
)

// getClient returns a client that is suitable for Nomad.
func getClient(src, dst string) *gg.Client {
lock.Lock()
defer lock.Unlock()

// Return the pre-initialized client
if getters == nil {
getters = make(map[string]gg.Getter, len(supported))
for _, getter := range supported {
if impl, ok := gg.Getters[getter]; ok {
getters[getter] = impl
}
}
}

return &gg.Client{
Src: src,
Dst: dst,
Dir: false, // Only support a single file for now.
Getters: getters,
}
}

func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string, error) {
if source == "" {
return "", fmt.Errorf("Source url is empty in Artifact Getter")
Expand All @@ -29,7 +63,7 @@ func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string,
}

artifactFile := filepath.Join(destDir, path.Base(u.Path))
if err := gg.GetFile(artifactFile, source); err != nil {
if err := getClient(source, artifactFile).Get(); err != nil {
return "", fmt.Errorf("Error downloading artifact: %s", err)
}

Expand Down