forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rendered_templates_archive_spec.go
56 lines (46 loc) · 1.2 KB
/
rendered_templates_archive_spec.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 applyspec
import (
"github.com/cloudfoundry/bosh-agent/agent/applier/models"
"github.com/cloudfoundry/bosh-utils/crypto"
"encoding/json"
)
type RenderedTemplatesArchiveSpec struct {
Sha1 *crypto.MultipleDigest `json:"sha1"`
BlobstoreID string `json:"blobstore_id"`
}
func (s RenderedTemplatesArchiveSpec) AsSource(job models.Job) models.Source {
var sha1 crypto.Digest
if s.Sha1 != nil {
sha1 = *s.Sha1
}
return models.Source{
Sha1: sha1,
BlobstoreID: s.BlobstoreID,
PathInArchive: job.Name,
}
}
type renderedTemplatesArchiveJSONStruct struct {
Sha1 string `json:"sha1"`
BlobstoreID string `json:"blobstore_id"`
}
func (s *RenderedTemplatesArchiveSpec) UnmarshalJSON(data []byte) error {
var jsonStruct renderedTemplatesArchiveJSONStruct
err := json.Unmarshal(data, &jsonStruct)
if err != nil {
return err
}
if jsonStruct.BlobstoreID == "" && jsonStruct.Sha1 == "" {
s = nil
return nil
}
var digest crypto.MultipleDigest
err = json.Unmarshal([]byte("\""+jsonStruct.Sha1+"\""), &digest)
if err != nil {
return err
}
*s = RenderedTemplatesArchiveSpec{
Sha1: &digest,
BlobstoreID: jsonStruct.BlobstoreID,
}
return nil
}