Skip to content

Commit

Permalink
Merge pull request #8 from anchore/anchore-api
Browse files Browse the repository at this point in the history
fix: ensure Report reponse object matches current Anchore API
  • Loading branch information
bradleyjones committed Dec 21, 2022
2 parents de1a88e + c381bc4 commit 7e7e3d2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
8 changes: 5 additions & 3 deletions ecg/inventory/report.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package inventory

type Report struct {
Timestamp string `json:"timestamp,omitempty"` // Should be generated using time.Now.UTC() and formatted according to RFC Y-M-DTH:M:SZ
Results []ReportItem `json:"results"`
InventoryType string `json:"inventory_type"`
Timestamp string `json:"timestamp,omitempty"` // Should be generated using time.Now.UTC() and formatted according to RFC Y-M-DTH:M:SZ
Results []ReportItem `json:"results"`
ClusterName string `json:"clusterName,omitempty"` // NOTE: The key here is ClusterName to match the Anchore API but it's actually the region

InventoryType string `json:"inventory_type"`
}
6 changes: 3 additions & 3 deletions ecg/inventory/reportitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

// ReportItem represents a cluster and all it's unique images
type ReportItem struct {
ClusterARN string `json:"cluster_arn,omitempty"`
Images []ReportImage `json:"images"`
Namespace string `json:"namespace,omitempty"` //NOTE The key is Namespace to match the Anchore API but it's actually the cluster ARN
Images []ReportImage `json:"images"`
}

// ReportImage represents a unique image in a cluster
Expand All @@ -18,7 +18,7 @@ type ReportImage struct {

// String represent the ReportItem as a string
func (r *ReportItem) String() string {
return fmt.Sprintf("ReportItem(cluster=%s, images=%v)", r.ClusterARN, r.Images)
return fmt.Sprintf("ReportItem(cluster=%s, images=%v)", r.Namespace, r.Images)
}

// key will return a unique key for a ReportImage
Expand Down
5 changes: 3 additions & 2 deletions ecg/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ func GetInventoryReport(cfg *config.Application) (inventory.Report, error) {
images, err := fetchImagesFromTasks(ecsClient, *cluster, tasks)

results = append(results, inventory.ReportItem{
ClusterARN: *cluster,
Images: images,
Namespace: *cluster, //NOTE The key is Namespace to match the Anchore API but it's actually the cluster ARN
Images: images,
})
}

return inventory.Report{
Timestamp: time.Now().UTC().Format(time.RFC3339),
Results: results,
ClusterName: cfg.Region, // NOTE: The key here is ClusterName to match the Anchore API but it's actually the region
InventoryType: "ecs",
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion ecg/presenter/table/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (pres *Presenter) Present(output io.Writer) error {

columns := []string{"Image Tag", "Repo Digest", "Cluster"}
for _, n := range pres.report.Results {
cluster := n.ClusterARN
cluster := n.Namespace
for _, image := range n.Images {
row := []string{image.Tag, image.RepoDigest, cluster}
rows = append(rows, row)
Expand Down

0 comments on commit 7e7e3d2

Please sign in to comment.