github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/cyclonedxhelpers/author.go (about) 1 package cyclonedxhelpers 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/nextlinux/gosbom/gosbom/pkg" 8 ) 9 10 func encodeAuthor(p pkg.Package) string { 11 if hasMetadata(p) { 12 switch metadata := p.Metadata.(type) { 13 case pkg.NpmPackageJSONMetadata: 14 return metadata.Author 15 case pkg.PythonPackageMetadata: 16 author := metadata.Author 17 if metadata.AuthorEmail != "" { 18 if author == "" { 19 return metadata.AuthorEmail 20 } 21 author += fmt.Sprintf(" <%s>", metadata.AuthorEmail) 22 } 23 return author 24 case pkg.GemMetadata: 25 if len(metadata.Authors) > 0 { 26 return strings.Join(metadata.Authors, ",") 27 } 28 return "" 29 } 30 } 31 return "" 32 } 33 34 func decodeAuthor(author string, metadata interface{}) { 35 switch meta := metadata.(type) { 36 case *pkg.NpmPackageJSONMetadata: 37 meta.Author = author 38 case *pkg.PythonPackageMetadata: 39 parts := strings.SplitN(author, " <", 2) 40 meta.Author = parts[0] 41 if len(parts) > 1 { 42 meta.AuthorEmail = strings.TrimSuffix(parts[1], ">") 43 } 44 case *pkg.GemMetadata: 45 meta.Authors = strings.Split(author, ",") 46 } 47 }