http report wip

This commit is contained in:
nils måsén 2021-06-27 15:30:23 +02:00
parent e3dd8d688a
commit efaf7190ee
25 changed files with 350 additions and 284 deletions

View file

@ -1,6 +1,9 @@
package session
import wt "github.com/containrrr/watchtower/pkg/types"
import (
wt "github.com/containrrr/watchtower/pkg/types"
"strings"
)
// State indicates what the current state is of the container
type State int
@ -19,51 +22,17 @@ const (
// ContainerStatus contains the container state during a session
type ContainerStatus struct {
containerID wt.ContainerID
oldImage wt.ImageID
newImage wt.ImageID
containerName string
imageName string
error
state State
ID wt.ContainerID
Name string
OldImageID wt.ImageID
NewImageID wt.ImageID
ImageName string
Error error
State State
}
// ID returns the container ID
func (u *ContainerStatus) ID() wt.ContainerID {
return u.containerID
}
// Name returns the container name
func (u *ContainerStatus) Name() string {
return u.containerName
}
// CurrentImageID returns the image ID that the container used when the session started
func (u *ContainerStatus) CurrentImageID() wt.ImageID {
return u.oldImage
}
// LatestImageID returns the newest image ID found during the session
func (u *ContainerStatus) LatestImageID() wt.ImageID {
return u.newImage
}
// ImageName returns the name:tag that the container uses
func (u *ContainerStatus) ImageName() string {
return u.imageName
}
// Error returns the error (if any) that was encountered for the container during a session
func (u *ContainerStatus) Error() string {
if u.error == nil {
return ""
}
return u.error.Error()
}
// State returns the current State that the container is in
func (u *ContainerStatus) State() string {
switch u.state {
func (state State) String() string {
switch state {
case SkippedState:
return "Skipped"
case ScannedState:
@ -80,3 +49,12 @@ func (u *ContainerStatus) State() string {
return "Unknown"
}
}
// MarshalJSON marshals State as a string
func (state State) MarshalJSON() ([]byte, error) {
sb := strings.Builder{}
sb.WriteString(`"`)
sb.WriteString(state.String())
sb.WriteString(`"`)
return []byte(sb.String()), nil
}