@@ -90,7 +90,7 @@ func (d *Driver) AddTemplate(ctx context.Context, templ *templates.ConstraintTem
90
90
func (d * Driver ) RemoveTemplate (ctx context.Context , templ * templates.ConstraintTemplate ) error {
91
91
kind := templ .Spec .CRD .Spec .Names .Kind
92
92
93
- constraintParent := storage.Path {"constraint " , kind }
93
+ constraintParent := storage.Path {"constraints " , kind }
94
94
95
95
d .mtx .Lock ()
96
96
defer d .mtx .Unlock ()
@@ -281,28 +281,38 @@ func (d *Driver) Query(ctx context.Context, target string, constraints []*unstru
281
281
}
282
282
283
283
func (d * Driver ) Dump (ctx context.Context ) (string , error ) {
284
- dt := make (map [string ]map [string ]rego.ResultSet )
284
+ // we want to create:
285
+ // targetName.modules.kind.moduleName = contents
286
+ // targetName.data = data
287
+ dt := make (map [string ]map [string ]interface {})
285
288
286
289
compilers := d .compilers .list ()
287
290
for targetName , targetCompilers := range compilers {
288
- targetData := make (map [string ]rego. ResultSet )
291
+ targetModules := make (map [string ]map [ string ] string )
289
292
290
293
for kind , compiler := range targetCompilers {
291
- rs , _ , err := d . eval ( ctx , compiler , targetName , [ ]string { "data" }, nil )
292
- if err != nil {
293
- return "" , err
294
+ kindModules := make ( map [ string ]string )
295
+ for modname , contents := range compiler . Modules {
296
+ kindModules [ modname ] = contents . String ()
294
297
}
295
- targetData [kind ] = rs
298
+ targetModules [kind ] = kindModules
296
299
}
300
+ dt [targetName ] = map [string ]interface {}{}
301
+ dt [targetName ]["modules" ] = targetModules
297
302
298
- dt [targetName ] = targetData
299
- }
303
+ emptyCompiler := ast .NewCompiler ().WithCapabilities (d .compilers .capabilities )
300
304
301
- resp := map [string ]interface {}{
302
- "data" : dt ,
305
+ rs , _ , err := d .eval (ctx , emptyCompiler , targetName , []string {}, nil )
306
+ if err != nil {
307
+ return "" , err
308
+ }
309
+
310
+ if len (rs ) != 0 && len (rs [0 ].Expressions ) != 0 {
311
+ dt [targetName ]["data" ] = rs [0 ].Expressions [0 ].Value
312
+ }
303
313
}
304
314
305
- b , err := json .MarshalIndent (resp , "" , " " )
315
+ b , err := json .MarshalIndent (dt , "" , " " )
306
316
if err != nil {
307
317
return "" , err
308
318
}
0 commit comments