@@ -16,7 +16,6 @@ import (
16
16
"github.com/flanksource/duty/rbac"
17
17
"github.com/flanksource/duty/rbac/policy"
18
18
"github.com/flanksource/duty/types"
19
- "github.com/flanksource/gomplate/v3"
20
19
"github.com/google/uuid"
21
20
"github.com/samber/lo"
22
21
"github.com/samber/oops"
@@ -206,7 +205,7 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models
206
205
207
206
var runSpec v1.PlaybookSpec
208
207
if err := json .Unmarshal (playbook .Spec , & runSpec ); err != nil {
209
- return nil , ctx .Oops ().Wrap (err )
208
+ return nil , ctx .Oops ().Wrapf (err , "failed to unmarshal playbook spec" )
210
209
}
211
210
212
211
{
@@ -216,17 +215,15 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models
216
215
hasExplicitAgent := len (runSpec .RunsOn ) != 0 || len (action .RunsOn ) != 0
217
216
usesFromConfigItem := action .Exec != nil && action .Exec .Connections .FromConfigItem != nil
218
217
if ! hasExplicitAgent && usesFromConfigItem {
219
- tpl := gomplate.Template {
220
- Template : * action .Exec .Connections .FromConfigItem ,
221
- }
222
- output , err := ctx .RunTemplate (tpl , templateEnv .AsMap (ctx ))
218
+ templater := ctx .NewStructTemplater (templateEnv .AsMap (ctx ), "" , nil )
219
+ output , err := templater .Template (* action .Exec .Connections .FromConfigItem )
223
220
if err != nil {
224
- return nil , ctx .Oops ().Wrap (err )
221
+ return nil , ctx .Oops ().Wrapf (err , "failed to template config item %s" , * action . Exec . Connections . FromConfigItem )
225
222
}
226
223
227
224
var fromConfigItem models.ConfigItem
228
225
if err := ctx .DB ().Select ("id" , "agent_id" ).Where ("id = ?" , output ).Find (& fromConfigItem ).Error ; err != nil {
229
- return nil , ctx .Oops ().Wrap (err )
226
+ return nil , ctx .Oops ().Wrapf (err , "failed to find config item %s" , output )
230
227
} else if fromConfigItem .AgentID != uuid .Nil {
231
228
runSpec .Actions [i ].RunsOn = []string {fromConfigItem .AgentID .String ()}
232
229
}
@@ -236,9 +233,10 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models
236
233
// Template run's spec (runsOn)
237
234
var runsOn []string
238
235
for _ , specRunOn := range runSpec .RunsOn {
239
- output , err := ctx .RunTemplate (gomplate.Template {Template : specRunOn }, templateEnv .AsMap (ctx ))
236
+ templater := ctx .NewStructTemplater (templateEnv .AsMap (ctx ), "" , nil )
237
+ output , err := templater .Template (specRunOn )
240
238
if err != nil {
241
- return nil , ctx .Oops ().Wrap (err )
239
+ return nil , ctx .Oops ().Wrapf (err , "failed to template run's spec %s" , specRunOn )
242
240
}
243
241
runsOn = append (runsOn , output )
244
242
}
0 commit comments