microsoft / regorus

Regorus - A fast, lightweight Rego (OPA policy language) interpreter written in Rust.
MIT License
130 stars 32 forks source link

Is the `import` statement fully supported? #284

Closed lquerel closed 2 months ago

lquerel commented 2 months ago

In Regorus, the following code works.

package semconv
import rego.v1

# Collect all attributes from previous groups that are prefixed by "registry."
prev_attributes := {attr.name | 
    some g in data.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

# Collect all attributes from current groups that are prefixed by "registry."
curr_attributes := {attr.name | 
    some g in input.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

prev_group_id_containing_attr := {attr.name: g.id |
    some g in data.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

But not this one (see the import with the alias). Note that the official implementation doesn't complain with this code. Is there something I'm missing?

package semconv
import rego.v1

# HERE I DEFINED AN ALIAS TO data.groups 
import data.groups as prev_groups

# Collect all attributes from previous groups that are prefixed by "registry."
prev_attributes := {attr.name | 
    some g in prev_groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

# Collect all attributes from current groups that are prefixed by "registry."
curr_attributes := {attr.name | 
    some g in input.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

prev_group_id_containing_attr := {attr.name: g.id |
    some g in prev_groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}
anakrish commented 2 months ago

This is a bug. The scheduler wasn't registering alias names which causes it to raise unsafe var error.