diff --git a/pkg/asset/ast.go b/pkg/asset/ast.go index 69f6caf4d..86fb873ed 100644 --- a/pkg/asset/ast.go +++ b/pkg/asset/ast.go @@ -8,7 +8,7 @@ import ( "github.com/goccy/go-yaml/ast" ) -func UpdateASTFile(file *ast.File, pkgs interface{}) error { +func UpdateASTFile(file *ast.File, pkgs interface{}) error { //nolint:cyclop node, err := yaml.ValueToNode(pkgs) if err != nil { return fmt.Errorf("convert packages to node: %w", err) @@ -20,7 +20,11 @@ func UpdateASTFile(file *ast.File, pkgs interface{}) error { continue } for _, mapValue := range body.Values { - if mapValue.Key.String() != "packages" { + key, ok := mapValue.Key.(*ast.StringNode) + if !ok { + continue + } + if key.Value != "packages" { continue } switch mapValue.Value.Type() { diff --git a/pkg/controller/generate/output/insert.go b/pkg/controller/generate/output/insert.go index 69aa33965..3db3eefe5 100644 --- a/pkg/controller/generate/output/insert.go +++ b/pkg/controller/generate/output/insert.go @@ -45,7 +45,11 @@ func (o *Outputter) generateInsert(cfgFilePath string, pkgs []*aqua.Package) err func getPkgsAST(values []*ast.MappingValueNode) *ast.MappingValueNode { for _, mapValue := range values { - if mapValue.Key.String() != "packages" { + key, ok := mapValue.Key.(*ast.StringNode) + if !ok { + continue + } + if key.Value != "packages" { continue } return mapValue diff --git a/pkg/controller/update/ast/package.go b/pkg/controller/update/ast/package.go index 86cf64aea..fbf2018e8 100644 --- a/pkg/controller/update/ast/package.go +++ b/pkg/controller/update/ast/package.go @@ -43,7 +43,11 @@ func parsePackageNode(logE *logrus.Entry, node ast.Node, newVersions map[string] var pkgVersion string var nameNode *ast.StringNode for _, mvn := range mvs { - switch mvn.Key.String() { + key, ok := mvn.Key.(*ast.StringNode) + if !ok { + continue + } + switch key.Value { case "registry": sn, ok := mvn.Value.(*ast.StringNode) if !ok { diff --git a/pkg/controller/update/ast/registry.go b/pkg/controller/update/ast/registry.go index 3eacc64fc..847007c0e 100644 --- a/pkg/controller/update/ast/registry.go +++ b/pkg/controller/update/ast/registry.go @@ -11,7 +11,11 @@ const typeStandard = "standard" func findMappingValue(values []*ast.MappingValueNode, key string) *ast.MappingValueNode { for _, value := range values { - if value.Key.String() == key { + sn, ok := value.Key.(*ast.StringNode) + if !ok { + continue + } + if sn.Value == key { return value } } @@ -65,7 +69,11 @@ func parseRegistryNode(logE *logrus.Entry, node ast.Node, newVersions map[string var newVersion string var rgstName string for _, mvn := range mvs { - switch mvn.Key.String() { + key, ok := mvn.Key.(*ast.StringNode) + if !ok { + continue + } + switch key.Value { case "ref": sn, ok := mvn.Value.(*ast.StringNode) if !ok {