(c flags.FlagContext)
| 105 | } |
| 106 | |
| 107 | func (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 | |
| 147 | func (cmd *BindService) BindApplication(app models.Application, serviceInstance models.ServiceInstance, paramsMap map[string]interface{}) error { |
| 148 | return cmd.serviceBindingRepo.Create(serviceInstance.GUID, app.GUID, paramsMap) |
nothing calls this directly
no test coverage detected