mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
Change required scope of entrypoint from rule to document (#6963)
And automatically change implied `scope` from `rule` to `document` when no `scope` is provided (on rule metadata). Fixes #6798 Signed-off-by: Anders Eknert <anders@styra.com>
This commit is contained in:
+7
-7
@@ -255,20 +255,20 @@ func (c *Compiler) WithRegoVersion(v ast.RegoVersion) *Compiler {
|
||||
return c
|
||||
}
|
||||
|
||||
func addEntrypointsFromAnnotations(c *Compiler, ar []*ast.AnnotationsRef) error {
|
||||
for _, ref := range ar {
|
||||
func addEntrypointsFromAnnotations(c *Compiler, arefs []*ast.AnnotationsRef) error {
|
||||
for _, aref := range arefs {
|
||||
var entrypoint ast.Ref
|
||||
scope := ref.Annotations.Scope
|
||||
scope := aref.Annotations.Scope
|
||||
|
||||
if ref.Annotations.Entrypoint {
|
||||
if aref.Annotations.Entrypoint {
|
||||
// Build up the entrypoint path from either package path or rule.
|
||||
switch scope {
|
||||
case "package":
|
||||
if p := ref.GetPackage(); p != nil {
|
||||
if p := aref.GetPackage(); p != nil {
|
||||
entrypoint = p.Path
|
||||
}
|
||||
case "rule":
|
||||
if r := ref.GetRule(); r != nil {
|
||||
case "document":
|
||||
if r := aref.GetRule(); r != nil {
|
||||
entrypoint = r.Ref().GroundPrefix()
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -2106,7 +2106,7 @@ q = true`,
|
||||
Annotations: []*ast.Annotations{
|
||||
{
|
||||
Title: "My P rule",
|
||||
Scope: "rule",
|
||||
Scope: "document",
|
||||
Entrypoint: true,
|
||||
},
|
||||
},
|
||||
@@ -2366,7 +2366,7 @@ func TestCompilerRegoEntrypointAnnotations(t *testing.T) {
|
||||
wantEntrypoints map[string]struct{}
|
||||
}{
|
||||
{
|
||||
note: "rule annotation",
|
||||
note: "implied document scope annotation",
|
||||
entrypoints: []string{},
|
||||
modules: map[string]string{
|
||||
"test.rego": `
|
||||
|
||||
Reference in New Issue
Block a user