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

Function GetPathForResource

pkg/resourceloader/resourceloader.go:41–54  ·  view source on GitHub ↗

GetPathForResource tries to load a file or URL from the given path. If the path starts with "http://" or "https://", it will try to load the file from the URL and save it in a temporary file. It will return the path to the temporary file. If the path is an actual file path, it will return the filepa

(resourcePath string)

Source from the content-addressed store, hash-verified

39// in a temporary file. It will return the path to the temporary file.
40// If the path is an actual file path, it will return the filepath
41func GetPathForResource(resourcePath string) (string, error) {
42 if _, err := os.Stat(resourcePath); err == nil {
43 return resourcePath, nil
44 }
45
46 // Try to load the resource from a URL
47 raw, err := loadResourceFromURLOrEnv(resourcePath)
48 if err != nil {
49 return "", fmt.Errorf("loading resource: %w", err)
50 }
51
52 // If the resource is loaded from a URL, save it in a temporary file
53 return createTempFile(resourcePath, raw)
54}
55
56func loadResourceFromURLOrEnv(resourcePath string) ([]byte, error) {
57 parts := strings.SplitAfterN(resourcePath, "://", 2)

Callers 4

LookupFunction · 0.92
newAttestationAddCmdFunction · 0.92
resolvePolicyInputFilesFunction · 0.92

Calls 2

loadResourceFromURLOrEnvFunction · 0.85
createTempFileFunction · 0.85

Tested by

no test coverage detected