Commit Graph

22 Commits

Author SHA1 Message Date
Patrick East c2d2d1b7fa Remove extra character in util/close.go
Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-07-31 03:43:38 -04:00
Varun Mathur 8885997264 Added ability to dynamically load .so objects and the respective required testing.
Signed-off-by: Varun Mathur <varun.mathur@live.com>
2018-08-16 13:11:49 -07:00
Stephan Renatus 38dd5a8110 json_test: add util.Reference test
Left this as an extra commit for now, as I'm not sure if you'd think it's of
much value... will squash or drop accordingly.

Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-05-15 08:57:12 -07:00
Stephan Renatus 004e6a80e7 storage/inmem: support pointers to structs
This should fix #722. It's a slight variation of the code snippet provided
there:

I wasn't sure what the reflect.Interface part was for, so this is using
only reflect.Ptr. Also, there existing tests would fail without the added
check for reflect.Invalid.

Adds a test case for inmem -- in a new method, as I couldn't quite fit it
into the schema of TestInMemoryWrite.

Also, util.Reference() ensures that the returned value is a pointer to
something -- and not a pointer to a pointer to something. While this wasn't
part of the issue #722, it felt weird not to solve the general problem, but
only the edge case. :)

Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-05-15 08:57:12 -07:00
Teemu Koponen 59976cf20a Fix error formatting in test.
Signed-off-by: Teemu Koponen <koponen@styra.com>
2018-04-28 10:58:00 -07:00
Torin Sandall f131cfcff3 Add support for bundle downloading
Previously, policies and data had to be pushed into OPA via the REST API
or loaded via command line arguments at startup.

With these changes, OPA can now be configured to pull down bundles of
policy and data from remote HTTP servers. When a bundle is downloaded
successfully, the policies and data are loaded out of the bundle file
and inserted into storage.
2018-03-16 08:51:37 -07:00
Stephan Renatus bb05fb8067 util.RoundTrip(): use neighbouring UnmarshalJSON function
The test failures this had introduced before, from index_tests.go's
TestIndicesBuild, suggested that this is probably what we want.

Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-03-13 09:35:14 -07:00
Stephan Renatus 5b07711891 ast: allow passing in []string, not only []interface{}
With this, where before we've gotten

    ast: illegal value: []string

and had worked around it by converting all our []string inputs to
[]interface{}, it now would work to pass in the []string values as-is.

This adds a roundtrip through the JSON encoding to both the rego.Input,
and the inmem store's Write.

Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-03-13 09:35:14 -07:00
Torin Sandall c612260af4 Refactor file loading for OPA
The file loading logic implemented in the runtime package is generally
useful within OPA. These changes factor the file loading into a separate
package that can be reused without taking a dependency on the runtime.
2017-09-07 11:40:22 -07:00
Torin Sandall 18b2e363bd Refactor rule graph 2017-04-26 15:04:48 -07:00
Torin Sandall cf56ae2c23 Add BFS traversal and refactor DFS 2017-04-26 15:04:48 -07:00
Torin Sandall 7077019d6e Add basic LIFO and FIFO structures 2017-04-26 15:04:48 -07:00
Torin Sandall 21c9a9b2b7 Add utility for enumerated cmdline args 2017-02-22 14:49:21 -08:00
Torin Sandall f2d3625d26 Add basic REST API authorization benchmark 2017-02-03 09:02:22 -08:00
Torin Sandall fe25593707 Update underlying number representation
These changes modify OPA to use json.Number to represent number values in
storage and the AST. Comparisons and numeric operations are handled by the
math/big package. Using json.Number avoids loss of precision when loading
integers greater than 2**53 and use of math/big avoids need for type
conversions in the built-in implementations. In the long run, the math/big
usage may be replaced with specific paths for smaller numbers.

Fixes #154
2016-12-05 15:30:38 -08:00
Torin Sandall 7c4cd38e89 Add subtest utility and apply in topdown
Go 1.7 makes sub-tests available in the testing framework. Among other things,
the sub-tests are nice because they can be run directly from the command line.
2016-08-30 12:06:47 -07:00
Torin Sandall d539b32064 Add package level GoDoc descriptions
Provide a high level description of ast and topdown packages as these are
currently the core of the project. We can flesh out the other package
descriptions as necessary.
2016-08-02 16:57:15 -07:00
Torin Sandall 1ecb93ad3d Optimization: Remove copying of bindings
Instead of copying the bindings each time a binding is added, return an object
that can be used to undo the binding at the end of the proof.
2016-07-12 08:49:38 -07:00
Torin Sandall 480281741b Address PR comments
- Refactored the checkSafetyBody function

    * Moved reordering into separate function with well defined interface.

    * Replaced ad-hoc maps to track sets of Vars with VarSet.

    * Added helper functions to get Vars on expressions, rules, etc. This
      makes the re-ordering much clearer.

- Updated test cases for DFS and re-ordering.

- Added comment in DFSTraversal to help callers consider whether
  the Visited state needs to be reset.

Also, fixed two separate bugs:

- When computing output variables in positions that unify recursively,
variable object keys should not be included (as the unification implementation
won't unify these.)

- When computing output variables, variables found in references (other than
the head) WILL be bound, so they should be included in the result. For
example:

> a = [1,2,3], a[i] != 2

In this case, "i" will be bound so it should be included in the output
variables for the expression.
2016-05-25 16:36:14 -07:00
Torin Sandall c5d8f52d5d Add recursion check
Also, add utility to perform DFS traversals.
2016-05-18 12:56:10 -07:00
Torin Sandall 3dc5a3ef33 Move compare.go into util package 2016-05-13 15:58:32 -07:00
Torin Sandall 2f99f291ce Add basic support for modules
- Basic compiler framework with a few steps to resolve references
- Extend runtime to support loading policies
- Update evaluation to deal with resolved references

    * Store calls (e.g., Patch, Get) expect paths. It's assumed that the path
    has had the "data" prefix removed.

    * The top level query interface expects paths so the "data" prefix is
    added before calling into the actual TopDown implementation.

    * The head of a reference can be used to determine whether it refers to a
    local variable or a document in the db.

    * Updates to misc. test helpers to preserve existing structure. Implicitly
    import top-level documents, rename local variables to avoid conflicts,
    etc.

- Refactor reference evaluation

    * Remove special casing around first reference term.

    This was what prevented embedded virtual doc references from working
    immediately. Previously, the code assumed that the first term in the
    reference identified the virtual doc/rule. This was an over simplification
    that worked while the initial implementation was in progress. Now that
    modules are supported, virtual docs/rules may be embedded at arbitrary
    depths, e.g., "data.a.b.c[i].d[j]" where "c" is the rule name and
    "a.b" is the package containing the rule.

    * Break up the reference valuation into smaller functions.
    * Reorder ref/path arguments
    * Rename path/ref to path/tail respectively

- Separate test case for embedded virtual docs.

Also, a few misc. changes:

- Fix Ref.String() in empty case.
- Refactor hashMap into separate package.
- Get rid of ad-hoc FNV implementation. Use the one from the stdlib!
- Refactored parsing helpers from eval into ast
2016-05-09 15:19:55 -07:00