mirror of
https://github.com/containrrr/watchtower.git
synced 2026-02-08 16:34:21 +01:00
feat(api): add updates API v2
This commit is contained in:
parent
47091761a5
commit
4a922f5a32
4 changed files with 73 additions and 33 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package session
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
|
||||
"github.com/containrrr/watchtower/pkg/types"
|
||||
|
|
@ -61,6 +62,38 @@ func (r *report) All() []types.ContainerReport {
|
|||
return all
|
||||
}
|
||||
|
||||
type jsonMap = map[string]interface{}
|
||||
|
||||
// MarshalJSON implements json.Marshaler
|
||||
func (r *report) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(jsonMap{
|
||||
`scanned`: marshalReports(r.Scanned()),
|
||||
`updated`: marshalReports(r.Updated()),
|
||||
`failed`: marshalReports(r.Failed()),
|
||||
`skipped`: marshalReports(r.Skipped()),
|
||||
`stale`: marshalReports(r.Stale()),
|
||||
`fresh`: marshalReports(r.Fresh()),
|
||||
})
|
||||
}
|
||||
|
||||
func marshalReports(reports []types.ContainerReport) []jsonMap {
|
||||
jsonReports := make([]jsonMap, len(reports))
|
||||
for i, report := range reports {
|
||||
jsonReports[i] = jsonMap{
|
||||
`id`: report.ID().ShortID(),
|
||||
`name`: report.Name(),
|
||||
`currentImageId`: report.CurrentImageID().ShortID(),
|
||||
`latestImageId`: report.LatestImageID().ShortID(),
|
||||
`imageName`: report.ImageName(),
|
||||
`state`: report.State(),
|
||||
}
|
||||
if errorMessage := report.Error(); errorMessage != "" {
|
||||
jsonReports[i][`error`] = errorMessage
|
||||
}
|
||||
}
|
||||
return jsonReports
|
||||
}
|
||||
|
||||
// NewReport creates a types.Report from the supplied Progress
|
||||
func NewReport(progress Progress) types.Report {
|
||||
report := &report{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue