Commit Graph

47 Commits

Author SHA1 Message Date
Brendan Devenney 433216a786 Make eval command's data flag repeatable
This allows the specification of multiple data/policy files, mirroring
the old behaviour of the run command's eval flag.

Resolves #713.

Signed-off-by: Brendan Devenney <brendan.devenney@cloudreach.com>
2018-04-28 11:04:55 -07:00
Torin Sandall b4c94fc108 Fix check subcommand parse error printing
The check subcommand was not formatting parse errors as JSON if
requested. Also, since the loader package returns a set of errors, parse
errors are unpacked to avoid double nesting.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-09 09:51:00 -07:00
Torin Sandall 75c7fefa0e Fill in eval subcommand help text
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-08 12:41:09 -07:00
Torin Sandall 484c68a20b Add JSON output format to check subcommand 2018-03-19 11:24:04 -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
Torin Sandall 966eaac912 Add cover package and enhance test subcommand 2018-03-13 11:52:02 -07:00
Torin Sandall 39cc4ef87f Add eval subcommand to run queries
With opa eval, the --eval flag on opa run is redundant and can be
removed.
2018-03-12 18:14:32 -07:00
Torin Sandall 2b3b3faeed Add parse subcommand to print AST of input 2018-03-12 18:14:32 -07:00
Torin Sandall 49df455339 Update check subcommand to error on empty input 2018-03-12 18:14:32 -07:00
Torin Sandall 3938a3a5b1 Add JSON format to test command 2018-03-12 18:14:32 -07:00
Torin Sandall ece1bb6d38 Refactor test runner to accept Store argument
This allows testers to provide input data in raw JSON/YAML files as
opposed to copying them into Rego files.
2017-09-20 09:43:32 -07:00
Torin Sandall 05e9eb601c Refactor diagnostics support in server and runtime
- These changes update the server to always report performance metrics
  and the remote client address. The metrics are cheap to compute and
  there is no significant reason to require more complex configuration
  at this point.

- These changes update the runtime to allow callers to supply the
  diagnostics buffer implementation. This way callers can hook up their
  own sinks to the server's diagnostics.
2017-09-19 15:54:26 -07:00
Torin Sandall 9570a4acc7 Refactor runtime to separate init and start
Previously, the runtime could only be initialized and started in one
shot. In some cases, callers want to be able to separate these into two
steps, especially since the start call will block.
2017-09-19 12:06:18 -07:00
Torin Sandall 80dfee89b5 Add stdin mode to opa fmt 2017-09-14 08:35:39 -07:00
Torin Sandall 8019c7e6be Remove backup creation from fmt subcommand
Overwriting is not the default and policies are usually stored in a VCS.
As a result, the backup files are not likely to be needed.
2017-09-12 17:28:49 -07:00
Torin Sandall 003c630bec Add new opa test sub-command
These changes add a new sub-command to execute policy tests.

Fixes #428
2017-09-07 11:40:22 -07:00
Torin Sandall 9ab9d8913d Refactor commands to namespace parameters 2017-09-07 11:40:22 -07:00
Torin Sandall 9b743d527f Refactor error limit flag
Avoid duplicating the flag description in each command that requires it.
2017-09-07 11:40:22 -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 1cb62879e5 Tweak one line descriptions of check and fmt 2017-09-07 11:40:22 -07:00
Matthew Mussomele 93e408b290 Make the server's diagnostics buffer size configurable 2017-08-08 15:45:12 -07:00
Matthew Mussomele d4edbf8454 Properly remove temporary files when running opa fmt -d
When computing diffs, `opa fmt` created temporary files in order to use
the diff utility. However, it did not properly clean up after itself,
leaving these temporary files behind.
2017-07-25 17:56:57 -07:00
Matthew Mussomele ca783539f8 Add support to cancel compilation after some number of errors
Sometimes compiling large policies with many errors causes more output
errors than is easily sorted through. The compiler has been updated to
cancel after a configurable number of errors (default no limit), and the
server, repl and check command support options for setting that limit.
2017-07-21 07:59:51 -07:00
Matthew Mussomele 2a001ef1c7 Correct opa fmt panic on missing files
If the provided file name does not exist, `opa fmt` would panic
due to filepath.Walk passing in a nil `os.FileInfo`. The WalkFunc
now checks the incoming error properly to catch this case.
2017-07-06 09:31:40 -07:00
Matthew Mussomele a204d79989 Only output filenames when -l is passed to 'opa fmt'
If the -l flag was used without the -w flag also being supplied,
the filenames would be lost in the output. Now, if -l is supplied,
any writes to stdout will be discarded, causing only the filenames
to be displayed.
2017-06-30 10:51:10 -04:00
Matthew Mussomele 2c4c433e7a Implement CLI for opa format 2017-06-29 13:10:36 -04:00
Matthew Mussomele ee50506743 Add check command to verify that modules parse and compile 2017-06-28 22:46:55 -04:00
Torin Sandall 3ced77412e Remove dead code from run command
The --policy-dir option was removed a while ago. Forgot to remove the
relevant helpers in the run command.
2017-06-23 13:18:15 -07:00
Torin Sandall b1fc681590 Remove persist/--policy-dir option
This is the first in series of Spring cleaning around the storage layer.
In the near future we will add local disk-based persistence support to
OPA. That support will handle storage of source files.

The --policy-dir option is almost entirely unused today. Removing it
will make it easier to get rid of the policyStore entirely.

The next thing to do will be to remove the specialized *Policy methods
from the storage layer. This way the storage layer can just accept
policies as normal data.

If policies need to be persisted until then, users can treat the
policies as config files and manage them outside of OPA.
2017-03-12 13:23:22 -07:00
Torin Sandall 6cdcb31f43 Add support for additional HTTP listener
Fixes #289
2017-03-12 12:04:35 -07:00
Torin Sandall 7d7d2912ae Replace glog with logrus 2017-03-12 12:04:35 -07:00
Torin Sandall bd39684341 Remove erroneous flag.Parse() call 2017-03-12 12:04:35 -07:00
Torin Sandall 96aad95475 Add identifier and authorizer to server 2017-02-22 14:49:21 -08:00
Torin Sandall 18ba055449 Add support for server-side HTTPS 2017-02-21 20:00:38 -08:00
Torin Sandall 83200a98e5 Update cmd with request changes 2016-12-19 09:59:04 -08:00
Torin Sandall ce7b9743ff Improve file loading support
These changes add support for recursively loading files from directories and
rooting data files at arbitrary locations in the global document.

Fixes #163
2016-11-25 16:27:48 -08:00
Torin Sandall 55768aba53 Add command line flag to eval, print, and exit
Can now evaluate queries from the command line, for example:

$ opa run -f json -e 'data.repl.version[x] = y'

Fixes #152
2016-11-25 10:27:01 -08:00
Torin Sandall 1eaceaab6a Add -w/--watch flag to OPA
If the watch flag is given (and OPA is running as an interactive shell), OPA
will watch the the command line files for changes. When the files change, OPA
will attempt to reload them.

This should improve the UX for people authoring policies as now they can run
the REPL against their policies and data and see changes reflected without
restarting the REPL.
2016-10-24 15:18:57 -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 cb502a36b3 Update OPA "policy enable" tag line
With the site refresh, we have begun referring to services being policy
enabled instead of applications. These changes just update a few spots that
were not touched in the refresh.
2016-08-02 09:31:01 -07:00
Torin Sandall 0687fe3dbd Add knob to control output format in REPL
Add support for JSON output format in addition to pretty format. Pretty
format is nice but sometimes data sets/queries are not well suited for it.
2016-05-25 16:36:13 -07:00
Torin Sandall 9333034606 Integrate github.com/golang/glog 2016-05-14 09:59:39 -07:00
Torin Sandall 12dad370d5 Add basic REST API support to server mode
- REST APIs

    * CRUDL on policy modules
    * Ad-hoc queries
    * Query and patch base documents
    * Query virtual documents

- Add PolicyStore to manage policy definition/module CRUDL operations.

    * Supports persistence of policy definitons.
    * Serve REST API CRUDL operations.
    * Manage install/uninstall of rules into data store.
    * Manage persistence of policy definitions.

- Misc. refactoring

    * Move storage creation into runtime Init.
    * Make AST types JSON serializable. Tweaked ast.Import to use Term instead
    of Value for the path.
2016-05-13 15:34:02 -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 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 1931ea2456 Add Makefile targets to lint and fix errors
Added golint dependency.
2016-04-05 10:26:07 -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