mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-20 17:10:13 +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
|
|
@ -2,8 +2,6 @@ package notifications
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
t "github.com/containrrr/watchtower/pkg/types"
|
||||
)
|
||||
|
||||
type jsonMap = map[string]interface{}
|
||||
|
|
@ -20,42 +18,12 @@ func (d Data) MarshalJSON() ([]byte, error) {
|
|||
}
|
||||
}
|
||||
|
||||
var report jsonMap
|
||||
if d.Report != nil {
|
||||
report = jsonMap{
|
||||
`scanned`: marshalReports(d.Report.Scanned()),
|
||||
`updated`: marshalReports(d.Report.Updated()),
|
||||
`failed`: marshalReports(d.Report.Failed()),
|
||||
`skipped`: marshalReports(d.Report.Skipped()),
|
||||
`stale`: marshalReports(d.Report.Stale()),
|
||||
`fresh`: marshalReports(d.Report.Fresh()),
|
||||
}
|
||||
}
|
||||
|
||||
return json.Marshal(jsonMap{
|
||||
`report`: report,
|
||||
`report`: d.Report,
|
||||
`title`: d.Title,
|
||||
`host`: d.Host,
|
||||
`entries`: entries,
|
||||
})
|
||||
}
|
||||
|
||||
func marshalReports(reports []t.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
|
||||
}
|
||||
|
||||
var _ json.Marshaler = &Data{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue