mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
2f99f291ce
- 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
55 lines
1023 B
Go
55 lines
1023 B
Go
// Copyright 2016 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package runtime
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/open-policy-agent/opa/eval"
|
|
)
|
|
|
|
// Params stores the configuration for an OPA instance.
|
|
type Params struct {
|
|
Server bool
|
|
Paths []string
|
|
HistoryPath string
|
|
}
|
|
|
|
// Runtime represents a single OPA instance.
|
|
type Runtime struct {
|
|
Store *eval.Storage
|
|
}
|
|
|
|
// Start is the entry point of an OPA instance.
|
|
func (rt *Runtime) Start(params *Params) {
|
|
|
|
store, err := eval.NewStorageFromFiles(params.Paths)
|
|
|
|
if err != nil {
|
|
fmt.Println("failed to open storage:", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
rt.Store = store
|
|
|
|
if !params.Server {
|
|
rt.runRepl(params)
|
|
} else {
|
|
rt.runServer(params)
|
|
}
|
|
}
|
|
|
|
func (rt *Runtime) runServer(params *Params) {
|
|
fmt.Println("not implemented: server mode")
|
|
os.Exit(1)
|
|
}
|
|
|
|
func (rt *Runtime) runRepl(params *Params) {
|
|
|
|
repl := NewRepl(rt, params.HistoryPath, os.Stdout)
|
|
repl.Loop()
|
|
}
|