in internal/fabric/factories.go [33:83]
func (f *RoleFactory) ApplyFactory(prefix string) error {
factoryFiles, err := os.ReadDir(f.Path)
if err != nil {
return err
}
for _, file := range factoryFiles {
var r yaml.Node
// read the file
p := f.Path + "/" + file.Name()
inBytes, err := utils.ReadFile(p)
if err != nil {
return err
}
// load file data into struct
if err := yaml.Unmarshal(inBytes, &r); err != nil {
return err
}
// update name property
for i, d := range r.Content {
// loop thru the nodes
for x := 0; x < len(d.Content); x += 2 {
// find the name property
if d.Content[x].Value == "name" {
// set the new name in the top level struct
oldValue := d.Content[x+1].Value
r.Content[i].Content[x+1].Value = prefix + "_" + oldValue
}
}
}
// marshal new data to bytes
outBytes, err := yaml.Marshal(&r)
if err != nil {
return err
}
// write the updated yaml file
if err := utils.CreateFile(p, outBytes, true); err != nil {
return err
}
}
return nil
}