Skip to content

Commit

Permalink
Added the service broker guid to the ServiceBroker type (#149)
Browse files Browse the repository at this point in the history
* Add support for service instance creation with parameters and/or tags

* Fetch all pages of data for ListServicePlansByQuery, not just the first

* Return all pages of results for ListServicesByQuery, not just the first page

* Use next_url when listing all service plans and services

* Add support for the Service Broker management APIs

* Added GetServiceByGuid and unit test for it

* Added Delete, Update, and GetByGuid calls for Service Plan Visibility entities

* *. Added Guid to the ServiceBroker struct
*. Added a convenience method to create a service_plan_visibility object based on the service plan unique id
  • Loading branch information
liorokman authored and lnguyen committed Nov 13, 2017
1 parent e67b935 commit ffcad5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion service_brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type CreateServiceBrokerRequest struct {
}

type ServiceBroker struct {
Guid string `json:"guid"`
Name string `json:"name"`
BrokerURL string `json:"broker_url"`
Username string `json:"auth_username"`
Expand Down Expand Up @@ -87,7 +88,7 @@ func (c *Client) UpdateServiceBroker(guid string, usb UpdateServiceBrokerRequest
if err != nil {
return ServiceBroker{}, err
}

serviceBrokerResource.Entity.Guid = serviceBrokerResource.Meta.Guid
return serviceBrokerResource.Entity, nil
}

Expand Down Expand Up @@ -118,6 +119,7 @@ func (c *Client) CreateServiceBroker(csb CreateServiceBrokerRequest) (ServiceBro
return ServiceBroker{}, err
}

serviceBrokerResource.Entity.Guid = serviceBrokerResource.Meta.Guid
return serviceBrokerResource.Entity, nil
}

Expand All @@ -130,6 +132,7 @@ func (c *Client) ListServiceBrokersByQuery(query url.Values) ([]ServiceBroker, e
return []ServiceBroker{}, err
}
for _, sb := range serviceBrokerResp.Resources {
sb.Entity.Guid = sb.Meta.Guid
sbs = append(sbs, sb.Entity)
}
requestUrl = serviceBrokerResp.NextUrl
Expand Down Expand Up @@ -160,6 +163,7 @@ func (c *Client) GetServiceBrokerByGuid(guid string) (ServiceBroker, error) {
if err != nil {
return ServiceBroker{}, err
}
serviceBrokerRes.Entity.Guid = serviceBrokerRes.Meta.Guid
return serviceBrokerRes.Entity, nil
}

Expand Down
1 change: 1 addition & 0 deletions service_brokers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestListServiceBrokers(t *testing.T) {
So(err, ShouldBeNil)

So(len(servicePlans), ShouldEqual, 1)
So(servicePlans[0].Guid, ShouldEqual, "90a413fd-a636-4133-8bfb-a94b07839e96")
So(servicePlans[0].Name, ShouldEqual, "name-85")
So(servicePlans[0].BrokerURL, ShouldEqual, "https://foo.com/url-2")
So(servicePlans[0].Username, ShouldEqual, "auth_username-2")
Expand Down
11 changes: 11 additions & 0 deletions service_plan_visibilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ func (c *Client) GetServicePlanVisibilityByGuid(guid string) (ServicePlanVisibil
return respBodyToServicePlanVisibility(resp.Body, c)
}

//a uniqueID is the id of the service in the catalog and not in cf internal db
func (c *Client) CreateServicePlanVisibilityByUniqueId(uniqueId string, organizationGuid string) (ServicePlanVisibility, error) {
q := url.Values{}
q.Set("q", fmt.Sprintf("unique_id:%s", uniqueId))
plans, err := c.ListServicePlansByQuery(q)
if err != nil {
return ServicePlanVisibility{}, errors.Wrap(err, fmt.Sprintf("Couldn't find a service plan with unique_id: %s", uniqueId))
}
return c.CreateServicePlanVisibility(plans[0].Guid, organizationGuid)
}

func (c *Client) CreateServicePlanVisibility(servicePlanGuid string, organizationGuid string) (ServicePlanVisibility, error) {
req := c.NewRequest("POST", "/v2/service_plan_visibilities")
req.obj = map[string]interface{}{
Expand Down

0 comments on commit ffcad5e

Please sign in to comment.