-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
636 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// https://www.openpolicyagent.org/docs/latest/policy-reference/ | ||
|
||
Prism.languages.rego = { | ||
'comment': /#.*/, | ||
'property': { | ||
pattern: /(^|[^\\.])(?:"(?:\\.|[^\\"\r\n])*"|`[^`]*`|\b[a-z_]\w*\b)(?=\s*:(?!=))/i, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
'string': { | ||
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"|`[^`]*`/, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
|
||
'keyword': /\b(?:as|default|else|import|package|not|null|some|with|set(?=\s*\())\b/, | ||
'boolean': /\b(?:true|false)\b/, | ||
|
||
'function': { | ||
pattern: /\b[a-z_]\w*\b(?:\s*\.\s*\b[a-z_]\w*\b)*(?=\s*\()/i, | ||
inside: { | ||
'namespace': /\b\w+\b(?=\s*\.)/, | ||
'punctuation': /\./ | ||
} | ||
}, | ||
|
||
'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i, | ||
'operator': /[-+*/%|&]|[<>:=]=?|!=|\b_\b/, | ||
'punctuation': /[,;.\[\]{}()]/ | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<h2>Full example</h2> | ||
<pre><code># Role-based Access Control (RBAC) | ||
|
||
# By default, deny requests. | ||
default allow = false | ||
|
||
# Allow admins to do anything. | ||
allow { | ||
user_is_admin | ||
} | ||
|
||
# Allow the action if the user is granted permission to perform the action. | ||
allow { | ||
# Find grants for the user. | ||
some grant | ||
user_is_granted[grant] | ||
|
||
# Check if the grant permits the action. | ||
input.action == grant.action | ||
input.type == grant.type | ||
} | ||
|
||
# user_is_admin is true if... | ||
user_is_admin { | ||
|
||
# for some `i`... | ||
some i | ||
|
||
# "admin" is the `i`-th element in the user->role mappings for the identified user. | ||
data.user_roles[input.user][i] == "admin" | ||
} | ||
|
||
# user_is_granted is a set of grants for the user identified in the request. | ||
# The `grant` will be contained if the set `user_is_granted` for every... | ||
user_is_granted[grant] { | ||
some i, j | ||
|
||
# `role` assigned an element of the user_roles for this user... | ||
role := data.user_roles[input.user][i] | ||
|
||
# `grant` assigned a single grant from the grants list for 'role'... | ||
grant := data.role_grants[role][j] | ||
} | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for booleans. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
# foobar | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "#"], | ||
["comment", "# foobar"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
object.remove({"a": {"b": {"c": 2}}, "x": 123}, {"a": 1}) == {"x": 123} | ||
|
||
output := is_set(x) | ||
output := intersection(set[set]) | ||
output := regex.match(pattern, value) | ||
output := glob.match("*.github.com", [], "api.github.com") | ||
output := bits.rsh(x, s) | ||
output := io.jwt.verify_ps384(string, certificate) | ||
|
||
io.jwt.encode_sign({ | ||
"typ": "JWT", | ||
"alg": "HS256"}, | ||
{}, { | ||
"kty": "oct", | ||
"k": "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow" | ||
}) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function", [ | ||
["namespace", "object"], | ||
["punctuation", "."], | ||
"remove" | ||
]], | ||
["punctuation", "("], | ||
["punctuation", "{"], | ||
["property", "\"a\""], | ||
["operator", ":"], | ||
["punctuation", "{"], | ||
["property", "\"b\""], | ||
["operator", ":"], | ||
["punctuation", "{"], | ||
["property", "\"c\""], | ||
["operator", ":"], | ||
["number", "2"], | ||
["punctuation", "}"], | ||
["punctuation", "}"], | ||
["punctuation", ","], | ||
["property", "\"x\""], | ||
["operator", ":"], | ||
["number", "123"], | ||
["punctuation", "}"], | ||
["punctuation", ","], | ||
["punctuation", "{"], | ||
["property", "\"a\""], | ||
["operator", ":"], | ||
["number", "1"], | ||
["punctuation", "}"], | ||
["punctuation", ")"], | ||
["operator", "=="], | ||
["punctuation", "{"], | ||
["property", "\"x\""], | ||
["operator", ":"], | ||
["number", "123"], | ||
["punctuation", "}"], | ||
|
||
"\r\n\r\noutput ", | ||
["operator", ":="], | ||
["function", ["is_set"]], | ||
["punctuation", "("], | ||
"x", | ||
["punctuation", ")"], | ||
|
||
"\r\noutput ", | ||
["operator", ":="], | ||
["function", ["intersection"]], | ||
["punctuation", "("], | ||
"set", | ||
["punctuation", "["], | ||
"set", | ||
["punctuation", "]"], | ||
["punctuation", ")"], | ||
|
||
"\r\noutput ", | ||
["operator", ":="], | ||
["function", [ | ||
["namespace", "regex"], | ||
["punctuation", "."], | ||
"match" | ||
]], | ||
["punctuation", "("], | ||
"pattern", | ||
["punctuation", ","], | ||
" value", | ||
["punctuation", ")"], | ||
|
||
"\r\noutput ", | ||
["operator", ":="], | ||
["function", [ | ||
["namespace", "glob"], | ||
["punctuation", "."], | ||
"match" | ||
]], | ||
["punctuation", "("], | ||
["string", "\"*.github.com\""], | ||
["punctuation", ","], | ||
["punctuation", "["], | ||
["punctuation", "]"], | ||
["punctuation", ","], | ||
["string", "\"api.github.com\""], | ||
["punctuation", ")"], | ||
|
||
"\r\noutput ", | ||
["operator", ":="], | ||
["function", [ | ||
["namespace", "bits"], | ||
["punctuation", "."], | ||
"rsh" | ||
]], | ||
["punctuation", "("], | ||
"x", | ||
["punctuation", ","], | ||
" s", | ||
["punctuation", ")"], | ||
|
||
"\r\noutput ", | ||
["operator", ":="], | ||
["function", [ | ||
["namespace", "io"], | ||
["punctuation", "."], | ||
["namespace", "jwt"], | ||
["punctuation", "."], | ||
"verify_ps384" | ||
]], | ||
["punctuation", "("], | ||
"string", | ||
["punctuation", ","], | ||
" certificate", | ||
["punctuation", ")"], | ||
|
||
["function", [ | ||
["namespace", "io"], | ||
["punctuation", "."], | ||
["namespace", "jwt"], | ||
["punctuation", "."], | ||
"encode_sign" | ||
]], | ||
["punctuation", "("], | ||
["punctuation", "{"], | ||
|
||
["property", "\"typ\""], | ||
["operator", ":"], | ||
["string", "\"JWT\""], | ||
["punctuation", ","], | ||
|
||
["property", "\"alg\""], | ||
["operator", ":"], | ||
["string", "\"HS256\""], | ||
["punctuation", "}"], | ||
["punctuation", ","], | ||
|
||
["punctuation", "{"], | ||
["punctuation", "}"], | ||
["punctuation", ","], | ||
["punctuation", "{"], | ||
|
||
["property", "\"kty\""], | ||
["operator", ":"], | ||
["string", "\"oct\""], | ||
["punctuation", ","], | ||
|
||
["property", "\"k\""], | ||
["operator", ":"], | ||
["string", "\"AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow\""], | ||
|
||
["punctuation", "}"], | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for all functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
as | ||
default | ||
else | ||
import | ||
package | ||
not | ||
null | ||
some | ||
with | ||
|
||
set() | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "as"], | ||
["keyword", "default"], | ||
["keyword", "else"], | ||
["keyword", "import"], | ||
["keyword", "package"], | ||
["keyword", "not"], | ||
["keyword", "null"], | ||
["keyword", "some"], | ||
["keyword", "with"], | ||
|
||
["keyword", "set"], ["punctuation", "("], ["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for all keywords. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
0 | ||
123 | ||
3.14159 | ||
5.0e8 | ||
0.2E+2 | ||
47e-5 | ||
-1.23 | ||
-2.34E33 | ||
-4.34E-33 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "0"], | ||
["number", "123"], | ||
["number", "3.14159"], | ||
["number", "5.0e8"], | ||
["number", "0.2E+2"], | ||
["number", "47e-5"], | ||
["number", "-1.23"], | ||
["number", "-2.34E33"], | ||
["number", "-4.34E-33"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
:= = : | ||
== != < <= > >= | ||
+ - / * % | ||
& | | ||
_ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", ":="], | ||
["operator", "="], | ||
["operator", ":"], | ||
|
||
["operator", "=="], | ||
["operator", "!="], | ||
["operator", "<"], | ||
["operator", "<="], | ||
["operator", ">"], | ||
["operator", ">="], | ||
|
||
["operator", "+"], | ||
["operator", "-"], | ||
["operator", "/"], | ||
["operator", "*"], | ||
["operator", "%"], | ||
|
||
["operator", "&"], | ||
["operator", "|"], | ||
|
||
["operator", "_"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
Oops, something went wrong.