summaryrefslogtreecommitdiffstats
path: root/registry/models.go
blob: 11e1db810019607398c9d029db4224a894729f31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Package registry is responsible for fetching data from the backend registry
// and providing the data for the UI components.
package registry

import (
	"context"
	"errors"
	"time"
)

// ErrNotFound should be returned for missing repositories/manifests.
var ErrNotFound = errors.New("registry resource not found")

type Provider interface {
	Repositories(ctx context.Context) ([]Repository, error)
	Repository(ctx context.Context, name string) (Repository, error)
	Manifest(ctx context.Context, repository, digest string) (Manifest, error)
}

type Repository struct {
	Name      string    `json:"name"`
	UpdatedAt time.Time `json:"updated_at"`
	Age       string    `json:"age,omitempty"`
	Tags      []Tag     `json:"tags"`
}

type Tag struct {
	Name           string    `json:"name"`
	Aliases        []string  `json:"aliases,omitempty"`
	UpdatedAt      time.Time `json:"updated_at"`
	Age            string    `json:"age,omitempty"`
	Platforms      string    `json:"platforms,omitempty"`
	SizeBytes      int64     `json:"size_bytes,omitempty"`
	ManifestDigest string    `json:"manifest_digest"`
}

type Manifest struct {
	Repository string             `json:"repository"`
	Digest     string             `json:"digest"`
	Kind       string             `json:"kind"`                 // "index" for a list; "image" for layers.
	SizeBytes  int64              `json:"size_bytes,omitempty"` // Registry-reported image total, when available.
	Tags       []TagReference     `json:"tags"`
	Platforms  []PlatformManifest `json:"platforms,omitempty"`
	Layers     []Layer            `json:"layers,omitempty"`
}

func (m Manifest) TotalSizeBytes() int64 {
	if m.SizeBytes > 0 {
		return m.SizeBytes
	}
	var total int64
	for _, layer := range m.Layers {
		total += layer.SizeBytes
	}
	return total
}

type TagReference struct {
	Name           string    `json:"name"`
	UpdatedAt      time.Time `json:"updated_at"`
	Age            string    `json:"age,omitempty"`
	ManifestDigest string    `json:"manifest_digest"`
}

type PlatformManifest struct {
	Platform  string `json:"platform"`
	Variant   string `json:"variant,omitempty"`
	SizeBytes int64  `json:"size_bytes"`
	Digest    string `json:"digest"`
}

type Layer struct {
	Digest    string `json:"digest"`
	SizeBytes int64  `json:"size_bytes"`
}