MCPcopy
hub / github.com/open-policy-agent/gatekeeper / ReadSources

Function ReadSources

pkg/gator/reader/filereader.go:16–46  ·  view source on GitHub ↗
(filenames []string, images []string, tempDir string)

Source from the content-addressed store, hash-verified

14var allowedExtensions = []string{gator.ExtYAML, gator.ExtYML, gator.ExtJSON}
15
16func ReadSources(filenames []string, images []string, tempDir string) ([]*unstructured.Unstructured, error) {
17 var sources []*source
18
19 // Read from --filename flag
20 s, err := readFiles(filenames)
21 if err != nil {
22 return nil, fmt.Errorf("reading from filenames: %w", err)
23 }
24 sources = append(sources, s...)
25
26 // Read from --image flag
27 s, err = readImages(images, tempDir)
28 if err != nil {
29 return nil, fmt.Errorf("pulling image: %w", err)
30 }
31 sources = append(sources, s...)
32
33 // Read stdin
34 stdinUnstructs, err := readStdin()
35 if err != nil {
36 return nil, fmt.Errorf("reading from stdin: %w", err)
37 }
38 sources = append(sources, &source{stdin: true, objs: stdinUnstructs})
39
40 conflicts := detectConflicts(sources)
41 for i := range conflicts {
42 logConflict(&conflicts[i])
43 }
44
45 return sourcesToUnstruct(sources), nil
46}
47
48func readImage(image string, tempDir string) ([]*source, error) {
49 dirPath, closeHandler, err := oci.PullImage(image, tempDir)

Callers 4

RunFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92

Calls 6

readFilesFunction · 0.85
readImagesFunction · 0.85
readStdinFunction · 0.85
detectConflictsFunction · 0.85
logConflictFunction · 0.85
sourcesToUnstructFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…