forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign.go
56 lines (44 loc) · 1.42 KB
/
sign.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
package registry
import (
"path"
"github.com/coreos/fleet/sign"
)
const (
signingPrefix = "/signing/"
)
// CreateSignatureSet stores the given SignatureSet in the repository
func (r *Registry) CreateSignatureSet(ss *sign.SignatureSet) error {
key := r.signatureSetPath(ss.Tag)
json, _ := marshal(ss)
_, err := r.etcd.Create(key, json, 0)
return err
}
// DestroySignatureSet destroys the SignatureSet associated with the given tag
func (r *Registry) DestroySignatureSet(tag string) {
key := r.signatureSetPath(tag)
r.etcd.Delete(key, false)
}
// GetSignatureSet returns the SignatureSet associated with the given tag
func (r *Registry) GetSignatureSet(tag string) *sign.SignatureSet {
key := r.signatureSetPath(tag)
resp, err := r.etcd.Get(key, false, true)
// Assume the error was KeyNotFound and return an empty data structure
if err != nil {
return nil
}
var sig sign.SignatureSet
//TODO: Handle the error generated by unmarshal
unmarshal(resp.Node.Value, &sig)
return &sig
}
// GetSignatureSetOfJob retrieves the SignatureSet associated with the given
// job, or nil if none can be found
func (r *Registry) GetSignatureSetOfJob(name string) *sign.SignatureSet {
return r.GetSignatureSet(sign.TagForJob(name))
}
func (r *Registry) destroySignatureSetOfJob(name string) {
r.DestroySignatureSet(sign.TagForJob(name))
}
func (r *Registry) signatureSetPath(s string) string {
return path.Join(r.keyPrefix, signingPrefix, s)
}