github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/templator/yaml/template.go (about) 1 package yaml 2 3 import ( 4 "path/filepath" 5 6 "github.com/caos/orbos/internal/operator/boom/api/latest" 7 helper2 "github.com/caos/orbos/internal/utils/helper" 8 "github.com/caos/orbos/internal/utils/yaml" 9 ) 10 11 func (y *YAML) Template(appInterface interface{}, spec *latest.ToolsetSpec, resultFunc func(string, string) error) error { 12 app, err := checkTemplatorInterface(appInterface) 13 if err != nil { 14 return err 15 } 16 17 yamlInterface := app.GetYaml(y.monitor, spec) 18 resultfilepath := y.GetResultsFilePath(app.GetName(), y.overlay, y.templatorDirectoryPath) 19 resultfiledirectory := y.getResultsFileDirectory(app.GetName(), y.overlay, y.templatorDirectoryPath) 20 21 resultAbsFilePath, err := filepath.Abs(resultfilepath) 22 if err != nil { 23 return err 24 } 25 resultAbsFileDirectory, err := filepath.Abs(resultfiledirectory) 26 if err != nil { 27 return err 28 } 29 30 if err := helper2.RecreatePath(resultAbsFileDirectory); err != nil { 31 return err 32 } 33 34 yamlStr := yamlInterface.(string) 35 if err := yaml.New(resultAbsFilePath).AddStringObject(yamlStr); err != nil { 36 return err 37 } 38 39 return resultFunc(resultAbsFilePath, "") 40 }