Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes to the download cmd in handling the context path and bug fixes #128

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions registry-library/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -164,7 +163,7 @@ func init() {
SkipTLSVerify: skipTLSVerify,
}

err = library.DownloadStarterProjectAsDir(filepath.Join(destDir, starterProject), registry, stack, starterProject, options)
err = library.DownloadStarterProjectAsDir(destDir, registry, stack, starterProject, options)
if err != nil {
fmt.Printf("failed to download starter project %s: %v\n", starterProject, err)
}
Expand Down
4 changes: 2 additions & 2 deletions registry-library/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func DownloadStarterProjectAsDir(path string, registryURL string, stack string,
filePath := filepath.Join(path, file.Name)

// validate extracted filepath
if !strings.HasPrefix(filePath, filepath.Clean(path)+string(os.PathSeparator)) {
if filePath != file.Name && !strings.HasPrefix(filePath, filepath.Clean(path)+string(os.PathSeparator)) {
return fmt.Errorf("invalid file path %s", filePath)
}

Expand Down Expand Up @@ -423,7 +423,7 @@ func DownloadStarterProjectAsBytes(registryURL string, stack string, starterProj
return nil, err
}

url := fmt.Sprintf("%s/%s", urlObj.String(), path.Join("devfiles", stackName, "starter-projects", starterProject))
url := fmt.Sprintf("%s://%s", urlObj.Scheme, path.Join(urlObj.Host, "devfiles", stackName, "starter-projects", starterProject))
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/pkg/tests/devfilelibrary_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,17 @@ var _ = ginkgo.Describe("[Verify registry library works with registry]", func()
})

ginkgo.It("should properly download stack starter project", func() {
tempDir := os.TempDir()
tempDir := path.Join(os.TempDir(), javaMavenStarter)
util.CmdShouldPass("registry-library", "download", publicDevfileRegistry, javaMavenStack, javaMavenStarter, "--context", tempDir)
starterPath := path.Join(tempDir, javaMavenStarter)
info, err := os.Stat(starterPath)
info, err := os.Stat(tempDir)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(info.IsDir()).To(gomega.Equal(true))
})

ginkgo.It("should properly download V2 stack starter project", func() {
tempDir := os.TempDir()
tempDir := path.Join(os.TempDir(), goStarter)
util.CmdShouldPass("registry-library", "download", publicDevfileRegistry, goStack, goStarter, "--context", tempDir, "--new-index-schema")
starterPath := path.Join(tempDir, goStarter)
info, err := os.Stat(starterPath)
info, err := os.Stat(tempDir)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(info.IsDir()).To(gomega.Equal(true))
})
Expand Down