-
Notifications
You must be signed in to change notification settings - Fork 7
/
replica_sync.go
74 lines (67 loc) · 2.44 KB
/
replica_sync.go
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
/*******************************************************************************
*
* Copyright 2021 SAP SE
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You should have received a copy of the License along with this
* program. If not, you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************/
package keppel
import "github.com/opencontainers/go-digest"
// ReplicaSyncPayload is the format for request bodies and response bodies of
// the sync-replica API endpoint.
//
// (This type is declared in this package because it gets used in both
// internal/api/peer and internal/tasks.)
type ReplicaSyncPayload struct {
Manifests []ManifestForSync `json:"manifests"`
}
// ManifestForSync represents a manifest in the _sync_replica API endpoint.
//
// (This type is declared in this package because it gets used in both
// internal/api/peer and internal/tasks.)
type ManifestForSync struct {
Digest digest.Digest `json:"digest"`
LastPulledAt *int64 `json:"last_pulled_at,omitempty"`
Tags []TagForSync `json:"tags,omitempty"`
}
// TagForSync represents a tag in the _sync_replica API endpoint.
//
// (This type is declared in this package because it gets used in both
// internal/api/peer and internal/tasks.)
type TagForSync struct {
Name string `json:"name"`
LastPulledAt *int64 `json:"last_pulled_at,omitempty"`
}
// HasManifest returns whether there is a manifest with the given digest in this
// payload.
func (p ReplicaSyncPayload) HasManifest(manifestDigest digest.Digest) bool {
for _, m := range p.Manifests {
if m.Digest == manifestDigest {
return true
}
}
return false
}
// DigestForTag returns the digest of the manifest that this tag points to, or
// the empty string if the tag does not exist in this payload.
func (p ReplicaSyncPayload) DigestForTag(name string) digest.Digest {
for _, m := range p.Manifests {
for _, t := range m.Tags {
if t.Name == name {
return m.Digest
}
}
}
return ""
}