forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates_repo.go
63 lines (48 loc) · 1.31 KB
/
templates_repo.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
package templatescompiler
import (
bosherr "github.com/cloudfoundry/bosh-agent/errors"
biindex "github.com/cloudfoundry/bosh-init/index"
bireljob "github.com/cloudfoundry/bosh-init/release/job"
)
type TemplateRecord struct {
BlobID string
BlobSHA1 string
}
type TemplatesRepo interface {
Save(bireljob.Job, TemplateRecord) error
Find(bireljob.Job) (TemplateRecord, bool, error)
}
type templatesRepo struct {
index biindex.Index
}
func NewTemplatesRepo(index biindex.Index) TemplatesRepo {
return templatesRepo{index: index}
}
func (tr templatesRepo) Save(job bireljob.Job, record TemplateRecord) error {
err := tr.index.Save(tr.jobKey(job), record)
if err != nil {
return bosherr.WrapError(err, "Saving job templates")
}
return nil
}
func (tr templatesRepo) Find(job bireljob.Job) (TemplateRecord, bool, error) {
var record TemplateRecord
err := tr.index.Find(tr.jobKey(job), &record)
if err != nil {
if err == biindex.ErrNotFound {
return record, false, nil
}
return record, false, bosherr.WrapError(err, "Finding job templates")
}
return record, true, nil
}
type jobTemplateKey struct {
JobName string
JobFingerprint string
}
func (tr templatesRepo) jobKey(job bireljob.Job) jobTemplateKey {
return jobTemplateKey{
JobName: job.Name,
JobFingerprint: job.Fingerprint,
}
}