Skip to content

Commit

Permalink
Merge pull request #934 from ernstvonoelsen/issue-928
Browse files Browse the repository at this point in the history
Issue 928
  • Loading branch information
joaopapereira authored Jan 30, 2025
2 parents fe109b1 + 04ac63b commit faba705
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func NewSortedFilesFromPaths(paths []string, opts SymlinkAllowOpts) ([]*File, er

relativePath := ""
pathPieces := strings.Split(path, "=")
if strings.HasPrefix(pathPieces[0], "http://") || strings.HasPrefix(pathPieces[0], "https://") {
pathPieces = []string{path}
} else if len(pathPieces) > 1 && (strings.HasPrefix(pathPieces[1], "http://") || strings.HasPrefix(pathPieces[1], "https://")) {
pathPieces[1] = strings.Join(pathPieces[1:], "=")
pathPieces = pathPieces[0:2]
}

switch len(pathPieces) {
case 1:
Expand Down
27 changes: 27 additions & 0 deletions pkg/files/file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package files_test

import (
"carvel.dev/ytt/pkg/files"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func TestNewSortedFilesFromPaths(t *testing.T) {
inputPaths := []string{
"../yamltemplate/filetests/def.tpltest",
"https://example.org/test.yaml?hello=world&foo=bar",
"an/overwritten/path/to/file.yaml=https://example.org/test.yaml?hello=world&foo=bar"}
filesToProcess, err := files.NewSortedFilesFromPaths(inputPaths, files.SymlinkAllowOpts{true, []string{}})

require.NoError(t, err)

assert.Equal(t, filesToProcess[0].RelativePath(), "def.tpltest")
assert.Equal(t, filesToProcess[1].RelativePath(), "test.yaml")
assert.Equal(t, filesToProcess[1].Description(), "HTTP URL 'https://example.org/test.yaml?hello=world&foo=bar'")
assert.Equal(t, filesToProcess[2].RelativePath(), "an/overwritten/path/to/file.yaml")
assert.Equal(t, filesToProcess[2].Description(), "HTTP URL 'https://example.org/test.yaml?hello=world&foo=bar'")
}
4 changes: 3 additions & 1 deletion pkg/files/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func (s HTTPSource) Description() string {
return fmt.Sprintf("HTTP URL '%s'", s.url)
}

func (s HTTPSource) RelativePath() (string, error) { return path.Base(s.url), nil }
func (s HTTPSource) RelativePath() (string, error) {
return path.Base(strings.Split(s.url, "?")[0]), nil
}

func (s HTTPSource) Bytes() ([]byte, error) {
resp, err := s.Client.Get(s.url)
Expand Down

0 comments on commit faba705

Please sign in to comment.