Skip to content

Commit 4d0d09e

Browse files
committed
feat: start working on a state-machine for pulls
1 parent 2cb4aed commit 4d0d09e

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

pkg/client/pull/state/state.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package state
2+
3+
import (
4+
"github.com/distribution/reference"
5+
"github.com/opencontainers/go-digest"
6+
)
7+
8+
type Pull interface {
9+
Ref() reference.Named
10+
Digest() *digest.Digest // can be nil when the pull is not yet complete
11+
Layers() []Layer
12+
Layer(id string) Layer
13+
}
14+
15+
type Layer interface {
16+
Id() string
17+
Status() string
18+
}
19+
20+
type pullBase struct {
21+
ref reference.Named
22+
layers []Layer
23+
}
24+
25+
func (p *pullBase) Ref() reference.Named {
26+
return p.ref
27+
}
28+
29+
func (p *pullBase) Digest() *digest.Digest {
30+
return nil
31+
}
32+
33+
func (p *pullBase) Layers() []Layer {
34+
return p.layers
35+
}
36+
37+
func (p *pullBase) Layer(id string) Layer {
38+
for _, l := range p.layers {
39+
if l.Id() == id {
40+
return l
41+
}
42+
}
43+
return nil
44+
}
45+
46+
type layerBase struct {
47+
id string
48+
}
49+
50+
func (l *layerBase) Id() string {
51+
return l.id
52+
}

0 commit comments

Comments
 (0)