github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/common/cyclonedxhelpers/author.go (about)

     1  package cyclonedxhelpers
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/anchore/syft/syft/pkg"
     8  )
     9  
    10  func encodeAuthor(p pkg.Package) string {
    11  	if hasMetadata(p) {
    12  		switch metadata := p.Metadata.(type) {
    13  		case pkg.NpmPackage:
    14  			return metadata.Author
    15  		case pkg.PythonPackage:
    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.RubyGemspec:
    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.NpmPackage:
    37  		meta.Author = author
    38  	case *pkg.PythonPackage:
    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.RubyGemspec:
    45  		meta.Authors = strings.Split(author, ",")
    46  	}
    47  }