6675 Commits

Author SHA1 Message Date
Torin Sandall f6c0e82b08 Merge pull request #32 from tsandall/modules
Add basic module support
2016-05-09 15:24:07 -07:00
Torin Sandall 1f12942ec5 Clean up error messages
Eventually these should be wrapped to provide more information on the source
of the error.
2016-05-09 15:21:58 -07:00
Torin Sandall 77e86f08bb Fix indexed evaluation bug
Term evaluation was not plugging the expression before checking if the indexer
could be used. As a result, the index was being built on the unplugged version
of the expression which resulted in false positives being returned by the
indexer. Because the evaluation expects the indexer to provide exact matches,
the query evaluation was yielding false positives.

Also, made a slight tweak to the docs to make the example slightly clearer.
2016-05-09 15:21:58 -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
Torin Sandall e1b3180a27 Merge pull request #31 from tsandall/rename-lang
Rename the language to Rego
2016-05-09 09:00:38 -07:00
Torin Sandall 299606cdac Rename the language to Rego
Rego: Latin verb for rule/govern/control.
2016-05-09 08:56:55 -07:00
Torin Sandall 77a7845863 Merge pull request #30 from tsandall/basic-indexing
Add basic indexing support
2016-05-06 08:22:11 -07:00
Torin Sandall 81459dbade Add basic indexing support
Non-ground references are lazily indexed during evaluation if they are
contained in an equality expression where the other side is ground (or ground
after plugging the current bindings).

Updates to data that is indexed cause the built index to be dropped from the
indices.

The indexing supports exact match, reverse lookup using the ground value in
the expression. The result of the lookup is a set of bindings that when
plugged into the reference, result in the equality evaluating to true. In
this way, the indexing is not "lossy", i.e., it does not produce false matches
(positive or negative).
2016-05-04 15:27:58 -07:00
Torin Sandall 52bc6ad2cb Add github.com/pkg/errors and update deps 2016-05-04 15:16:02 -07:00
Torin Sandall 3d10912d98 Merge pull request #29 from tsandall/master
Remove broken submodule directories
2016-05-04 15:12:34 -07:00
Torin Sandall 7ef3742560 Remove broken submodule directories
These were accidentally added with the liner and termtables dependencies. They
do not appear to be needed. However, "go get github.com/open-policy-agent/opa"
fails because "git submodule init ..." is run and this fails to find the
.gitmodules file it expects.
2016-05-04 15:09:26 -07:00
Torin Sandall 7e621c68e6 Merge pull request #28 from tsandall/repl
Add REPL and miscellaneous fixes
2016-05-03 13:34:08 -07:00
Torin Sandall ffe9e58dd0 Miscellaneous fixes
1. Refs to rules that produce set or object docs were not being handled
correctly when the key value was a variable that had an existing binding. The
term evaluation code must check the bindings for variables it encounters while
processing references.

2. Refs to vars were not being handled correctly when the ref contained
variables that had existing bindings. This issue was similar to (1).

3. Refs to vars bound to arrays or objects with invalid indices/keys (e.g.,
out of range) were causing evaluation to panic. Invalid indices/keys are
now treated as undefined.

4. Header field composition wasn't taking objects and arrays into account.

5. An equality expr with vars on both sides will eval to true and the vars will
be unified. However, if this was the last expression in the body, the vars are
still non-ground and so the proof should not be considered successful.

6. Move traceSuccess call into evalExpr. This way it will be applied for all
built-ins automatically.

7. Address comments from PR #27:

- Rename isDefined to isTrue in evalContextNegated
- Add comment about substituting variables in partial set/object evaluation
- Add test cases involving multiple virtual docs and subsitution
2016-05-03 13:25:04 -07:00
Torin Sandall d1c3ca5191 Add basic run command
- Introduced new run command that lets users start an instance of OPA.
- Added basic REPL as first mode that can be run, server mode coming soon.
- Extended Storage to support a JSON Patch like interface.
2016-05-02 08:43:19 -07:00
Torin Sandall fcc9a3135d Merge pull request #27 from tsandall/virtual-docs
Fleshing out initial top down implementation
2016-05-02 08:35:43 -07:00
Torin Sandall ec7efe1a06 Add basic tracing support
Emit messages for four main steps of the evaluation process:

