-
Notifications
You must be signed in to change notification settings - Fork 929
/
apply_manifest_command.go
113 lines (88 loc) · 3.09 KB
/
apply_manifest_command.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package v7
import (
"os"
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/command/v7/shared"
"code.cloudfoundry.org/cli/util/manifestparser"
"code.cloudfoundry.org/clock"
"github.com/cloudfoundry/bosh-cli/director/template"
)
//go:generate counterfeiter . ApplyManifestActor
type ApplyManifestActor interface {
SetSpaceManifest(spaceGUID string, rawManifest []byte) (v7action.Warnings, error)
}
//go:generate counterfeiter . ManifestParser
type ManifestParser interface {
FullRawManifest() []byte
InterpolateAndParse(pathToManifest string, pathsToVarsFiles []string, vars []template.VarKV, appName string) error
}
type ApplyManifestCommand struct {
PathToManifest flag.ManifestPathWithExistenceCheck `short:"f" description:"Path to app manifest"`
usage interface{} `usage:"CF_NAME apply-manifest -f APP_MANIFEST_PATH"`
relatedCommands interface{} `related_commands:"create-app, create-app-manifest, push"`
UI command.UI
Config command.Config
SharedActor command.SharedActor
ManifestLocator ManifestLocator
Actor ApplyManifestActor
Parser ManifestParser
CWD string
}
func (cmd *ApplyManifestCommand) Setup(config command.Config, ui command.UI) error {
cmd.UI = ui
cmd.Config = config
cmd.SharedActor = sharedaction.NewActor(config)
ccClient, _, err := shared.GetNewClientsAndConnectToCF(config, ui, "")
if err != nil {
return err
}
cmd.Actor = v7action.NewActor(ccClient, config, nil, nil, clock.NewClock())
cmd.ManifestLocator = manifestparser.NewLocator()
cmd.Parser = manifestparser.NewParser()
currentDir, err := os.Getwd()
cmd.CWD = currentDir
return err
}
func (cmd ApplyManifestCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, true)
if err != nil {
return err
}
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
var manifestReadPath = string(cmd.PathToManifest)
if manifestReadPath == "" {
locatorPath := cmd.CWD
resolvedPath, exists, err := cmd.ManifestLocator.Path(locatorPath)
if err != nil {
return err
}
if !exists {
return translatableerror.ManifestFileNotFoundInDirectoryError{PathToManifest: locatorPath}
}
manifestReadPath = resolvedPath
}
cmd.UI.DisplayTextWithFlavor("Applying manifest {{.ManifestPath}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"ManifestPath": manifestReadPath,
"OrgName": cmd.Config.TargetedOrganization().Name,
"SpaceName": cmd.Config.TargetedSpace().Name,
"Username": user.Name,
})
err = cmd.Parser.InterpolateAndParse(manifestReadPath, nil, nil, "")
if err != nil {
return err
}
warnings, err := cmd.Actor.SetSpaceManifest(cmd.Config.TargetedSpace().GUID, cmd.Parser.FullRawManifest())
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
cmd.UI.DisplayOK()
return nil
}