Skip to content

Commit

Permalink
support multiple checksum suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Apr 24, 2023
1 parent 94834c9 commit 5b055b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .toolbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ tools:
github: kubernetes/minikube
gh:
github: cli/cli
kubelogin:
github: Azure/kubelogin

target: ./download
14 changes: 13 additions & 1 deletion cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
"amd64": {"arm"},
"windows": {"darwin"},
}
checksumSuffixes = []string{"sum", "sha256"}

// fetchCmd represents the fetch command
fetchCmd = &cobra.Command{
Expand Down Expand Up @@ -226,7 +227,9 @@ func findMatching(toolName string, assets []types.Asset) *types.Asset {
var matching []*types.Asset
for i := range assets {
a := assets[i]
if strings.Contains(a.Name, toolName) && matches(runtime.GOOS, a.Name) && !strings.HasSuffix(a.Name, "sum") {
if strings.Contains(a.Name, toolName) &&
matches(runtime.GOOS, a.Name) &&
!hasForbiddenSuffix(a) {
matching = append(matching, &a)
}
}
Expand Down Expand Up @@ -260,6 +263,15 @@ func findMatching(toolName string, assets []types.Asset) *types.Asset {
return matching[0]
}

func hasForbiddenSuffix(a types.Asset) bool {
for _, suffix := range checksumSuffixes {
if strings.HasSuffix(a.Name, suffix) {
return true
}
}
return false
}

func parseTemplate(templ string, version string) string {
ut, err := template.New("url").Parse(templ)
if err != nil {
Expand Down

0 comments on commit 5b055b8

Please sign in to comment.