github.com/ryanslade/nomad@v0.2.4-0.20160128061903-fc95782f2089/client/getter/getter.go (about) 1 package getter 2 3 import ( 4 "fmt" 5 "log" 6 "net/url" 7 "path" 8 "path/filepath" 9 "runtime" 10 "strings" 11 "syscall" 12 13 gg "github.com/hashicorp/go-getter" 14 ) 15 16 func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string, error) { 17 if source == "" { 18 return "", fmt.Errorf("Source url is empty in Artifact Getter") 19 } 20 u, err := url.Parse(source) 21 if err != nil { 22 return "", err 23 } 24 25 // if checksum is seperate, apply to source 26 if checksum != "" { 27 source = strings.Join([]string{source, fmt.Sprintf("checksum=%s", checksum)}, "?") 28 logger.Printf("[DEBUG] client.getter: Applying checksum to Artifact Source URL, new url: %s", source) 29 } 30 31 artifactFile := filepath.Join(destDir, path.Base(u.Path)) 32 if err := gg.GetFile(artifactFile, source); err != nil { 33 return "", fmt.Errorf("Error downloading artifact: %s", err) 34 } 35 36 // Add execution permissions to the newly downloaded artifact 37 if runtime.GOOS != "windows" { 38 if err := syscall.Chmod(artifactFile, 0755); err != nil { 39 logger.Printf("[ERR] driver.raw_exec: Error making artifact executable: %s", err) 40 } 41 } 42 return artifactFile, nil 43 }