36 lines
842 B
Go
36 lines
842 B
Go
package downloader
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/allanger/yaho/internal/tools/git"
|
|
"github.com/allanger/yaho/internal/tools/helm"
|
|
)
|
|
|
|
type PullOptions struct {}
|
|
|
|
// A very stupid check
|
|
func isGitRepo(repository string) bool {
|
|
return strings.HasPrefix(repository, "git@") || strings.HasSuffix(repository, ".git")
|
|
}
|
|
// Pull chart into a temporary directory
|
|
func PullChart(ctx context.Context, repository, chart, version string, opts *PullOptions) (string, error) {
|
|
if isGitRepo(repository) {
|
|
git := git.GitLib{}
|
|
path, err := git.CloneRepo(ctx, repository, version)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return fmt.Sprintf("%s/%s", path, chart), nil
|
|
} else {
|
|
helm := helm.HelmLib{}
|
|
path, err := helm.PullChart(ctx, repository, chart, version)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return path, nil
|
|
}
|
|
}
|