MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / loadFromURL

Function loadFromURL

pkg/resourceloader/resourceloader.go:74–94  ·  view source on GitHub ↗

loadFromURL loads the content of a URL and returns it as a byte slice.

(url string)

Source from the content-addressed store, hash-verified

72
73// loadFromURL loads the content of a URL and returns it as a byte slice.
74func loadFromURL(url string) ([]byte, error) {
75 // 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
77 // #nosec G107
78 resp, err := http.Get(url)
79 if err != nil {
80 return nil, fmt.Errorf("requesting URL: %w", err)
81 }
82 defer resp.Body.Close()
83
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
89 raw, err := io.ReadAll(resp.Body)
90 if err != nil {
91 return nil, fmt.Errorf("loading URL response: %w", err)
92 }
93 return raw, nil
94}
95
96// loadFromEnv loads the content of an environment variable and returns it as a byte slice.
97func loadFromEnv(envVar string) ([]byte, error) {

Callers 1

loadResourceFromURLOrEnvFunction · 0.85

Calls 2

GetMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected