Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename the language to Rego #31

Merged
merged 1 commit into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store
.vscode
opa
opalog/parser.go
ast/parser.go
coverage
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# license that can be found in the LICENSE file.

PACKAGES := \
github.com/open-policy-agent/opa/ast/.../ \
github.com/open-policy-agent/opa/cmd/.../ \
github.com/open-policy-agent/opa/eval/.../ \
github.com/open-policy-agent/opa/opalog/.../ \
github.com/open-policy-agent/opa/runtime/.../

BUILD_COMMIT := $(shell ./build/get-build-commit.sh)
Expand Down
6 changes: 3 additions & 3 deletions opalog/parser_ext.go → ast/parser_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

// This file contains extra functions for parsing Opalog.
// This file contains extra functions for parsing Rego.
// Most of the parsing is handled by the auto-generated code in
// parser.go, however, there are additional utilities that are
// helpful for dealing with Opalog source inputs (e.g., REPL
// helpful for dealing with Rego source inputs (e.g., REPL
// statements, source files, etc.)

package opalog
package ast

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion opalog/parser_test.go → ast/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package opalog
package ast

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions opalog/policy.go → ast/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package opalog
package ast

import "fmt"
import "strings"
Expand Down Expand Up @@ -43,7 +43,7 @@ type (
Alias Var
}

// Rule represents a rule as defined by Opalog. Rules define the
// Rule represents a rule as defined in the language. Rules define the
// content of documents that represent policy decisions.
Rule struct {
Location *Location
Expand Down
2 changes: 1 addition & 1 deletion opalog/policy_test.go → ast/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package opalog
package ast

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion opalog/opalog.peg → ast/rego.peg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
package opalog
package ast

//
// BUGS: the escaped forward solidus (`\/`) is not currently handled for strings.
Expand Down
10 changes: 5 additions & 5 deletions opalog/term.go → ast/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package opalog
package ast

import "fmt"
import "regexp"
Expand Down Expand Up @@ -205,7 +205,7 @@ func (str String) Hash() int {
return stringHash(string(str))
}

// Var represents a variable as defined by Opalog.
// Var represents a variable as defined by the language.
type Var string

// VarTerm creates a new Term with a Variable value.
Expand Down Expand Up @@ -238,7 +238,7 @@ func (variable Var) String() string {
return string(variable)
}

// Ref represents a reference as defined by Opalog.
// Ref represents a reference as defined by the language.
type Ref []*Term

// EmptyRef returns a new, empty reference.
Expand Down Expand Up @@ -353,7 +353,7 @@ func (ref Ref) Underlying() ([]interface{}, error) {
// QueryIterator defines the interface for querying AST documents with references.
type QueryIterator func(map[Var]Value, Value) error

// Array represents an array as defined by Opalog. Arrays are similar to the
// Array represents an array as defined by the language. Arrays are similar to the
// same types as defined by JSON with the exception that they can contain Vars
// and References.
type Array []*Term
Expand Down Expand Up @@ -423,7 +423,7 @@ func (arr Array) queryRec(ref Ref, keys map[Var]Value, iter QueryIterator) error
}
}

// Object represents an object as defined by Opalog. Objects are similar to
// Object represents an object as defined by the language. Objects are similar to
// the same types as defined by JSON with the exception that they can contain
// Vars and References.
type Object [][2]*Term
Expand Down
4 changes: 2 additions & 2 deletions opalog/term_test.go → ast/term_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package opalog
package ast

import (
"fmt"
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestQuery(t *testing.T) {
{"object nested", `e[100]`, []string{`["true"]`, "[{}]"}},
{"vars", `a[i][j][k]`, []string{`[[4], "d"]`, `[{i:0, j:1, k:"b"}, {i:0, j:2, k:"c"}]`}},
{"vars/mixed", `a[0][j][k]`, []string{`[[4], "d"]`, `[{j:1, k:"b"}, {j:2, k:"c"}]`}},
{"array bad index type", `a["0"]`, fmt.Errorf(`unexpected non-numeric index in ["0"]: "0" (opalog.String)`)},
{"array bad index type", `a["0"]`, fmt.Errorf(`unexpected non-numeric index in ["0"]: "0" (ast.String)`)},
{"array bad index value", "a[1]", fmt.Errorf(`unexpected index in [1]: out of bounds: 1`)},
{"array bad element type", "a[0][0][1]", fmt.Errorf(`unexpected non-composite at [0][1]: true`)},
{"object bad key", `e["hello"]`, fmt.Errorf(`missing key "hello": ["hello"]`)},
Expand Down
16 changes: 8 additions & 8 deletions docs/CONCEPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Conceptually, OPA is a collection of algorithms that answer questions about poli
At a high level, using OPA involves:

- Deploying OPA on servers alongside applications.
- Writing policies a declarative language ("Opalog") and loading them into OPA.
- Writing policies a declarative language ("Rego") and loading them into OPA.
- Pushing application state that is relevant to policy into OPA.
- Executing queries via OPA's APIs to answer questions about operations governed by policy.
- Reacting to notifications delivered by OPA when policy is violated.
Expand Down Expand Up @@ -188,17 +188,17 @@ Conceptually, there are two kinds of documents in OPA:

<img src="https://cdn.rawgit.com/open-policy-agent/opa/9f5f1e6fa68fd0ee627122b9e5c8809519e5bba8/docs/data-model-dependencies.svg" />

When defining policies, rules are written which contain expressions that reference documents. The language that rules are written in ("Opalog") lets you reference base documents and virtual documents in exactly the same way.
When defining policies, rules are written which contain expressions that reference documents. The language that rules are written in ("Rego") lets you reference base documents and virtual documents in exactly the same way.

<img src="https://cdn.rawgit.com/open-policy-agent/opa/86672fab147c476cb8e8b0950b6c4fd48b5b2014/docs/data-model-logical.svg" />

## <a name="policies"></a> Policies

Policies are defined in OPA's native query language: Opalog.
Policies are defined in OPA's native query language: Rego.

Opalog is a declarative language based on [Datalog](https://en.wikipedia.org/wiki/Datalog). Opalog allows policy writers to define modules which contain rules. Rules contain expressions which assert facts about the expected state of documents stored in OPA. The documents referenced in rules may be base documents pushed by applications integrated with OPA or virtual documents defined by other rules.
Rego is a declarative language based on [Datalog](https://en.wikipedia.org/wiki/Datalog). Rego allows policy writers to define modules which contain rules. Rules contain expressions which assert facts about the expected state of documents stored in OPA. The documents referenced in rules may be base documents pushed by applications integrated with OPA or virtual documents defined by other rules.

To support document-oriented models such as JSON, Opalog has rich support for referencing nested documents (i.e., documents inside arrays or objects). The syntax for referencing nested documents is based on dictionary and array access in languages like Python as well as JSON Path.
To support document-oriented models such as JSON, Rego has rich support for referencing nested documents (i.e., documents inside arrays or objects). The syntax for referencing nested documents is based on dictionary and array access in languages like Python as well as JSON Path.

Let's look at an example.

Expand Down Expand Up @@ -236,7 +236,7 @@ Content-Type: application/json

We can write a rule which enumerates servers that expose HTTP (but not HTTPS) and are connected to public networks. These represent violations of policy.

```opalog
```rego
package opa.examples # this policy belongs the opa.examples package

import data.servers # import the data.servers document to refer to it as "servers" instead of "data.servers"
Expand All @@ -255,7 +255,7 @@ public_servers[server] :- # a server exists in the public_
networks[j].public = true # and the network is public
```

The key aspects of Opalog are illustrated by this example:
The key aspects of Rego are illustrated by this example:

- Rules define the content of virtual documents. In this case, we create two virtual documents: `violations` and `public_servers`.

Expand Down Expand Up @@ -286,4 +286,4 @@ Content-Type: application/json

## What's Next

For more information on how to write policy definitions and queries, see [Opalog: OPA's Query Language](./LANGUAGE.md).
For more information on how to write policy definitions and queries, see [Rego: OPA's Query Language](./LANGUAGE.md).
4 changes: 2 additions & 2 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ If you need to update the dependencies:
1. Commit the changes to the glide.lock file and any files under the vendor
directory.

## Opalog
## Rego

If you need to modify the Opalog syntax you must update opalog/opalog.peg. Both `make build` and `make test` will re-generate the parser but if you want to test the parser generation explicitly you can run `make generate`.
If you need to modify the Rego syntax you must update ast/rego.peg. Both `make build` and `make test` will re-generate the parser but if you want to test the parser generation explicitly you can run `make generate`.
Loading