diff --git a/src/extensions/bigbang/bigbang.go b/src/extensions/bigbang/bigbang.go index a0715fbb8c..59b9e7b0b6 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -84,12 +84,14 @@ func Run(YOLO bool, tmpPaths types.ComponentPaths, c types.ZarfComponent) (types } } + bbRepo := fmt.Sprintf("%s@%s", cfg.Repo, cfg.Version) + // Configure helm to pull down the Big Bang chart. helmCfg := helm.Helm{ Chart: types.ZarfChart{ Name: bb, Namespace: bb, - URL: cfg.Repo, + URL: bbRepo, Version: cfg.Version, ValuesFiles: cfg.ValuesFiles, GitPath: "./chart", @@ -494,7 +496,7 @@ func findImagesforBBChartRepo(repo string, values chartutil.Values) (images []st chart := types.ZarfChart{ Name: repo, - URL: matches[0], + URL: repo, Version: matches[1], GitPath: "chart", } diff --git a/src/internal/agent/hooks/flux.go b/src/internal/agent/hooks/flux.go index 21ad215192..98981b2ef6 100644 --- a/src/internal/agent/hooks/flux.go +++ b/src/internal/agent/hooks/flux.go @@ -80,7 +80,7 @@ func mutateGitRepo(r *v1.AdmissionRequest) (result *operations.Result, err error // Mutate the git URL if necessary if isCreate || (isUpdate && !isPatched) { // Mutate the git URL so that the hostname matches the hostname in the Zarf state - transformedURL, err := transform.GitTransformURL(zarfState.GitServer.Address, patchedURL, zarfState.GitServer.PushUsername) + transformedURL, err := transform.GitURL(zarfState.GitServer.Address, patchedURL, zarfState.GitServer.PushUsername) if err != nil { message.Warnf("Unable to transform the git url, using the original url we have: %s", patchedURL) } diff --git a/src/internal/agent/http/proxy.go b/src/internal/agent/http/proxy.go index 8c563fcc3a..b805d53564 100644 --- a/src/internal/agent/http/proxy.go +++ b/src/internal/agent/http/proxy.go @@ -73,7 +73,7 @@ func proxyRequestTransform(r *http.Request) error { } else { switch { case isGitUserAgent(r.UserAgent()): - targetURL, err = transform.GitTransformURL(zarfState.GitServer.Address, getTLSScheme(r.TLS)+r.Host+r.URL.String(), zarfState.GitServer.PushUsername) + targetURL, err = transform.GitURL(zarfState.GitServer.Address, getTLSScheme(r.TLS)+r.Host+r.URL.String(), zarfState.GitServer.PushUsername) case isPipUserAgent(r.UserAgent()): targetURL, err = transform.PipTransformURL(zarfState.ArtifactServer.Address, getTLSScheme(r.TLS)+r.Host+r.URL.String()) case isNpmUserAgent(r.UserAgent()): diff --git a/src/internal/packager/git/pull.go b/src/internal/packager/git/pull.go index 355ae21dee..79313cde32 100644 --- a/src/internal/packager/git/pull.go +++ b/src/internal/packager/git/pull.go @@ -38,7 +38,7 @@ func (g *Git) Pull(gitURL, targetFolder string, shallow bool) error { g.Spinner.Updatef("Processing git repo %s", gitURL) // Split the remote url and the zarf reference - gitURLNoRef, refPlain, err := transform.GitTransformURLSplitRef(gitURL) + gitURLNoRef, refPlain, err := transform.GitURLSplitRef(gitURL) if err != nil { return err } @@ -51,7 +51,7 @@ func (g *Git) Pull(gitURL, targetFolder string, shallow bool) error { } // Construct a path unique to this git repo - repoFolder, err := transform.GitTransformURLtoFolderName(gitURL) + repoFolder, err := transform.GitURLtoFolderName(gitURL) if err != nil { return err } diff --git a/src/internal/packager/git/push.go b/src/internal/packager/git/push.go index 12ffd4f36b..0d6a6b942d 100644 --- a/src/internal/packager/git/push.go +++ b/src/internal/packager/git/push.go @@ -25,7 +25,7 @@ func (g *Git) PushRepo(srcURL, targetFolder string) error { defer spinner.Stop() // Setup git paths, including a unique name for the repo based on the hash of the git URL to avoid conflicts. - repoFolder, err := transform.GitTransformURLtoFolderName(srcURL) + repoFolder, err := transform.GitURLtoFolderName(srcURL) if err != nil { return fmt.Errorf("unable to parse git url (%s): %w", srcURL, err) } @@ -34,7 +34,7 @@ func (g *Git) PushRepo(srcURL, targetFolder string) error { // Check that this package is using the new repo format (if not fallback to the format from <= 0.24.x) _, err = os.Stat(repoPath) if os.IsNotExist(err) { - repoFolder, err = transform.GitTransformURLtoRepoName(srcURL) + repoFolder, err = transform.GitURLtoRepoName(srcURL) if err != nil { return fmt.Errorf("unable to parse git url (%s): %w", srcURL, err) } @@ -63,7 +63,7 @@ func (g *Git) PushRepo(srcURL, targetFolder string) error { return err } remoteURL := remote.Config().URLs[0] - repoName, err := transform.GitTransformURLtoRepoName(remoteURL) + repoName, err := transform.GitURLtoRepoName(remoteURL) if err != nil { message.Warnf("Unable to add the read-only user to the repo: %s\n", repoName) return err @@ -94,7 +94,7 @@ func (g *Git) prepRepoForPush() (*git.Repository, error) { } remoteURL := remote.Config().URLs[0] - targetURL, err := transform.GitTransformURL(g.Server.Address, remoteURL, g.Server.PushUsername) + targetURL, err := transform.GitURL(g.Server.Address, remoteURL, g.Server.PushUsername) if err != nil { return nil, fmt.Errorf("unable to transform the git url: %w", err) } diff --git a/src/internal/packager/helm/common.go b/src/internal/packager/helm/common.go index e5682f0092..34e9047702 100644 --- a/src/internal/packager/helm/common.go +++ b/src/internal/packager/helm/common.go @@ -11,6 +11,7 @@ import ( "github.com/defenseunicorns/zarf/src/types" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" + "helm.sh/helm/v3/pkg/cli" ) // Helm is a config object for working with helm charts. @@ -25,6 +26,7 @@ type Helm struct { Cluster *cluster.Cluster Cfg *types.PackagerConfig KubeVersion string + Settings *cli.EnvSettings actionConfig *action.Configuration } diff --git a/src/internal/packager/helm/repo.go b/src/internal/packager/helm/repo.go index 5816d7e5cb..e16667a95b 100644 --- a/src/internal/packager/helm/repo.go +++ b/src/internal/packager/helm/repo.go @@ -8,10 +8,12 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/git" "github.com/defenseunicorns/zarf/src/pkg/message" + "github.com/defenseunicorns/zarf/src/pkg/transform" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/registry" @@ -22,29 +24,65 @@ import ( "helm.sh/helm/v3/pkg/repo" ) +// PackageChart creates a chart archive from a path to a chart on the host os and builds chart dependencies +func (h *Helm) PackageChart(destination string) error { + if len(h.Chart.URL) > 0 { + url, refPlain, err := transform.GitURLSplitRef(h.Chart.URL) + // check if the chart is a git url with a ref (if an error is returned url will be empty) + isGitURL := strings.HasSuffix(url, ".git") + if err != nil { + message.Debugf("unable to parse the url, continuing with %s", h.Chart.URL) + } + + if isGitURL { + // if it is a git url append chart version as if its a tag + if refPlain == "" { + h.Chart.URL = fmt.Sprintf("%s@%s", h.Chart.URL, h.Chart.Version) + } + + _, err = h.PackageChartFromGit(destination) + + if err != nil { + return fmt.Errorf("error creating chart archive, unable to pull the chart from git: %s", err.Error()) + } + } else { + h.DownloadPublishedChart(destination) + } + + } else { + _, err := h.PackageChartFromLocalFiles(destination) + if err != nil { + return fmt.Errorf("error creating chart archive, unable to package the chart: %s", err.Error()) + } + } + return nil +} + // PackageChartFromLocalFiles creates a chart archive from a path to a chart on the host os. -func (h *Helm) PackageChartFromLocalFiles(destination string) string { +func (h *Helm) PackageChartFromLocalFiles(destination string) (string, error) { spinner := message.NewProgressSpinner("Processing helm chart %s:%s from %s", h.Chart.Name, h.Chart.Version, h.Chart.LocalPath) defer spinner.Stop() // Validate the chart _, err := loader.LoadDir(h.Chart.LocalPath) if err != nil { - spinner.Fatalf(err, "Validation failed for chart from %s (%s)", h.Chart.LocalPath, err.Error()) + spinner.Errorf(err, "Validation failed for chart from %s (%s)", h.Chart.LocalPath, err.Error()) + return "", err } - + h.buildChartDependencies(spinner) client := action.NewPackage() client.Destination = destination path, err := client.Run(h.Chart.LocalPath, nil) if err != nil { - spinner.Fatalf(err, "Helm is unable to save the archive and create the package %s", path) + spinner.Errorf(err, "Helm is unable to save the archive and create the package %s", path) + return "", err } spinner.Success() - return path + return path, nil } // PackageChartFromGit is a special implementation of chart archiving that supports the https://p1.dso.mil/#/products/big-bang/ model. @@ -52,8 +90,6 @@ func (h *Helm) PackageChartFromGit(destination string) (string, error) { spinner := message.NewProgressSpinner("Processing helm chart %s", h.Chart.Name) defer spinner.Stop() - client := action.NewPackage() - // Retrieve the repo containing the chart gitPath, err := h.DownloadChartFromGitToTemp(spinner) if err != nil { @@ -61,26 +97,9 @@ func (h *Helm) PackageChartFromGit(destination string) (string, error) { } defer os.RemoveAll(gitPath) - // Set the directory for the chart - chartPath := filepath.Join(gitPath, h.Chart.GitPath) - - // Validate the chart - if _, err := loader.LoadDir(chartPath); err != nil { - spinner.Errorf(err, "Validation failed for chart %s (%s)", h.Chart.Name, err.Error()) - return "", err - } - - // Tell helm where to save the archive and create the package - client.Destination = destination - name, err := client.Run(chartPath, nil) - if err != nil { - spinner.Errorf(err, "Helm is unable to save the archive and create the package %s", name) - return "", err - } - - spinner.Success() - - return name, nil + // Set the directory for the chart and package it + h.Chart.LocalPath = filepath.Join(gitPath, h.Chart.GitPath) + return h.PackageChartFromLocalFiles(destination) } // DownloadPublishedChart loads a specific chart version from a remote repo. @@ -154,14 +173,40 @@ func (h *Helm) DownloadChartFromGitToTemp(spinner *message.Spinner) (string, err // Create the Git configuration and download the repo gitCfg := git.NewWithSpinner(h.Cfg.State.GitServer, spinner) - gitRepoWithRef := fmt.Sprintf("%s@%s", h.Chart.URL, h.Chart.Version) - // Download the git repo to a temporary directory - err := gitCfg.DownloadRepoToTemp(gitRepoWithRef) + err := gitCfg.DownloadRepoToTemp(h.Chart.URL) if err != nil { - spinner.Errorf(err, "Unable to download the git repo %s", gitRepoWithRef) + spinner.Errorf(err, "Unable to download the git repo %s", h.Chart.URL) return "", err } return gitCfg.GitPath, nil } + +// buildChartDependencies builds the helm chart dependencies +func (h *Helm) buildChartDependencies(spinner *message.Spinner) error { + regClient, err := registry.NewClient(registry.ClientOptEnableCache(true)) + if err != nil { + spinner.Fatalf(err, "Unable to create a new registry client") + } + h.Settings = cli.New() + man := &downloader.Manager{ + Out: os.Stdout, + ChartPath: h.Chart.LocalPath, + Getters: getter.All(h.Settings), + RegistryClient: regClient, + + RepositoryConfig: h.Settings.RepositoryConfig, + RepositoryCache: h.Settings.RepositoryCache, + Debug: false, + } + // Verify the chart + man.Verify = downloader.VerifyIfPossible + + // Build the deps from the helm chart + err = man.Build() + if e, ok := err.(downloader.ErrRepoNotFound); ok { + return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error()) + } + return nil +} diff --git a/src/internal/packager/helm/utils.go b/src/internal/packager/helm/utils.go index 13e30d978b..472a5c4978 100644 --- a/src/internal/packager/helm/utils.go +++ b/src/internal/packager/helm/utils.go @@ -66,13 +66,14 @@ func (h *Helm) parseChartValues() (map[string]any, error) { func (h *Helm) createActionConfig(namespace string, spinner *message.Spinner) error { // Initialize helm SDK actionConfig := new(action.Configuration) - settings := cli.New() + // Set the setings for the helm SDK + h.Settings = cli.New() // Set the namespace for helm - settings.SetNamespace(namespace) + h.Settings.SetNamespace(namespace) // Setup K8s connection - err := actionConfig.Init(settings.RESTClientGetter(), namespace, "", spinner.Updatef) + err := actionConfig.Init(h.Settings.RESTClientGetter(), namespace, "", spinner.Updatef) // Set the actionConfig is the received Helm pointer h.actionConfig = actionConfig diff --git a/src/pkg/packager/create.go b/src/pkg/packager/create.go index fb31a11590..ef138461d3 100755 --- a/src/pkg/packager/create.go +++ b/src/pkg/packager/create.go @@ -10,7 +10,6 @@ import ( "fmt" "os" "path/filepath" - "regexp" "strconv" "strings" "time" @@ -326,8 +325,7 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel // If any helm charts are defined, process them. for chartIdx, chart := range component.Charts { - re := regexp.MustCompile(`\.git$`) - isGitURL := re.MatchString(chart.URL) + helmCfg := helm.Helm{ Chart: chart, Cfg: p.cfg, @@ -343,18 +341,10 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent, isSkel } p.cfg.Pkg.Components[index].Charts[chartIdx].LocalPath = rel - } else if isGitURL { - _, err = helmCfg.PackageChartFromGit(componentPath.Charts) - if err != nil { - return fmt.Errorf("error creating chart archive, unable to pull the chart from git: %s", err.Error()) - } - } else if len(chart.URL) > 0 { - helmCfg.DownloadPublishedChart(componentPath.Charts) } else { - path := helmCfg.PackageChartFromLocalFiles(componentPath.Charts) - zarfFilename := fmt.Sprintf("%s-%s.tgz", chart.Name, chart.Version) - if !strings.HasSuffix(path, zarfFilename) { - return fmt.Errorf("error creating chart archive, user provided chart name and/or version does not match given chart") + err := helmCfg.PackageChart(componentPath.Charts) + if err != nil { + return err } } @@ -694,7 +684,7 @@ func (p *Packager) removeCopiesFromDifferentialPackage() error { // Generate a list of all unique repos for this component for _, repoURL := range component.Repos { // Split the remote url and the zarf reference - _, refPlain, err := transform.GitTransformURLSplitRef(repoURL) + _, refPlain, err := transform.GitURLSplitRef(repoURL) if err != nil { return err } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index d6e9926f49..7651d451ad 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -113,27 +113,19 @@ func (p *Packager) FindImages(baseDir, repoHelmChartPath string, kubeVersionOver if len(component.Charts) > 0 { _ = utils.CreateDirectory(componentPath.Charts, 0700) _ = utils.CreateDirectory(componentPath.Values, 0700) - re := regexp.MustCompile(`\.git$`) for _, chart := range component.Charts { - isGitURL := re.MatchString(chart.URL) + helmCfg := helm.Helm{ Chart: chart, Cfg: p.cfg, } helmCfg.Cfg.State = types.ZarfState{} - if isGitURL { - path, err := helmCfg.PackageChartFromGit(componentPath.Charts) - if err != nil { - return fmt.Errorf("unable to download chart from git repo (%s): %w", chart.URL, err) - } - // track the actual chart path - chartOverrides[chart.Name] = path - } else if len(chart.URL) > 0 { - helmCfg.DownloadPublishedChart(componentPath.Charts) - } else { - helmCfg.PackageChartFromLocalFiles(componentPath.Charts) + + err := helmCfg.PackageChart(componentPath.Charts) + if err != nil { + return fmt.Errorf("unable to package the chart %s: %s", chart.URL, err.Error()) } for idx, path := range chart.ValuesFiles { diff --git a/src/pkg/transform/git.go b/src/pkg/transform/git.go index 95e08c6be5..c3b1cb306b 100644 --- a/src/pkg/transform/git.go +++ b/src/pkg/transform/git.go @@ -12,14 +12,14 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) -// For further explanation: https://regex101.com/r/YxpfhC/3 -var gitURLRegex = regexp.MustCompile(`^(?P[a-z]+:\/\/)(?P.+?)\/(?P[\w\-\.]+?)(?P\.git)?(?P@(?P\+)?(?P[\/\+\w\-\.]+))?(?P\/(?Pinfo\/.*|git-upload-pack|git-receive-pack))?$`) +// For further explanation: https://regex101.com/r/YxpfhC/5 +var gitURLRegex = regexp.MustCompile(`^(?P[a-z]+:\/\/)(?P.+?)\/(?P[\w\-\.]+?)?(?P\.git)?(\/)?(?P@(?P\+)?(?P[\/\+\w\-\.]+))?(?P\/(?Pinfo\/.*|git-upload-pack|git-receive-pack))?$`) // MutateGitURLsInText changes the gitURL hostname to use the repository Zarf is configured to use. func MutateGitURLsInText(logger Log, targetBaseURL string, text string, pushUser string) string { extractPathRegex := regexp.MustCompile(`[a-z]+:\/\/[^\/]+\/(.*\.git)`) output := extractPathRegex.ReplaceAllStringFunc(text, func(match string) string { - output, err := GitTransformURL(targetBaseURL, match, pushUser) + output, err := GitURL(targetBaseURL, match, pushUser) if err != nil { logger("Unable to transform the git url, using the original url we have: %s", match) return match @@ -29,8 +29,8 @@ func MutateGitURLsInText(logger Log, targetBaseURL string, text string, pushUser return output } -// GitTransformURLSplitRef takes a git url and returns a separated source url and zarf reference. -func GitTransformURLSplitRef(sourceURL string) (string, string, error) { +// GitURLSplitRef takes a git url and returns a separated source url and zarf reference. +func GitURLSplitRef(sourceURL string) (string, string, error) { get, err := helpers.MatchRegex(gitURLRegex, sourceURL) if err != nil { @@ -43,8 +43,8 @@ func GitTransformURLSplitRef(sourceURL string) (string, string, error) { return gitURLNoRef, refPlain, nil } -// GitTransformURLtoFolderName takes a git url and returns the folder name for the repo in the Zarf package. -func GitTransformURLtoFolderName(sourceURL string) (string, error) { +// GitURLtoFolderName takes a git url and returns the folder name for the repo in the Zarf package. +func GitURLtoFolderName(sourceURL string) (string, error) { get, err := helpers.MatchRegex(gitURLRegex, sourceURL) if err != nil { @@ -64,8 +64,8 @@ func GitTransformURLtoFolderName(sourceURL string) (string, error) { return newRepoName, nil } -// GitTransformURLtoRepoName takes a git url and returns the name of the repo in the remote airgap repository. -func GitTransformURLtoRepoName(sourceURL string) (string, error) { +// GitURLtoRepoName takes a git url and returns the name of the repo in the remote airgap repository. +func GitURLtoRepoName(sourceURL string) (string, error) { get, err := helpers.MatchRegex(gitURLRegex, sourceURL) if err != nil { @@ -86,9 +86,9 @@ func GitTransformURLtoRepoName(sourceURL string) (string, error) { return newRepoName, nil } -// GitTransformURL takes a base URL, a source url and a username and returns a Zarf-compatible url. -func GitTransformURL(targetBaseURL string, sourceURL string, pushUser string) (*url.URL, error) { - repoName, err := GitTransformURLtoRepoName(sourceURL) +// GitURL takes a base URL, a source url and a username and returns a Zarf-compatible url. +func GitURL(targetBaseURL string, sourceURL string, pushUser string) (*url.URL, error) { + repoName, err := GitURLtoRepoName(sourceURL) if err != nil { return nil, err } diff --git a/src/pkg/transform/git_test.go b/src/pkg/transform/git_test.go index 4b7b0fd52c..0bee04260d 100644 --- a/src/pkg/transform/git_test.go +++ b/src/pkg/transform/git_test.go @@ -26,6 +26,9 @@ var gitURLs = []string{ "https://github.com/defenseunicorns/zarf.helm.git", "https://github.com/defenseunicorns/zarf.git@refs/tags/v0.16.0", "https://github.com/DoD-Platform-One/big-bang.git@refs/heads/release-1.54.x", + "https://github.com/prometheus-community/helm-charts.git@kube-prometheus-stack-47.3.0", + "https://github.com/prometheus-community/", + "https://github.com/", // Smart Git Protocol URLs for proxying (https://www.git-scm.com/docs/http-protocol) "https://github.com/defenseunicorns/zarf.helm.git/info/refs", @@ -70,7 +73,7 @@ func TestMutateGitURLsInText(t *testing.T) { require.Equal(t, expectedText, resultingText) } -func TestGitTransformURLSplitRef(t *testing.T) { +func TestGitURLSplitRef(t *testing.T) { var expectedResult = [][]string{ // Normal git repos and references for pushing/pulling {"https://repo1.dso.mil/platform-one/big-bang/apps/security-tools/twistlock.git", ""}, @@ -87,6 +90,9 @@ func TestGitTransformURLSplitRef(t *testing.T) { {"https://github.com/defenseunicorns/zarf.helm.git", ""}, {"https://github.com/defenseunicorns/zarf.git", "refs/tags/v0.16.0"}, {"https://github.com/DoD-Platform-One/big-bang.git", "refs/heads/release-1.54.x"}, + {"https://github.com/prometheus-community/helm-charts.git", "kube-prometheus-stack-47.3.0"}, + {"https://github.com/prometheus-community", ""}, + {"https://github.com/", ""}, // Smart Git Protocol URLs for proxying (https://www.git-scm.com/docs/http-protocol) {"https://github.com/defenseunicorns/zarf.helm.git", ""}, @@ -97,19 +103,19 @@ func TestGitTransformURLSplitRef(t *testing.T) { } for idx, url := range gitURLs { - gitURLNoRef, refPlain, err := GitTransformURLSplitRef(url) + gitURLNoRef, refPlain, err := GitURLSplitRef(url) require.NoError(t, err) require.Equal(t, expectedResult[idx][0], gitURLNoRef) require.Equal(t, expectedResult[idx][1], refPlain) } for _, url := range badGitURLs { - _, _, err := GitTransformURLSplitRef(url) + _, _, err := GitURLSplitRef(url) require.Error(t, err) } } -func TestGitTransformURLtoFolderName(t *testing.T) { +func TestGitURLtoFolderName(t *testing.T) { var expectedResult = []string{ // Normal git repos and references for pushing/pulling "twistlock-1590638614", @@ -126,6 +132,9 @@ func TestGitTransformURLtoFolderName(t *testing.T) { "zarf.helm-2570741950", "zarf-2175050463", "big-bang-2705706079", + "helm-charts-1319967699", + "prometheus-community-3453166319", + "-1276058275", // Smart Git Protocol URLs for proxying (https://www.git-scm.com/docs/http-protocol) "zarf.helm-2570741950", @@ -136,18 +145,18 @@ func TestGitTransformURLtoFolderName(t *testing.T) { } for idx, url := range gitURLs { - repoFolder, err := GitTransformURLtoFolderName(url) + repoFolder, err := GitURLtoFolderName(url) require.NoError(t, err) require.Equal(t, expectedResult[idx], repoFolder) } for _, url := range badGitURLs { - _, err := GitTransformURLtoFolderName(url) + _, err := GitURLtoFolderName(url) require.Error(t, err) } } -func TestGitTransformURLtoRepoName(t *testing.T) { +func TestGitURLtoRepoName(t *testing.T) { var expectedResult = []string{ // Normal git repos and references for pushing/pulling "twistlock-97328248", @@ -164,6 +173,9 @@ func TestGitTransformURLtoRepoName(t *testing.T) { "zarf.helm-842267124", "zarf-1211668992", "big-bang-2366614037", + "helm-charts-3648076006", + "prometheus-community-2749132599", + "-98306241", // Smart Git Protocol URLs for proxying (https://www.git-scm.com/docs/http-protocol) "zarf.helm-842267124", @@ -174,18 +186,18 @@ func TestGitTransformURLtoRepoName(t *testing.T) { } for idx, url := range gitURLs { - repoName, err := GitTransformURLtoRepoName(url) + repoName, err := GitURLtoRepoName(url) require.NoError(t, err) require.Equal(t, expectedResult[idx], repoName) } for _, url := range badGitURLs { - _, err := GitTransformURLtoRepoName(url) + _, err := GitURLtoRepoName(url) require.Error(t, err) } } -func TestGitTransformURL(t *testing.T) { +func TestGitURL(t *testing.T) { var expectedResult = []string{ // Normal git repos and references for pushing/pulling "https://gitlab.com/repo-owner/twistlock-97328248.git", @@ -202,6 +214,9 @@ func TestGitTransformURL(t *testing.T) { "https://gitlab.com/repo-owner/zarf.helm-842267124.git", "https://gitlab.com/repo-owner/zarf-1211668992.git", "https://gitlab.com/repo-owner/big-bang-2366614037.git", + "https://gitlab.com/repo-owner/helm-charts-3648076006.git", + "https://gitlab.com/repo-owner/prometheus-community-2749132599", + "https://gitlab.com/repo-owner/-98306241", // Smart Git Protocol URLs for proxying (https://www.git-scm.com/docs/http-protocol) "https://gitlab.com/repo-owner/zarf.helm-842267124.git/info/refs", @@ -212,13 +227,13 @@ func TestGitTransformURL(t *testing.T) { } for idx, url := range gitURLs { - repoURL, err := GitTransformURL("https://gitlab.com", url, "repo-owner") + repoURL, err := GitURL("https://gitlab.com", url, "repo-owner") require.NoError(t, err) require.Equal(t, expectedResult[idx], repoURL.String()) } for _, url := range badGitURLs { - _, err := GitTransformURL("https://gitlab.com", url, "repo-owner") + _, err := GitURL("https://gitlab.com", url, "repo-owner") require.Error(t, err) } } diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index d4f7ba2968..e45048d6e0 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -240,7 +240,7 @@ func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components if !isSkeleton { for _, repo := range component.Repos { - dir, err := transform.GitTransformURLtoFolderName(repo) + dir, err := transform.GitURLtoFolderName(repo) suite.NoError(err) suite.DirExists(filepath.Join(componentPaths.Repos, dir)) }