github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/python_package_metadata.go (about) 1 package pkg 2 3 import ( 4 "sort" 5 6 "github.com/scylladb/go-set/strset" 7 ) 8 9 var _ FileOwner = (*PythonPackageMetadata)(nil) 10 11 // PythonFileDigest represents the file metadata for a single file attributed to a python package. 12 type PythonFileDigest struct { 13 Algorithm string `json:"algorithm"` 14 Value string `json:"value"` 15 } 16 17 // PythonFileRecord represents a single entry within a RECORD file for a python wheel or egg package 18 type PythonFileRecord struct { 19 Path string `json:"path"` 20 Digest *PythonFileDigest `json:"digest,omitempty"` 21 Size string `json:"size,omitempty"` 22 } 23 24 type PythonDirectURLOriginInfo struct { 25 URL string `json:"url"` 26 CommitID string `json:"commitId,omitempty"` 27 VCS string `json:"vcs,omitempty"` 28 } 29 30 // PythonPackageMetadata represents all captured data for a python egg or wheel package. 31 type PythonPackageMetadata struct { 32 Name string `json:"name" mapstruct:"Name"` 33 Version string `json:"version" mapstruct:"Version"` 34 Author string `json:"author" mapstruct:"Author"` 35 AuthorEmail string `json:"authorEmail" mapstruct:"Authoremail"` 36 Platform string `json:"platform" mapstruct:"Platform"` 37 Files []PythonFileRecord `json:"files,omitempty"` 38 SitePackagesRootPath string `json:"sitePackagesRootPath"` 39 TopLevelPackages []string `json:"topLevelPackages,omitempty"` 40 DirectURLOrigin *PythonDirectURLOriginInfo `json:"directUrlOrigin,omitempty"` 41 } 42 43 type DirectURLOrigin struct { 44 URL string `json:"url"` 45 VCSInfo VCSInfo `json:"vcs_info"` 46 ArchiveInfo ArchiveInfo `json:"archive_info"` 47 DirInfo DirInfo `json:"dir_info"` 48 } 49 50 type DirInfo struct { 51 Editable bool `json:"editable"` 52 } 53 54 type ArchiveInfo struct { 55 Hash string `json:"hash"` 56 } 57 58 type VCSInfo struct { 59 CommitID string `json:"commit_id"` 60 VCS string `json:"vcs"` 61 RequestedRevision string `json:"requested_revision"` 62 } 63 64 func (m PythonPackageMetadata) OwnedFiles() (result []string) { 65 s := strset.New() 66 for _, f := range m.Files { 67 if f.Path != "" { 68 s.Add(f.Path) 69 } 70 } 71 result = s.List() 72 sort.Strings(result) 73 return result 74 }