Session report collection and report templates (#981)

* wip: notification stats

* make report notifications optional

* linting/documentation fixes

* linting/documentation fixes

* merge types.Container and container.Interface

* smaller naming/format fixes

* use typed image/container IDs

* simplify notifier and update tests

* add missed doc comments

* lint fixes

* remove unused constructors

* rename old/new current/latest
This commit is contained in:
nils måsén 2021-06-27 09:05:01 +02:00 committed by GitHub
parent d0ecc23d72
commit e3dd8d688a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 853 additions and 598 deletions

View file

@ -1,14 +1,53 @@
package types
import "github.com/docker/docker/api/types"
import (
"github.com/docker/docker/api/types"
"strings"
)
// ImageID is a hash string representing a container image
type ImageID string
// ContainerID is a hash string representing a container instance
type ContainerID string
// ShortID returns the 12-character (hex) short version of an image ID hash, removing any "sha256:" prefix if present
func (id ImageID) ShortID() (short string) {
return shortID(string(id))
}
// ShortID returns the 12-character (hex) short version of a container ID hash, removing any "sha256:" prefix if present
func (id ContainerID) ShortID() (short string) {
return shortID(string(id))
}
func shortID(longID string) string {
prefixSep := strings.IndexRune(longID, ':')
offset := 0
length := 12
if prefixSep >= 0 {
if longID[0:prefixSep] == "sha256" {
offset = prefixSep + 1
} else {
length += prefixSep + 1
}
}
if len(longID) >= offset+length {
return longID[offset : offset+length]
}
return longID
}
// Container is a docker container running an image
type Container interface {
ContainerInfo() *types.ContainerJSON
ID() string
ID() ContainerID
IsRunning() bool
Name() string
ImageID() string
ImageID() ImageID
SafeImageID() ImageID
ImageName() string
Enabled() (bool, bool)
IsMonitorOnly() bool