|
8 | 8 | "net/http"
|
9 | 9 | "net/url"
|
10 | 10 | "os"
|
| 11 | + "path/filepath" |
11 | 12 |
|
12 | 13 | "github.com/operator-framework/operator-registry/pkg/image"
|
13 | 14 | "k8s.io/apimachinery/pkg/util/yaml"
|
@@ -85,15 +86,21 @@ type HttpGetter interface {
|
85 | 86 | // FetchCatalogConfig will fetch the catalog configuration file from the given path.
|
86 | 87 | // The path can be a local file path OR a URL that returns the raw contents of the catalog
|
87 | 88 | // configuration file.
|
| 89 | +// The filepath can be structured relative or as an absolute path |
88 | 90 | func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, error) {
|
89 | 91 | var tempCatalog io.ReadCloser
|
90 | 92 | 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) { |
92 | 97 | tempCatalog, err = os.Open(path)
|
93 | 98 | if err != nil {
|
94 | 99 | return nil, fmt.Errorf("opening catalog config file %q: %v", path, err)
|
95 | 100 | }
|
96 | 101 | } else {
|
| 102 | + // Evalute remote catalog config |
| 103 | + // If URi is valid, execute fetch |
97 | 104 | tempResp, err := httpGetter.Get(catalogURI.String())
|
98 | 105 | if err != nil {
|
99 | 106 | return nil, fmt.Errorf("fetching remote catalog config file %q: %v", path, err)
|
|
0 commit comments