Skip to content

Commit

Permalink
bundle: Make the DirectoryLoader public
Browse files Browse the repository at this point in the history
Previously we had it in an internal package but used by a public API,
which basically means it can't actually be used outside of OPA.
Initial thinking was that this was an OK situation, but by popular
demand we are making it available to everyone so OPA as a lib users
can use the bundle loading API's.

Fixes: #1840
Signed-off-by: Patrick East <east.patrick@gmail.com>
  • Loading branch information
patrick-east committed Nov 14, 2019
1 parent cdcebd8 commit 8688bc0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
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

0 comments on commit 8688bc0

Please sign in to comment.