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

AST: rules with variables in ref missing attached annotations #7050

Closed
anderseknert opened this issue Sep 23, 2024 · 2 comments · Fixed by #7052
Closed

AST: rules with variables in ref missing attached annotations #7050

anderseknert opened this issue Sep 23, 2024 · 2 comments · Fixed by #7052
Labels

Comments

@anderseknert
Copy link
Member

Since a few releases back, rule-level annotations are now attached to the rules they annotate in the AST. However, this doesn't seem to be the case for any rule where a variable component is in the rule ref.

Given a rule like this:

# METADATA
# description: bug
bug[x] if x := 5

The annotation can be found under annotations:

  "annotations": [
    {
      "description": "bug",
      "scope": "rule"
    }
  ],

But not under the rule:

  "rules": [
    {
      "body": [
        {
          "index": 0,
          "terms": [
            {
              "type": "ref",
              "value": [
                {
                  "type": "var",
                  "value": "assign"
                }
              ]
            },
            {
              "type": "var",
              "value": "x"
            },
            {
              "type": "number",
              "value": 5
            }
          ]
        }
      ],
      "head": {
        "value": {
          "type": "boolean",
          "value": true
        },
        "ref": [
          {
            "type": "var",
            "value": "bug"
          },
          {
            "type": "var",
            "value": "x"
          }
        ]
      }
    }
  ],
@johanfylling
Copy link
Contributor

The metadata is available to the rule at runtime, so this is likely a serialization issue.

package play

import rego.v1

# METADATA
# description: bug
bug[x] if x := rego.metadata.rule()

->

{
    "bug": {
        "{\"description\":\"bug\",\"scope\":\"rule\"}": true
    }
}

@anderseknert
Copy link
Member Author

Available "to" the rule, but not available on the rule :)

anderseknert added a commit to anderseknert/opa that referenced this issue Sep 23, 2024
Previously, annotations were missing on rules that had variable
components in the ref head. Now we annotate the rule using the
path up to the first var.

Fixes open-policy-agent#7050

Signed-off-by: Anders Eknert <anders@styra.com>
@anderseknert anderseknert changed the title Rules with variables in ref missing attached annotations AST: rules with variables in ref missing attached annotations Sep 23, 2024
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 23, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 23, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 23, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 23, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 23, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 23, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.
- Add pprof option to language-server command, and pprof handlers
  to web server

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 24, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.
- Add pprof option to language-server command, and pprof handlers
  to web server

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit to StyraInc/regal that referenced this issue Sep 24, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.
- Add pprof option to language-server command, and pprof handlers
  to web server

Signed-off-by: Anders Eknert <anders@styra.com>
srenatus pushed a commit to srenatus/regal that referenced this issue Oct 1, 2024
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.
- Add pprof option to language-server command, and pprof handlers
  to web server

Signed-off-by: Anders Eknert <anders@styra.com>
charlieegan3 pushed a commit to charlieegan3/regal that referenced this issue Jan 6, 2025
This rule is not for everyone, and hence in the `custom` category.

For a public projects, libraries and reusable policies, this should
however be considered.

This uncovered a
[bug in OPA](open-policy-agent/opa#7050), which has
now been addressed. In order to make progress on this we're now depending on
OPA `main`. This should be changed as soon as OPA v0.69.0 is released.

Some unrelated fixes in this PR, fixing annoyances as I worked on it:
- add Regal specific attributes (`input.regal.*`) to the input created by the
  `eval:use-as-input` directive
- Add another metadata snippet to allow creating a `# METADATA` block
  with only description and no title. Tbh, I'm still not sure what to
  use `title` for, while `description` is pretty much mandatory.
- Set `ignore-if-sub-attribute: true` on default config for
  `prefer-some-in-iteration` rule. This was documented to be the case
  already, but seemed to have gone missing at some point.
- Add pprof option to language-server command, and pprof handlers
  to web server

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants