github.com/quay/claircore@v1.5.28/indexreport.go (about)

     1  package claircore
     2  
     3  // IndexRecord is an entry in the IndexReport.
     4  //
     5  // IndexRecords provide full access to contextual package
     6  // structures such as Distribution and Repository.
     7  //
     8  // A list of these can be thought of as an "unpacked" IndexReport
     9  type IndexRecord struct {
    10  	Package      *Package
    11  	Distribution *Distribution
    12  	Repository   *Repository
    13  }
    14  
    15  // IndexReport provides a database for discovered artifacts in an image.
    16  //
    17  // IndexReports make heavy usage of lookup maps to associate information
    18  // without repetition.
    19  type IndexReport struct {
    20  	// the manifest hash this IndexReport is describing
    21  	Hash Digest `json:"manifest_hash"`
    22  	// the current state of the index operation
    23  	State string `json:"state"`
    24  	// all discovered packages in this manifest key'd by package id
    25  	Packages map[string]*Package `json:"packages"`
    26  	// all discovered distributions in this manifest key'd by distribution id
    27  	Distributions map[string]*Distribution `json:"distributions"`
    28  	// all discovered repositories in this manifest key'd by repository id
    29  	Repositories map[string]*Repository `json:"repository"`
    30  	// a list of environment details a package was discovered in key'd by package id
    31  	Environments map[string][]*Environment `json:"environments"`
    32  	// whether the index operation finished successfully
    33  	Success bool `json:"success"`
    34  	// an error string in the case the index did not succeed
    35  	Err string `json:"err"`
    36  	// Files doesn't end up in the json report but needs to be available at post-coalesce
    37  	Files map[string]File `json:"-"`
    38  }
    39  
    40  // IndexRecords returns a list of IndexRecords derived from the IndexReport
    41  func (report *IndexReport) IndexRecords() []*IndexRecord {
    42  	out := []*IndexRecord{}
    43  	for _, pkg := range report.Packages {
    44  		for _, env := range report.Environments[pkg.ID] {
    45  			if len(env.RepositoryIDs) == 0 {
    46  				record := &IndexRecord{}
    47  				record.Package = pkg
    48  				record.Distribution = report.Distributions[env.DistributionID]
    49  				out = append(out, record)
    50  				continue
    51  			}
    52  			// create package record for each repository
    53  			for _, repositoryID := range env.RepositoryIDs {
    54  				record := &IndexRecord{}
    55  				record.Package = pkg
    56  				record.Distribution = report.Distributions[env.DistributionID]
    57  				record.Repository = report.Repositories[repositoryID]
    58  				out = append(out, record)
    59  			}
    60  		}
    61  	}
    62  	return out
    63  }