forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign.go
66 lines (54 loc) · 1.59 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
57
58
59
60
61
62
63
64
65
66
package registry
import (
"path"
"github.com/coreos/fleet/etcd"
"github.com/coreos/fleet/sign"
)
const (
signingPrefix = "/signing/"
)
// CreateSignatureSet stores the given SignatureSet in the repository
func (r *EtcdRegistry) CreateSignatureSet(ss *sign.SignatureSet) error {
json, _ := marshal(ss)
req := etcd.Create{
Key: r.signatureSetPath(ss.Tag),
Value: json,
}
_, err := r.etcd.Do(&req)
return err
}
// DestroySignatureSet destroys the SignatureSet associated with the given tag
func (r *EtcdRegistry) DestroySignatureSet(tag string) {
req := etcd.Delete{
Key: r.signatureSetPath(tag),
}
r.etcd.Do(&req)
}
// getSignatureSet returns the SignatureSet associated with the given tag
func (r *EtcdRegistry) getSignatureSet(tag string) *sign.SignatureSet {
req := etcd.Get{
Key: r.signatureSetPath(tag),
Recursive: true,
}
resp, err := r.etcd.Do(&req)
// 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
}
// JobSignatureSet retrieves the SignatureSet associated with the given
// job, or nil if none can be found
func (r *EtcdRegistry) JobSignatureSet(name string) (*sign.SignatureSet, error) {
// TODO(jonboulle): handle errors
return r.getSignatureSet(sign.TagForJob(name)), nil
}
func (r *EtcdRegistry) destroySignatureSetOfJob(name string) {
r.DestroySignatureSet(sign.TagForJob(name))
}
func (r *EtcdRegistry) signatureSetPath(s string) string {
return path.Join(r.keyPrefix, signingPrefix, s)
}