-
Notifications
You must be signed in to change notification settings - Fork 3
/
cf.go
76 lines (67 loc) · 1.48 KB
/
cf.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
package mapper
import (
"code.cloudfoundry.org/cli/util/manifestparser"
"github.com/springernature/halfpipe/manifest"
"strings"
)
type cf struct {
}
func (c cf) Apply(original manifest.Manifest) (updated manifest.Manifest, err error) {
updated = original
u, err := c.updateTasks(updated.Tasks)
if err != nil {
return
}
updated.Tasks = u
return updated, nil
}
func (c cf) updateTasks(tasks manifest.TaskList) (updated manifest.TaskList, err error) {
for _, task := range tasks {
switch task := task.(type) {
case manifest.Parallel:
u, e := c.updateTasks(task.Tasks)
if e != nil {
err = e
return
}
task.Tasks = u
updated = append(updated, task)
case manifest.Sequence:
u, e := c.updateTasks(task.Tasks)
if e != nil {
err = e
return
}
task.Tasks = u
updated = append(updated, task)
case manifest.DeployCF:
cf, e := c.mapCf(task)
if e != nil {
err = e
return
}
updated = append(updated, cf)
default:
updated = append(updated, task)
}
}
return updated, err
}
func (c cf) mapCf(cf manifest.DeployCF) (updated manifest.DeployCF, err error) {
updated = cf
if strings.HasPrefix(cf.Manifest, "../") {
return
}
cfManifest, err := manifestparser.ManifestParser{}.InterpolateAndParse(cf.Manifest, nil, nil)
if err != nil {
return
}
if cfManifest.Applications[0].Docker != nil {
updated.IsDockerPush = true
}
updated.CfApplication = cfManifest.Applications[0]
return
}
func NewCfMapper() Mapper {
return cf{}
}