-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(file domain): add network.DownloadFile and use go-getter to dow…
…nload files (#760) * chore(file domain): use go-getter to download files * validate assessment results in file download test
- Loading branch information
1 parent
fae5e4c
commit 9654993
Showing
11 changed files
with
261 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package network | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/go-getter/v2" | ||
) | ||
|
||
// DownloadFile downloads a file to the requested dst (full file path) from src. | ||
// wd is used when resolving relative paths and should be set to the common root | ||
// directory of relative paths (defaults to the directory the input file is in). | ||
// Go-getter supports the following protocols, though not all are relevant in | ||
// file mode (and Lula can extend the Getter interface if we need to add to this | ||
// list): | ||
// | ||
// - Local files | ||
// - Git | ||
// - Mercurial | ||
// - HTTP | ||
// - Amazon S3 | ||
// - Google GCP | ||
// - SMB | ||
// - Source: https://pkg.go.dev/github.com/hashicorp/go-getter/v2#section-readme | ||
// | ||
// DownloadFile returns the actual download path and error. The error returned | ||
// may be a go-multierror. | ||
func DownloadFile(ctx context.Context, dst, src, wd string) (string, error) { | ||
client := getter.Client{ | ||
// following symlinks is a security concern | ||
DisableSymlinks: true, | ||
} | ||
|
||
rsp, err := client.Get(ctx, &getter.Request{ | ||
Src: src, | ||
Dst: dst, | ||
Pwd: wd, | ||
Copy: true, // if we are getting a local file, copy it instead of making a symlink | ||
GetMode: getter.ModeFile, | ||
}) | ||
if rsp == nil { | ||
return "", err | ||
} | ||
|
||
return rsp.Dst, err | ||
} |
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 |
---|---|---|
|
@@ -56,5 +56,4 @@ func TestLintCommand(t *testing.T) { | |
} | ||
}) | ||
} | ||
|
||
} |
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
Oops, something went wrong.