diff --git a/cf/api/fakes/fake_user_provided_service_instance_repo.go b/cf/api/fakes/fake_user_provided_service_instance_repo.go index ca2fbdf1694..7011d0fc16c 100644 --- a/cf/api/fakes/fake_user_provided_service_instance_repo.go +++ b/cf/api/fakes/fake_user_provided_service_instance_repo.go @@ -5,12 +5,12 @@ import "github.com/cloudfoundry/cli/cf/models" type FakeUserProvidedServiceInstanceRepo struct { CreateName string CreateDrainUrl string - CreateParams map[string]string + CreateParams map[string]interface{} UpdateServiceInstance models.ServiceInstanceFields } -func (repo *FakeUserProvidedServiceInstanceRepo) Create(name, drainUrl string, params map[string]string) (apiErr error) { +func (repo *FakeUserProvidedServiceInstanceRepo) Create(name, drainUrl string, params map[string]interface{}) (apiErr error) { repo.CreateName = name repo.CreateDrainUrl = drainUrl repo.CreateParams = params diff --git a/cf/api/user_provided_service_instances.go b/cf/api/user_provided_service_instances.go index 307b8da08ab..23ff89172fd 100644 --- a/cf/api/user_provided_service_instances.go +++ b/cf/api/user_provided_service_instances.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/cloudfoundry/cli/cf/configuration" "github.com/cloudfoundry/cli/cf/errors" "github.com/cloudfoundry/cli/cf/models" @@ -11,7 +12,7 @@ import ( ) type UserProvidedServiceInstanceRepository interface { - Create(name, drainUrl string, params map[string]string) (apiErr error) + Create(name, drainUrl string, params map[string]interface{}) (apiErr error) Update(serviceInstanceFields models.ServiceInstanceFields) (apiErr error) } @@ -26,14 +27,14 @@ func NewCCUserProvidedServiceInstanceRepository(config configuration.Reader, gat return } -func (repo CCUserProvidedServiceInstanceRepository) Create(name, drainUrl string, params map[string]string) (apiErr error) { +func (repo CCUserProvidedServiceInstanceRepository) Create(name, drainUrl string, params map[string]interface{}) (apiErr error) { path := fmt.Sprintf("%s/v2/user_provided_service_instances", repo.config.ApiEndpoint()) type RequestBody struct { - Name string `json:"name"` - Credentials map[string]string `json:"credentials"` - SpaceGuid string `json:"space_guid"` - SysLogDrainUrl string `json:"syslog_drain_url"` + Name string `json:"name"` + Credentials map[string]interface{} `json:"credentials"` + SpaceGuid string `json:"space_guid"` + SysLogDrainUrl string `json:"syslog_drain_url"` } jsonBytes, err := json.Marshal(RequestBody{ @@ -55,8 +56,8 @@ func (repo CCUserProvidedServiceInstanceRepository) Update(serviceInstanceFields path := fmt.Sprintf("%s/v2/user_provided_service_instances/%s", repo.config.ApiEndpoint(), serviceInstanceFields.Guid) type RequestBody struct { - Credentials map[string]string `json:"credentials,omitempty"` - SysLogDrainUrl string `json:"syslog_drain_url,omitempty"` + Credentials map[string]interface{} `json:"credentials,omitempty"` + SysLogDrainUrl string `json:"syslog_drain_url,omitempty"` } reqBody := RequestBody{serviceInstanceFields.Params, serviceInstanceFields.SysLogDrainUrl} diff --git a/cf/api/user_provided_service_instances_test.go b/cf/api/user_provided_service_instances_test.go index b2fe5a20922..af8eb3fc0ec 100644 --- a/cf/api/user_provided_service_instances_test.go +++ b/cf/api/user_provided_service_instances_test.go @@ -29,7 +29,7 @@ var _ = Describe("UserProvidedServiceRepository", func() { ts, handler, repo := createUserProvidedServiceInstanceRepo(req) defer ts.Close() - apiErr := repo.Create("my-custom-service", "", map[string]string{ + apiErr := repo.Create("my-custom-service", "", map[string]interface{}{ "host": "example.com", "user": "me", "password": "secret", @@ -49,7 +49,7 @@ var _ = Describe("UserProvidedServiceRepository", func() { ts, handler, repo := createUserProvidedServiceInstanceRepo(req) defer ts.Close() - apiErr := repo.Create("my-custom-service", "syslog://example.com", map[string]string{ + apiErr := repo.Create("my-custom-service", "syslog://example.com", map[string]interface{}{ "host": "example.com", "user": "me", "password": "secret", @@ -69,7 +69,7 @@ var _ = Describe("UserProvidedServiceRepository", func() { ts, handler, repo := createUserProvidedServiceInstanceRepo(req) defer ts.Close() - params := map[string]string{ + params := map[string]interface{}{ "host": "example.com", "user": "me", "password": "secret", diff --git a/cf/commands/service/create_user_provided_service.go b/cf/commands/service/create_user_provided_service.go index 4c8799d5b4d..bdb113619b3 100644 --- a/cf/commands/service/create_user_provided_service.go +++ b/cf/commands/service/create_user_provided_service.go @@ -66,7 +66,7 @@ func (cmd CreateUserProvidedService) Run(c *cli.Context) { params := c.String("p") params = strings.Trim(params, `"`) - paramsMap := make(map[string]string) + paramsMap := make(map[string]interface{}) err := json.Unmarshal([]byte(params), ¶msMap) if err != nil && params != "" { @@ -90,7 +90,7 @@ func (cmd CreateUserProvidedService) Run(c *cli.Context) { cmd.ui.Ok() } -func (cmd CreateUserProvidedService) mapValuesFromPrompt(params string, paramsMap map[string]string) map[string]string { +func (cmd CreateUserProvidedService) mapValuesFromPrompt(params string, paramsMap map[string]interface{}) map[string]interface{} { for _, param := range strings.Split(params, ",") { param = strings.Trim(param, " ") paramsMap[param] = cmd.ui.Ask("%s", param) diff --git a/cf/commands/service/create_user_provided_service_test.go b/cf/commands/service/create_user_provided_service_test.go index e523fe1298f..bce703db90d 100644 --- a/cf/commands/service/create_user_provided_service_test.go +++ b/cf/commands/service/create_user_provided_service_test.go @@ -58,7 +58,7 @@ var _ = Describe("create-user-provided-service command", func() { )) Expect(repo.CreateName).To(Equal("my-custom-service")) - Expect(repo.CreateParams).To(Equal(map[string]string{ + Expect(repo.CreateParams).To(Equal(map[string]interface{}{ "foo": "foo value", "bar": "bar value", "baz": "baz value", @@ -71,15 +71,15 @@ var _ = Describe("create-user-provided-service command", func() { }) It("accepts service parameters as JSON without prompting", func() { - args := []string{"-p", `{"foo": "foo value", "bar": "bar value", "baz": "baz value"}`, "my-custom-service"} + args := []string{"-p", `{"foo": "foo value", "bar": "bar value", "baz": 4}`, "my-custom-service"} testcmd.RunCommand(cmd, args, requirementsFactory) Expect(ui.Prompts).To(BeEmpty()) Expect(repo.CreateName).To(Equal("my-custom-service")) - Expect(repo.CreateParams).To(Equal(map[string]string{ + Expect(repo.CreateParams).To(Equal(map[string]interface{}{ "foo": "foo value", "bar": "bar value", - "baz": "baz value", + "baz": float64(4), })) Expect(ui.Outputs).To(ContainSubstrings( diff --git a/cf/commands/service/update_user_provided_service.go b/cf/commands/service/update_user_provided_service.go index 9c321505829..6b7b5d1f94f 100644 --- a/cf/commands/service/update_user_provided_service.go +++ b/cf/commands/service/update_user_provided_service.go @@ -71,7 +71,7 @@ func (cmd *UpdateUserProvidedService) Run(c *cli.Context) { drainUrl := c.String("l") params := c.String("p") - paramsMap := make(map[string]string) + paramsMap := make(map[string]interface{}) if params != "" { err := json.Unmarshal([]byte(params), ¶msMap) diff --git a/cf/commands/service/update_user_provided_service_test.go b/cf/commands/service/update_user_provided_service_test.go index a4bb0bb160a..64d671fcb46 100644 --- a/cf/commands/service/update_user_provided_service_test.go +++ b/cf/commands/service/update_user_provided_service_test.go @@ -80,7 +80,7 @@ var _ = Describe("update-user-provided-service test", func() { []string{"TIP"}, )) Expect(serviceRepo.UpdateServiceInstance.Name).To(Equal("service-name")) - Expect(serviceRepo.UpdateServiceInstance.Params).To(Equal(map[string]string{"foo": "bar"})) + Expect(serviceRepo.UpdateServiceInstance.Params).To(Equal(map[string]interface{}{"foo": "bar"})) Expect(serviceRepo.UpdateServiceInstance.SysLogDrainUrl).To(Equal("syslog://example.com")) }) }) diff --git a/cf/models/service_instance.go b/cf/models/service_instance.go index 76d3e0adb2e..f3ed5129435 100644 --- a/cf/models/service_instance.go +++ b/cf/models/service_instance.go @@ -5,7 +5,7 @@ type ServiceInstanceFields struct { Name string SysLogDrainUrl string ApplicationNames []string - Params map[string]string + Params map[string]interface{} } type ServiceInstance struct {