20 Commits

Author SHA1 Message Date
Anders Eknert bdb11d4c7e Fix: add missing BuildAnnotationSet to ast v0 (#7349)
Fixes #7347

Signed-off-by: Anders Eknert <anders@styra.com>
2025-02-09 20:35:03 +01:00
Johan Fylling a179a24c48 v1 API
All packages, except for `cmd` and `internal`, have been moved into a new `v1` root package.

Old packages are kept for backwards-compatibility reasons. All contained code is replaced with simple type aliases and proxy functions to `v1` implementations.

Old packages default to the Rego v0 syntax, new `v1` packages default to the Rego v1 syntax.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:27:34 +01:00
Johan Fylling 7bb6dbe36b Preparing for v1 API
Moving (most) source to v1 root package to prepare for v0/v1 API separation.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:09:03 +01:00
Anders Eknert e959bce141 Fix: attach annotation to static part of rule ref (#7052)
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 #7050

Signed-off-by: Anders Eknert <anders@styra.com>
2024-09-23 13:33:14 +02:00
Anders Eknert f10cc1f4c8 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>
2024-08-28 13:22:30 +02:00
Johan Fylling 5464b005e8 Bumping golangci-lint to v1.59.1 (#6817)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-06-19 15:13:43 +02:00
Ashutosh Narkar 4e5c36d05c Include annotations in rule AST (#6771)
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
Co-authored-by: Johan Fylling <johan.dev@fylling.se>
2024-05-30 14:54:48 +02:00
Will Beason 8119dc097b Fix IDE warnings and remove usage of several deprecated fields. (#6397)
Signed-off-by: Will Beason <willbeason@gmail.com>
Co-authored-by: Johan Fylling <johan.dev@fylling.se>
2023-11-13 10:22:33 -06:00
Charlie Egan cd0bf5b4d2 Add option to marshal location text (#6234) 2023-09-21 09:40:07 +01:00
Zoran Regvart a33e0e0474 fix: preserve jsonOptions in NewAnnotationsRef (#5753)
Makes sure that `jsonOptions` are preserved in NewAnnotationsRef.

Signed-off-by: Zoran Regvart <zoran@regvart.com>
2023-03-14 15:28:11 +00:00
Charlie Egan fbfa705063 [ast/opa parse] Support marshalling of all ast location data (#5576)
Signed-off-by: Charlie Egan <charlie@styra.com>
2023-03-09 09:49:30 +00:00
Johan Fylling c0360f1af5 ast: Annotations scoped to package carries across modules (#5627)
Fixes: #5251

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-02-16 20:31:01 +01:00
Johan Fylling f93d0f8fea bundle: Retain metadata annotations for Wasm entrypoints during inspection (#5603)
* Pruning METADATA blocks associated with Wasm compiled entrypoints from Rego source in bundle
* Adding metadata annotations to wasm entrypoint declarations in bundle .manifest file
* Reading metadata annotations from both Rego source and .manifest file in bundle during `inspect`

Fixes: #5588
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-02-03 12:15:21 +01:00
Philip Conrad 7b6a04eac2 ast/annotations: Add type coercion guards to avoid panics. (#5373)
This commit adds type coercion guards around the AST annotation
set building logic, to avoid panics when nil values appear.

Nil node values can happen here after copy-propagation, because
the AST nodes can be ripped out from under the annotation system
when they are pruned away or inlined into other rules.

Fixes: #5368

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-11-09 09:17:26 +01:00
Philip Conrad e2eabe88c1 ast+compile+cmd: Support entrypoint annotations. (#5246)
This commit adds support to the `compile` package for extracting
entrypoints from Rego `entrypoint` metadata annotations. The new
entrypoint annotations can be applied to any valid entrypoint target,
e.g. rules and packages.

An example policy using the new entrypoint annotations:

    package test

    # METADATA
    # entrypoint: true
    allow {
        input.x
    }

The `build` and `eval` CLI commands have been updated so that they do
not require an entrypoint to be explicitly provided with `-e`, so long
as at least one valid rule/package is marked with an entrypoint
annotation.

The new feature is additive; entrypoints can still be explicitly
provided to these commands by `-e`, and those will be used alongside the
entrypoints discovered from the metadata annotations.

Fixes: #3459

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-10-24 14:35:17 -04:00
Philip Conrad b2d92a33c1 Add prealloc linter check + linter fixes (#5139)
This commit adds the `prealloc` linter to the list of linters for OPA, and fixes up the miscellaneous locations in the code that the linter found where we could easily preallocate slices.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-09-15 15:09:54 -04:00
Johan Fylling c6226621c4 ast: Adding rego.metadata.* built-in functions (#4537)
New functions:
* rego.metadata.chain(): returns the chain of metadata, starting from the active rule, going outward
* rego.metadata.rule(): returns the metadata for the active rule

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2022-04-13 11:46:11 +02:00
Johan Fylling 35d7e58a84 cmd: Adding annotations listing to inspect command (#4388)
By passing `-a` to `opa inspect`, it will pretty-print information
about the rules' and packages' annotations.

For all annotations, including related_resources, use `-fjson`.

Fixes: #4387

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2022-03-03 10:10:37 +01:00
Johan Fylling f4b03e9a19 ast: Compiling annotations also for modules with solo package definition (#4372)
Basing compiled annotation set on module set, and not rule graph,
as that caused annotations in modules with only package and no rules
to not get picked up.

Fixes: #4369
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2022-02-22 16:19:53 +01:00
Johan Fylling 1d1eb4df00 ast: Adding annotation override support to all annotation types (#4370)
Fixes: #4331
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2022-02-22 12:30:30 +01:00