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

Function LoadFileOrURL

app/cli/pkg/action/util.go:32–53  ·  view source on GitHub ↗

LoadFileOrURL loads a file from a local path or a URL

(fileRef string)

Source from the content-addressed store, hash-verified

30
31// LoadFileOrURL loads a file from a local path or a URL
32func LoadFileOrURL(fileRef string) ([]byte, error) {
33 parts := strings.SplitAfterN(fileRef, "://", 2)
34 if len(parts) == 2 {
35 scheme := parts[0]
36 switch scheme {
37 case "http://":
38 fallthrough
39 case "https://":
40 // #nosec G107
41 resp, err := http.Get(fileRef)
42 if err != nil {
43 return nil, err
44 }
45 defer resp.Body.Close()
46 return io.ReadAll(resp.Body)
47 default:
48 return nil, errors.New("invalid file scheme")
49 }
50 }
51
52 return os.ReadFile(filepath.Clean(fileRef))
53}
54
55// ValidateAndExtractName validates and extracts a name from either
56// an explicit name parameter OR from metadata.name in the file content.

Callers 7

newWorkflowCreateCmdFunction · 0.92
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
ValidateAndExtractNameFunction · 0.85

Calls 2

GetMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected