Skip to content

Commit 87c0b28

Browse files
author
Ish Shah
authored
[BUGFIX] Allow absolute filepaths for resolving catalog config (#1128)
* Add absolute filepath check in uri checker Signed-off-by: Ish Shah <[email protected]> * Add docs/notes for future maintaining Signed-off-by: Ish Shah <[email protected]> * add abs path tests Signed-off-by: Ish Shah <[email protected]> * fix path Signed-off-by: Ish Shah <[email protected]> * fix error string Signed-off-by: Ish Shah <[email protected]> * abs path test cleared Signed-off-by: Ish Shah <[email protected]> * add failure test Signed-off-by: Ish Shah <[email protected]> * add error msg Signed-off-by: Ish Shah <[email protected]> * add should error Signed-off-by: Ish Shah <[email protected]> * remove redundant tests Signed-off-by: Ish Shah <[email protected]> * comment nit --------- Signed-off-by: Ish Shah <[email protected]>
1 parent a71ca09 commit 87c0b28

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

alpha/template/composite/composite.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"net/url"
1010
"os"
11+
"path/filepath"
1112

1213
"github.com/operator-framework/operator-registry/pkg/image"
1314
"k8s.io/apimachinery/pkg/util/yaml"
@@ -85,15 +86,21 @@ type HttpGetter interface {
8586
// FetchCatalogConfig will fetch the catalog configuration file from the given path.
8687
// The path can be a local file path OR a URL that returns the raw contents of the catalog
8788
// configuration file.
89+
// The filepath can be structured relative or as an absolute path
8890
func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, error) {
8991
var tempCatalog io.ReadCloser
9092
catalogURI, err := url.ParseRequestURI(path)
91-
if err != nil {
93+
// Evalute local catalog config
94+
// URI parse will fail on relative filepaths
95+
// Check if path is an absolute filepath
96+
if err != nil || filepath.IsAbs(path) {
9297
tempCatalog, err = os.Open(path)
9398
if err != nil {
9499
return nil, fmt.Errorf("opening catalog config file %q: %v", path, err)
95100
}
96101
} else {
102+
// Evalute remote catalog config
103+
// If URi is valid, execute fetch
97104
tempResp, err := httpGetter.Get(catalogURI.String())
98105
if err != nil {
99106
return nil, fmt.Errorf("fetching remote catalog config file %q: %v", path, err)

alpha/template/composite/composite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ func TestFetchCatalogConfig(t *testing.T) {
540540
assertions func(t *testing.T, rc io.ReadCloser, err error)
541541
}
542542

543+
testDir := t.TempDir()
544+
543545
testCases := []testCase{
544546
{
545547
name: "Successful HTTP fetch",
@@ -569,7 +571,8 @@ func TestFetchCatalogConfig(t *testing.T) {
569571
name: "Successful file fetch",
570572
path: "file/test.yaml",
571573
fakeGetter: &fakeGetter{
572-
catalog: validCatalog,
574+
catalog: validCatalog,
575+
shouldError: true,
573576
},
574577
createFile: true,
575578
assertions: func(t *testing.T, rc io.ReadCloser, err error) {
@@ -591,8 +594,6 @@ func TestFetchCatalogConfig(t *testing.T) {
591594
},
592595
}
593596

594-
testDir := t.TempDir()
595-
596597
for _, tc := range testCases {
597598
t.Run(tc.name, func(t *testing.T) {
598599
filepath := tc.path

0 commit comments

Comments
 (0)