-
Notifications
You must be signed in to change notification settings - Fork 1
/
fileset.go
75 lines (66 loc) · 1.68 KB
/
fileset.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
75
package schema
import (
"encoding/json"
"errors"
"github.com/coreos/rocket/app-container/schema/types"
)
type FilesetManifest struct {
ACVersion types.SemVer `json:"acVersion"`
ACKind types.ACKind `json:"acKind"`
Name types.ACName `json:"name"`
OS string `json:"os"`
Arch string `json:"arch"`
Dependencies []Dependency `json:"dependencies"`
Files []string `json:"files"`
}
type Dependency struct {
Name types.ACName `json:"name"`
Hash types.Hash `json:"hash"`
Root string `json:"root"`
}
func NewFilesetManifest(name string) (*FilesetManifest, error) {
n, err := types.NewACName(name)
if err != nil {
return nil, err
}
fsm := FilesetManifest{
ACVersion: AppContainerVersion,
ACKind: "FilesetManifest",
OS: "linux",
Arch: "amd64",
Name: *n,
}
return &fsm, nil
}
type fileSetManifest FilesetManifest
func (fsm *FilesetManifest) assertValid() error {
if fsm.ACKind != "FilesetManifest" {
return types.ACKindError(`missing or bad ACKind (must be "FilesetManifest")`)
}
if fsm.OS != "linux" {
return errors.New(`missing or bad OS (must be "linux")`)
}
if fsm.Arch != "amd64" {
return errors.New(`missing or bad Arch (must be "amd64")`)
}
return nil
}
func (fsm *FilesetManifest) UnmarshalJSON(data []byte) error {
f := fileSetManifest{}
err := json.Unmarshal(data, &f)
if err != nil {
return err
}
nfsm := FilesetManifest(f)
if err := nfsm.assertValid(); err != nil {
return err
}
*fsm = nfsm
return nil
}
func (fsm FilesetManifest) MarshalJSON() ([]byte, error) {
if err := fsm.assertValid(); err != nil {
return nil, err
}
return json.Marshal(fileSetManifest(fsm))
}