Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundle: Make the DirectoryLoader public #1902

Merged
merged 1 commit into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/pkg/errors"

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/internal/file"
"github.com/open-policy-agent/opa/util"
)

Expand Down Expand Up @@ -124,19 +123,18 @@ type ModuleFile struct {

// Reader contains the reader to load the bundle from.
type Reader struct {
loader file.DirectoryLoader
loader DirectoryLoader
includeManifestInData bool
}

// NewReader returns a new Reader.
// Deprecated: Use NewCustomReader with TarballLoader instead
// NewReader returns a new Reader which is configured for reading tarballs.
func NewReader(r io.Reader) *Reader {
return NewCustomReader(file.NewTarballLoader(r))
return NewCustomReader(NewTarballLoader(r))
}

// NewCustomReader returns a new Reader configured to use the
// specified DirectoryLoader.
func NewCustomReader(loader file.DirectoryLoader) *Reader {
func NewCustomReader(loader DirectoryLoader) *Reader {
nr := Reader{
loader: loader,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/file/loader.go → bundle/file.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package file
package bundle

import (
"archive/tar"
Expand Down
2 changes: 1 addition & 1 deletion internal/file/loader_test.go → bundle/file_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package file
package bundle

import (
"bytes"
Expand Down
9 changes: 4 additions & 5 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/bundle"
"github.com/open-policy-agent/opa/internal/file"
fileurl "github.com/open-policy-agent/opa/internal/file/url"
"github.com/open-policy-agent/opa/internal/merge"
"github.com/open-policy-agent/opa/storage"
Expand Down Expand Up @@ -147,16 +146,16 @@ func AsBundle(path string) (*bundle.Bundle, error) {
return nil, fmt.Errorf("error reading %q: %s", path, err)
}

var bundleLoader file.DirectoryLoader
var bundleLoader bundle.DirectoryLoader

if fi.IsDir() {
bundleLoader = file.NewDirectoryLoader(path)
bundleLoader = bundle.NewDirectoryLoader(path)
} else {
fh, err := os.Open(path)
if err != nil {
return nil, err
}
bundleLoader = file.NewTarballLoader(fh)
bundleLoader = bundle.NewTarballLoader(fh)
}

br := bundle.NewCustomReader(bundleLoader)
Expand Down Expand Up @@ -365,7 +364,7 @@ func loadFileForAnyType(path string, bs []byte) (interface{}, error) {
}

func loadBundleFile(bs []byte) (bundle.Bundle, error) {
tl := file.NewTarballLoader(bytes.NewBuffer(bs))
tl := bundle.NewTarballLoader(bytes.NewBuffer(bs))
br := bundle.NewCustomReader(tl).IncludeManifestInData(true)
return br.Read()
}
Expand Down