Skip to content

Commit e6b295b

Browse files
authored
chore(pkg): Only download material if 200 (#1871)
Signed-off-by: Javier Rodriguez <[email protected]>
1 parent 4f6ec22 commit e6b295b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/resourceloader/resourceloader.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ func loadResourceFromURLOrEnv(resourcePath string) ([]byte, error) {
7373
// loadFromURL loads the content of a URL and returns it as a byte slice.
7474
func loadFromURL(url string) ([]byte, error) {
7575
// As cosign does: https://github.com/sigstore/cosign/blob/beb9cf21bc6741bc6e6b9736bdf57abfb91599c0/pkg/blob/load.go#L47
76+
// By default it will attempt a maximum 10 redirects
7677
// #nosec G107
7778
resp, err := http.Get(url)
7879
if err != nil {
7980
return nil, fmt.Errorf("requesting URL: %w", err)
8081
}
8182
defer resp.Body.Close()
8283

84+
// Check if the response is OK
85+
if resp.StatusCode != http.StatusOK {
86+
return nil, fmt.Errorf("loading URL: %s", resp.Status)
87+
}
88+
8389
raw, err := io.ReadAll(resp.Body)
8490
if err != nil {
8591
return nil, fmt.Errorf("loading URL response: %w", err)

0 commit comments

Comments
 (0)