-
Notifications
You must be signed in to change notification settings - Fork 198
/
raw_ansible.go
95 lines (77 loc) · 2.6 KB
/
raw_ansible.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package config
type rawAnsible struct {
BeforeInstall []rawAnsibleTask `yaml:"beforeInstall"`
Install []rawAnsibleTask `yaml:"install"`
BeforeSetup []rawAnsibleTask `yaml:"beforeSetup"`
Setup []rawAnsibleTask `yaml:"setup"`
CacheVersion string `yaml:"cacheVersion,omitempty"`
BeforeInstallCacheVersion string `yaml:"beforeInstallCacheVersion,omitempty"`
InstallCacheVersion string `yaml:"installCacheVersion,omitempty"`
BeforeSetupCacheVersion string `yaml:"beforeSetupCacheVersion,omitempty"`
SetupCacheVersion string `yaml:"setupCacheVersion,omitempty"`
rawImage *rawStapelImage `yaml:"-"` // parent
UnsupportedAttributes map[string]interface{} `yaml:",inline"`
}
func (c *rawAnsible) UnmarshalYAML(unmarshal func(interface{}) error) error {
if parent, ok := parentStack.Peek().(*rawStapelImage); ok {
c.rawImage = parent
}
parentStack.Push(c)
type plain rawAnsible
err := unmarshal((*plain)(c))
parentStack.Pop()
if err != nil {
return err
}
if err := checkOverflow(c.UnsupportedAttributes, c, c.rawImage.doc); err != nil {
return err
}
return nil
}
func (c *rawAnsible) toDirective() (ansible *Ansible, err error) {
ansible = &Ansible{}
ansible.CacheVersion = c.CacheVersion
ansible.BeforeInstallCacheVersion = c.BeforeInstallCacheVersion
ansible.InstallCacheVersion = c.InstallCacheVersion
ansible.BeforeSetupCacheVersion = c.BeforeSetupCacheVersion
ansible.SetupCacheVersion = c.SetupCacheVersion
for ind := range c.BeforeInstall {
if ansibleTask, err := c.BeforeInstall[ind].toDirective(); err != nil {
return nil, err
} else {
ansible.BeforeInstall = append(ansible.BeforeInstall, ansibleTask)
}
}
for ind := range c.Install {
if ansibleTask, err := c.Install[ind].toDirective(); err != nil {
return nil, err
} else {
ansible.Install = append(ansible.Install, ansibleTask)
}
}
for ind := range c.BeforeSetup {
if ansibleTask, err := c.BeforeSetup[ind].toDirective(); err != nil {
return nil, err
} else {
ansible.BeforeSetup = append(ansible.BeforeSetup, ansibleTask)
}
}
for ind := range c.Setup {
if ansibleTask, err := c.Setup[ind].toDirective(); err != nil {
return nil, err
} else {
ansible.Setup = append(ansible.Setup, ansibleTask)
}
}
ansible.raw = c
if err := c.validateDirective(ansible); err != nil {
return nil, err
}
return ansible, nil
}
func (c *rawAnsible) validateDirective(ansible *Ansible) (err error) {
if err := ansible.validate(); err != nil {
return err
}
return nil
}