diff --git a/internal/commands/push.go b/internal/commands/push.go index e84f126469..7213b3df6b 100644 --- a/internal/commands/push.go +++ b/internal/commands/push.go @@ -202,7 +202,7 @@ func pushLayers(ctx context.Context, pusher content.Pusher, policyPath, dataPath } for path, contents := range engine.Documents() { - data := []byte(contents) + data := []byte(contents.(string)) desc := content.NewDescriptorFromBytes(openPolicyAgentDataLayerMediaType, data) desc.Annotations = map[string]string{ ocispec.AnnotationTitle: path, diff --git a/policy/engine.go b/policy/engine.go index dc2f016fa2..62e40c608f 100644 --- a/policy/engine.go +++ b/policy/engine.go @@ -31,7 +31,7 @@ type Engine struct { compiler *ast.Compiler store storage.Store policies map[string]string - docs map[string]string + docs map[string]interface{} } type compilerOptions struct { @@ -137,26 +137,8 @@ func LoadWithData(policyPaths []string, dataPaths []string, capabilities string, return nil, fmt.Errorf("get documents store: %w", err) } - // FilteredPaths will recursively find all file paths that contain a valid document - // extension from the given list of data paths. - allDocumentPaths, err := loader.FilteredPaths(dataPaths, filter) - if err != nil { - return nil, fmt.Errorf("filter data paths: %w", err) - } - documentContents := make(map[string]string) - for _, documentPath := range allDocumentPaths { - contents, err := os.ReadFile(documentPath) - if err != nil { - return nil, fmt.Errorf("read file: %w", err) - } - - documentPath = filepath.Clean(documentPath) - documentPath = filepath.ToSlash(documentPath) - documentContents[documentPath] = string(contents) - } - engine.store = store - engine.docs = documentContents + engine.docs = documents.Documents return engine, nil } @@ -242,7 +224,7 @@ func (e *Engine) Namespaces() []string { // Documents returns all of the documents loaded into the engine. // The result is a map where the key is the filepath of the document // and its value is the raw contents of the loaded document. -func (e *Engine) Documents() map[string]string { +func (e *Engine) Documents() map[string]interface{} { return e.docs }