Skip to content

Conversation

@burdzwastaken
Copy link

  • Adds --rego-version flag to create and doc commands (default: v0)
  • Parses Rego v1 syntax
  • Generates OPA v1 compatible ConstraintTemplates
  • Strips import future.keywords.* and import rego.v1 from v1 output

Fixes #637 & #663


// StripV1Imports removes `import future.keywords.*` and `import rego.v1`
// imports from Rego source code since these are not needed in OPA v1.
func StripV1Imports(source string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the idea, I personally woudn't want konstraint to alter the rego code though. Could this be put behind an additional command line flag like --strip-v0-imports?

prevBlank := false
for line := range strings.SplitSeq(source, "\n") {
trimmed := strings.TrimSpace(line)
if strings.HasPrefix(trimmed, "import future.keywords") ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be explicit here and mention all keywords it should filter?

I wonder what happens if rego v1 needs additional keywords and they get added to future.keywords

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.

Have Konstraint generate GateKeeper's expected v1 Syntax

2 participants