Skip to content

Commit a4a8b60

Browse files
authored
constraint: Update Rego driver to support rego.v1 (#517)
* constraint: Rego v1 poc This is an initial PoC to show what rego.v1 support might look. Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> * constraint: Rego v1 tests for AddTemplate too The addTemplate operation had not been tested in my updates to other tests. Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> * Update attemptVersions to always be v1 first This makes it consistent with the compilation versions. Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> * driver/rego: Make v1 support opt-in with field Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> * constrainttemplate_types_test: Add version field Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> * rego-driver: Revert to v0 hook module https://github.com/open-policy-agent/frameworks/pull/517/files#r2004431952 Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> * rego-driver: Add GetSource test Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> * rego-driver: revise switch case https://github.com/open-policy-agent/frameworks/pull/517/files/dc39c8d9ba4422d4229d5d72fec977bb715e8d59#r2008355303 Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> --------- Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com> Co-authored-by: Charlie Egan <charlieegan3@users.noreply.github.com>
1 parent 79a9477 commit a4a8b60

32 files changed

+1517
-570
lines changed

constraint/pkg/apis/templates/v1/constrainttemplate_types_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ func TestTypeConversion(t *testing.T) {
146146
Engine: regoSchema.Name,
147147
Source: &templates.Anything{
148148
Value: (&regoSchema.Source{
149-
Rego: regoOnlyExpectedResult.Spec.Targets[0].Rego,
150-
Libs: regoOnlyExpectedResult.Spec.Targets[0].Libs,
149+
Rego: regoOnlyExpectedResult.Spec.Targets[0].Rego,
150+
Libs: regoOnlyExpectedResult.Spec.Targets[0].Libs,
151+
Version: "",
151152
}).ToUnstructured(),
152153
},
153154
},
@@ -211,7 +212,10 @@ func TestTypeConversion(t *testing.T) {
211212
{
212213
Engine: "Rego",
213214
Source: &templates.Anything{
214-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
215+
Value: map[string]interface{}{
216+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
217+
"version": "",
218+
},
215219
},
216220
},
217221
},
@@ -331,7 +335,10 @@ func TestTypeConversion(t *testing.T) {
331335
{
332336
Engine: "Rego",
333337
Source: &templates.Anything{
334-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
338+
Value: map[string]interface{}{
339+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
340+
"version": "",
341+
},
335342
},
336343
},
337344
},
@@ -450,7 +457,10 @@ func TestTypeConversion(t *testing.T) {
450457
{
451458
Engine: "Rego",
452459
Source: &templates.Anything{
453-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
460+
Value: map[string]interface{}{
461+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
462+
"version": "",
463+
},
454464
},
455465
},
456466
},
@@ -514,7 +524,10 @@ func TestTypeConversion(t *testing.T) {
514524
{
515525
Engine: "Rego",
516526
Source: &templates.Anything{
517-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "this rego should be clobbered"}] { true }`},
527+
Value: map[string]interface{}{
528+
"rego": `package hello ; violation[{"msg": "this rego should be clobbered"}] { true }`,
529+
"version": "",
530+
},
518531
},
519532
},
520533
},
@@ -575,7 +588,10 @@ func TestTypeConversion(t *testing.T) {
575588
{
576589
Engine: "Rego",
577590
Source: &templates.Anything{
578-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
591+
Value: map[string]interface{}{
592+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
593+
"version": "",
594+
},
579595
},
580596
},
581597
},

constraint/pkg/apis/templates/v1alpha1/constrainttemplate_types_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ func TestTypeConversion(t *testing.T) {
146146
Engine: regoSchema.Name,
147147
Source: &templates.Anything{
148148
Value: (&regoSchema.Source{
149-
Rego: regoOnlyExpectedResult.Spec.Targets[0].Rego,
150-
Libs: regoOnlyExpectedResult.Spec.Targets[0].Libs,
149+
Rego: regoOnlyExpectedResult.Spec.Targets[0].Rego,
150+
Libs: regoOnlyExpectedResult.Spec.Targets[0].Libs,
151+
Version: "",
151152
}).ToUnstructured(),
152153
},
153154
},
@@ -211,7 +212,10 @@ func TestTypeConversion(t *testing.T) {
211212
{
212213
Engine: "Rego",
213214
Source: &templates.Anything{
214-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
215+
Value: map[string]interface{}{
216+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
217+
"version": "",
218+
},
215219
},
216220
},
217221
},
@@ -331,7 +335,10 @@ func TestTypeConversion(t *testing.T) {
331335
{
332336
Engine: "Rego",
333337
Source: &templates.Anything{
334-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
338+
Value: map[string]interface{}{
339+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
340+
"version": "",
341+
},
335342
},
336343
},
337344
},
@@ -450,7 +457,10 @@ func TestTypeConversion(t *testing.T) {
450457
{
451458
Engine: "Rego",
452459
Source: &templates.Anything{
453-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
460+
Value: map[string]interface{}{
461+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
462+
"version": "",
463+
},
454464
},
455465
},
456466
},
@@ -514,7 +524,10 @@ func TestTypeConversion(t *testing.T) {
514524
{
515525
Engine: "Rego",
516526
Source: &templates.Anything{
517-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "this rego should be clobbered"}] { true }`},
527+
Value: map[string]interface{}{
528+
"rego": `package hello ; violation[{"msg": "this rego should be clobbered"}] { true }`,
529+
"version": "",
530+
},
518531
},
519532
},
520533
},
@@ -575,7 +588,10 @@ func TestTypeConversion(t *testing.T) {
575588
{
576589
Engine: "Rego",
577590
Source: &templates.Anything{
578-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
591+
Value: map[string]interface{}{
592+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
593+
"version": "",
594+
},
579595
},
580596
},
581597
},