1. new expression (eval)
2. trying to evaluate a plugged expression (try)
3. successfully evaluated a plugged expression (success)
4. finished evaluating a query (finish)

Also refactored query interface slightly to take a params struct. This will be
a bit more future proof.
2016-04-20 09:44:38 -07:00
Torin Sandall 104852c1d8 Add support for negation 2016-04-19 17:04:30 -07:00
Torin Sandall 98a8621874 Add support for disjunction
- Refactored TopDownContext to contain a slice of expressions instead of a
rule. This will allow the TopDown algorithm to be readily used for ad-hoc
expressions.

- Refactored test cases to avoid duplicating test logic.
2016-04-19 16:04:56 -07:00
Torin Sandall 2b231addcb Add support for virtual docs
These changes extend the reference evaluation to support virtual docs, i.e.,
rules that reference other rules. The reference evaluation is extended so that
references to rules are evaluated and then the bindings are updated to map the
original reference to the output of the referenced rule (aka, the virtual
document).

Additional changes:

- Added support for references against variables.
- Added hashMap to store bindings. This is required because bindings can now
be variables or references.
- Added Query helper on Array and Object AST types.

Addressed comments from initial PR:

- Comments for future optimization
- Additional test cases
- Removed unnecessary branch from evalEqUnifyArrayRef
- Fixed evaluation of non-ground refs embedded inside objects/arrays.
- Renamed document kind enumeration values
2016-04-19 13:43:25 -07:00
Torin Sandall ee681a9553 Merge pull request #26 from tsandall/initial-topdown
Add beginning of top down evaluation
2016-04-18 14:00:26 -07:00
Torin Sandall 881b2afef8 Add beginning of top down evaluation
This is the initial implementation of the top down evaluation algorithm. It
has not be optimized at all and there are a few features that are still not
implemented.

The initial implementation handles:

- Evaluation of rules that produce object, set, and scalar documents.
- Equality built-in that unifies variables found in the operands.
- Basic helper modules (storage.go and compare.go) to assist evaluation.

This initial implementation does not include:

- Any type of tracing
- Negation
- Disjunction
- References against virtual documents or variables (i.e., only storage)
2016-04-14 15:25:00 -07:00
Torin Sandall 8f82805463 Merge pull request #25 from tsandall/add-coverage
Add Makefile target to run coverage
2016-04-13 18:03:49 -07:00
Torin Sandall cf1caf8b92 Add Makefile target to run coverage
For now the target fails because there are no tests for the "cmd" package.
Since this is being used manually for now, this is acceptable.
2016-04-13 18:00:51 -07:00
Torin Sandall 6b94279151 Update ROADMAP.md 2016-04-12 19:59:37 -07:00
Torin Sandall c36ad91608 Merge pull request #24 from tsandall/initial-grammar
Flesh out the grammar
2016-04-07 16:58:53 -07:00
Torin Sandall 72feff583c Flesh out the grammar
- Added expressions, packages, imports, rules, and modules to grammar
- Added support for comments
- Added a few failure cases to strings, arrays, and objects
- Added IsGround interface to terms
2016-04-07 16:55:20 -07:00
Torin Sandall 9e0fdd7b2e Merge pull request #23 from tsandall/linting
Add Makefile targets to lint and fix errors
2016-04-05 10:28:43 -07:00
Torin Sandall 1931ea2456 Add Makefile targets to lint and fix errors
Added golint dependency.
2016-04-05 10:26:07 -07:00
Torin Sandall ef31b1e7c9 Merge pull request #21 from tsandall/fix-packages
Fix package dependencies
2016-04-04 10:58:26 -07:00
Torin Sandall 3d9fd53b26 Fix package dependencies
Glide was warning about the glide.lock file being out-of-date.
2016-04-04 10:46:37 -07:00
Torin Sandall 9c4b43c288 Merge pull request #20 from tsandall/add-references
Add references to the grammar
2016-04-02 12:07:43 -07:00
Torin Sandall 157e4f083a Add references to the grammar
The special iterator variable ("_") is not supported yet. The _ variable will
be handled by mangling the variable name while parsing the rules (which are
still to come).

Also refactored terms to use type declaration and type switches. All terms are
now represented by underlying Go types without relying on extra structs. The
Kind attribute on Term has been removed in favour of type switches.

Lastly, removing the generated parser from the repository for now. Once the
grammar has stabilized, we can add the generated code back. The diffs were
unpleasant.
2016-04-02 12:03:31 -07:00
Torin Sandall a2ff4234c3 Merge pull request #19 from tsandall/opalog-grammar
Add variables to the grammar
2016-03-31 13:55:54 -07:00
Torin Sandall 8ed63b76dd Add variables to the grammar
This change set also includes a bit of refactoring:

- Renamed jsonlog to opalog
- Renamed Dictionary to Object
- Split AST into separate files
- Tweaked parser definition to separate terms with whitespace
- Renamed helper functions in parser_test.go to distinguish from cases
- Moved reflection helper into test suite and renamed
- Modified Term.String() to make output more readable
- Reorganized the grammar file
- Allow scalars and variables as object keys. We will deal with this when
serializing to JSON.
2016-03-31 13:51:33 -07:00
Torin Sandall feaa302fce Merge pull request #18 from tsandall/mechanics
Updates to infrastructure and some documentation on process
2016-03-30 09:04:49 -07:00
Torin Sandall e2297a7833 Basic infrastructure and process documentation
- Updated source code layout to use standard Go project structure.
- Makefile for build and test execution.
- Glide for dependency management.
- Integrated spf13/cobra for command line entry point.
- Added docs on release and development process.
2016-03-30 08:58:21 -07:00
Tim Hinrichs 50cc2891cb Merge pull request #17 from tsandall/set-clarity
Refined set syntax and more
2016-03-28 13:30:49 -07:00
Torin Sandall d5fe834688 Merge pull request #9 from tsandall/initial-roadmap
Add initial ROADMAP with potential features
2016-03-24 16:52:35 -07:00
Torin Sandall 012a2ac522 Add initial ROADMAP document 2016-03-24 16:50:48 -07:00
Torin Sandall d42bf835bb Refine set syntax and more
The main changes are:

Removed the overloading of the equality operator to do set membership tests
and updated set generation syntax to align with the new membership test
syntax.

Also, got rid of the "[]" syntax in references and replaced with special "_"
character that is treated as a special iterator. Documented this behaviour in
the references section.

Also, fixed semantics so that document content is defined in terms of the rule
head which is in turn defined by instances of the body that evaluate to true.
E.g., instead of "p :- 7", we now write "p = 7", which is short for "p = 7 :-
true".
2016-03-24 16:31:28 -07:00
Torin Sandall 86672fab14 Updating data-model-logical.svg 2016-03-24 16:20:21 -07:00
Torin Sandall dc7871b176 Merge pull request #10 from tsandall/language-ref
Add initial version of the language reference
2016-03-24 11:47:57 -07:00
Torin Sandall 6f1f0de27c Add initial version of the language reference
This covers language introduction, grammar, basics, and details on various
aspects of Opalog:

- Scalar values
- Composite values
- Variables
- References
- Rules
- Generating sets
- Generating objects
- Incremental definitions
- Negation
- Modules
- Packages
- Imports
- Comments
- Example data
2016-03-24 11:43:24 -07:00
Torin Sandall 149783f4d5 Merge pull request #16 from tsandall/fix-typos
Fix typos
2016-03-23 14:37:40 -07:00
Torin Sandall 01f7a592a7 Fix typos 2016-03-23 14:35:34 -07:00
Torin Sandall 190b73984f Add ignore for Visual Studio Code 2016-03-23 14:32:38 -07:00
Torin Sandall e2e4c1cab8 Merge pull request #15 from tsandall/fix-images
Fix images
2016-03-17 23:14:08 -07:00
Torin Sandall 903ce87f06 Lock SVGs to commit and use CDN 2016-03-17 23:13:52 -07:00
Torin Sandall 9f5f1e6fa6 Attempting to fix SVGs 2016-03-17 22:55:10 -07:00
Torin Sandall a8e70aa99d Merge pull request #14 from tsandall/logical-data-model
Add logical data model diagram
2016-03-17 19:32:21 -07:00