MCPcopy
hub / github.com/cloudfoundry/cli / Execute

Method Execute

cf/commands/service/bind_service.go:107–145  ·  view source on GitHub ↗
(c flags.FlagContext)

Source from the content-addressed store, hash-verified

105}
106
107func (cmd *BindService) Execute(c flags.FlagContext) error {
108 app := cmd.appReq.GetApplication()
109 serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
110 params := c.String("c")
111
112 paramsMap, err := json.ParseJSONFromFileOrString(params)
113 if err != nil {
114 return errors.New(T("Invalid configuration provided for -c flag. Please provide a valid JSON object or path to a file containing a valid JSON object."))
115 }
116
117 cmd.ui.Say(T("Binding service {{.ServiceInstanceName}} to app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...",
118 map[string]interface{}{
119 "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name),
120 "AppName": terminal.EntityNameColor(app.Name),
121 "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
122 "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
123 "CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
124 }))
125
126 err = cmd.BindApplication(app, serviceInstance, paramsMap)
127 if err != nil {
128 if httperr, ok := err.(errors.HTTPError); ok && httperr.ErrorCode() == errors.ServiceBindingAppServiceTaken {
129 cmd.ui.Ok()
130 cmd.ui.Warn(T("App {{.AppName}} is already bound to {{.ServiceName}}.",
131 map[string]interface{}{
132 "AppName": app.Name,
133 "ServiceName": serviceInstance.Name,
134 }))
135 return nil
136 }
137
138 return err
139 }
140
141 cmd.ui.Ok()
142 cmd.ui.Say(T("TIP: Use '{{.CFCommand}} {{.AppName}}' to ensure your env variable changes take effect",
143 map[string]interface{}{"CFCommand": terminal.CommandColor(cf.Name + " restage"), "AppName": app.Name}))
144 return nil
145}
146
147func (cmd *BindService) BindApplication(app models.Application, serviceInstance models.ServiceInstance, paramsMap map[string]interface{}) error {
148 return cmd.serviceBindingRepo.Create(serviceInstance.GUID, app.GUID, paramsMap)

Callers

nothing calls this directly

Calls 15

BindApplicationMethod · 0.95
NewFunction · 0.92
EntityNameColorFunction · 0.92
CommandColorFunction · 0.92
GetApplicationMethod · 0.65
GetServiceInstanceMethod · 0.65
StringMethod · 0.65
SayMethod · 0.65
OrganizationFieldsMethod · 0.65
SpaceFieldsMethod · 0.65
UsernameMethod · 0.65

Tested by

no test coverage detected