-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from hashicorp/f-getter-refactor
client/drivers: Refactor to use Getter wrapper
- Loading branch information
Showing
14 changed files
with
260 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package getter | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"path" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"syscall" | ||
|
||
gg "github.com/hashicorp/go-getter" | ||
) | ||
|
||
func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string, error) { | ||
if source == "" { | ||
return "", fmt.Errorf("Source url is empty in Artifact Getter") | ||
} | ||
u, err := url.Parse(source) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// if checksum is seperate, apply to source | ||
if checksum != "" { | ||
source = strings.Join([]string{source, fmt.Sprintf("checksum=%s", checksum)}, "?") | ||
logger.Printf("[DEBUG] client.getter: Applying checksum to Artifact Source URL, new url: %s", source) | ||
} | ||
|
||
artifactFile := filepath.Join(destDir, path.Base(u.Path)) | ||
if err := gg.GetFile(artifactFile, source); err != nil { | ||
return "", fmt.Errorf("Error downloading artifact: %s", err) | ||
} | ||
|
||
// Add execution permissions to the newly downloaded artifact | ||
if runtime.GOOS != "windows" { | ||
if err := syscall.Chmod(artifactFile, 0755); err != nil { | ||
logger.Printf("[ERR] driver.raw_exec: Error making artifact executable: %s", err) | ||
} | ||
} | ||
return artifactFile, nil | ||
} |
Oops, something went wrong.