constraint/pkg/apis/templates/v1beta1/constrainttemplate_types_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ func TestTypeConversion(t *testing.T) {
146146
Engine: regoSchema.Name,
147147
Source: &templates.Anything{
148148
Value: (&regoSchema.Source{
149-
Rego: regoOnlyExpectedResult.Spec.Targets[0].Rego,
150-
Libs: regoOnlyExpectedResult.Spec.Targets[0].Libs,
149+
Rego: regoOnlyExpectedResult.Spec.Targets[0].Rego,
150+
Libs: regoOnlyExpectedResult.Spec.Targets[0].Libs,
151+
Version: "",
151152
}).ToUnstructured(),
152153
},
153154
},
@@ -211,7 +212,10 @@ func TestTypeConversion(t *testing.T) {
211212
{
212213
Engine: "Rego",
213214
Source: &templates.Anything{
214-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
215+
Value: map[string]interface{}{
216+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
217+
"version": "",
218+
},
215219
},
216220
},
217221
},
@@ -331,7 +335,10 @@ func TestTypeConversion(t *testing.T) {
331335
{
332336
Engine: "Rego",
333337
Source: &templates.Anything{
334-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
338+
Value: map[string]interface{}{
339+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
340+
"version": "",
341+
},
335342
},
336343
},
337344
},
@@ -450,7 +457,10 @@ func TestTypeConversion(t *testing.T) {
450457
{
451458
Engine: "Rego",
452459
Source: &templates.Anything{
453-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
460+
Value: map[string]interface{}{
461+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
462+
"version": "",
463+
},
454464
},
455465
},
456466
},
@@ -514,7 +524,10 @@ func TestTypeConversion(t *testing.T) {
514524
{
515525
Engine: "Rego",
516526
Source: &templates.Anything{
517-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "this rego should be clobbered"}] { true }`},
527+
Value: map[string]interface{}{
528+
"rego": `package hello ; violation[{"msg": "this rego should be clobbered"}] { true }`,
529+
"version": "",
530+
},
518531
},
519532
},
520533
},
@@ -575,7 +588,10 @@ func TestTypeConversion(t *testing.T) {
575588
{
576589
Engine: "Rego",
577590
Source: &templates.Anything{
578-
Value: map[string]interface{}{"rego": `package hello ; violation[{"msg": "msg"}] { true }`},
591+
Value: map[string]interface{}{
592+
"rego": `package hello ; violation[{"msg": "msg"}] { true }`,
593+
"version": "",
594+
},
579595
},
580596
},
581597
},

0 commit comments

Comments
 (0)