-
Notifications
You must be signed in to change notification settings - Fork 199
/
raw_import.go
80 lines (61 loc) · 1.71 KB
/
raw_import.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
package config
type rawImport struct {
ImageName string `yaml:"image,omitempty"`
ArtifactName string `yaml:"artifact,omitempty"`
Before string `yaml:"before,omitempty"`
After string `yaml:"after,omitempty"`
Stage string `yaml:"stage,omitempty"`
rawArtifactExport `yaml:",inline"`
rawStapelImage *rawStapelImage `yaml:"-"` // parent
UnsupportedAttributes map[string]interface{} `yaml:",inline"`
}
func (c *rawImport) configSection() interface{} {
return c
}
func (c *rawImport) doc() *doc {
return c.rawStapelImage.doc
}
func (c *rawImport) UnmarshalYAML(unmarshal func(interface{}) error) error {
if parent, ok := parentStack.Peek().(*rawStapelImage); ok {
c.rawStapelImage = parent
}
parentStack.Push(c)
type plain rawImport
err := unmarshal((*plain)(c))
parentStack.Pop()
if err != nil {
return err
}
c.rawArtifactExport.inlinedIntoRaw(c)
if err := checkOverflow(c.UnsupportedAttributes, c, c.rawStapelImage.doc); err != nil {
return err
}
if c.rawArtifactExport.rawExportBase.To == "" {
c.rawArtifactExport.rawExportBase.To = c.rawArtifactExport.rawExportBase.Add
}
return nil
}
func (c *rawImport) toDirective() (imp *Import, err error) {
imp = &Import{}
if artifactExport, err := c.rawArtifactExport.toDirective(); err != nil {
return nil, err
} else {
imp.ArtifactExport = artifactExport
}
imp.ImageName = c.ImageName
imp.ArtifactName = c.ArtifactName
imp.Before = c.Before
imp.After = c.After
imp.Stage = c.Stage
imp.raw = c
if err = c.validateDirective(imp); err != nil {
return nil, err
}
return imp, nil
}
func (c *rawImport) validateDirective(imp *Import) (err error) {
if err = imp.validate(); err != nil {
return err
}
return nil
}