Skip to content

ast: add feature registration from the outside#7782

Merged
srenatus merged 1 commit intoopen-policy-agent:mainfrom
srenatus:sr/kprvvwrznpun
Jul 17, 2025
Merged

ast: add feature registration from the outside#7782
srenatus merged 1 commit intoopen-policy-agent:mainfrom
srenatus:sr/kprvvwrznpun

Conversation

@srenatus
Copy link
Copy Markdown
Contributor

@srenatus srenatus commented Jul 17, 2025

If I add this to main.go (imagine another executable including OPA),

diff --git a/main.go b/main.go
index 9d5aea6c7c..5126479107 100644
--- a/main.go
+++ b/main.go
@@ -8,9 +8,11 @@
 	"os"
 
 	"github.com/open-policy-agent/opa/cmd"
+	"github.com/open-policy-agent/opa/v1/ast"
 )
 
 func main() {
+	ast.RegisterFeatures("foo", "bar", "baz")
 	if err := cmd.RootCommand.Execute(); err != nil {
 		os.Exit(1)
 	}

and I subsequently run opa capabilities --current, we'll find (other stuff omitted):

{
  "features": [
    "bar",
    "baz",
    "foo",
    "keywords_in_refs",
    "rego_v1"
  ]
}

This complements builtins, which can already be registered from the outside.

If I add this to `main.go` (imagine another executable including OPA),

```diff
diff --git a/main.go b/main.go
index 9d5aea6..5126479107 100644
--- a/main.go
+++ b/main.go
@@ -8,9 +8,11 @@
 	"os"
 
 	"github.com/open-policy-agent/opa/cmd"
+	"github.com/open-policy-agent/opa/v1/ast"
 )
 
 func main() {
+	ast.RegisterFeatures("foo", "bar", "baz")
 	if err := cmd.RootCommand.Execute(); err != nil {
 		os.Exit(1)
 	}
```

and I subsequently run `opa capabilities --current`, we'll find (other
stuff omitted):

```json
{
  "features": [
    "bar",
    "baz",
    "foo",
    "keywords_in_refs",
    "rego_v1"
  ]
}
```

Signed-off-by: Stephan Renatus <stephan@styra.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Jul 17, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 18ee630
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/6878c807086a0b000860e478
😎 Deploy Preview https://deploy-preview-7782--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@srenatus srenatus enabled auto-merge (rebase) July 17, 2025 09:59
@srenatus srenatus disabled auto-merge July 17, 2025 10:45
@srenatus srenatus merged commit 47f764e into open-policy-agent:main Jul 17, 2025
31 checks passed
@srenatus srenatus deleted the sr/kprvvwrznpun branch July 17, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants