Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GET v3/service_brokers/:guid #3644

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/handlers/service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ func (h *ServiceBroker) list(r *http.Request) (*routing.Response, error) {
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForList(presenter.ForServiceBroker, brokers, h.serverURL, *r.URL)), nil
}

func (h *ServiceBroker) get(r *http.Request) (*routing.Response, error) {
authInfo, _ := authorization.InfoFromContext(r.Context())
logger := logr.FromContextOrDiscard(r.Context()).WithName("handlers.service-broker.list")

guid := routing.URLParam(r, "guid")
broker, err := h.serviceBrokerRepo.GetServiceBroker(r.Context(), authInfo, guid)
if err != nil {
return nil, apierrors.LogAndReturn(logger, apierrors.ForbiddenAsNotFound(err), "failed to get service broker")
}

return routing.NewResponse(http.StatusOK).WithBody(presenter.ForServiceBroker(broker, h.serverURL)), nil
}

func (h *ServiceBroker) delete(r *http.Request) (*routing.Response, error) {
authInfo, _ := authorization.InfoFromContext(r.Context())
logger := logr.FromContextOrDiscard(r.Context()).WithName("handlers.service-broker.delete")
Expand Down Expand Up @@ -136,6 +149,7 @@ func (h *ServiceBroker) AuthenticatedRoutes() []routing.Route {
return []routing.Route{
{Method: "POST", Pattern: ServiceBrokersPath, Handler: h.create},
{Method: "GET", Pattern: ServiceBrokersPath, Handler: h.list},
{Method: "GET", Pattern: ServiceBrokerPath, Handler: h.get},
{Method: "DELETE", Pattern: ServiceBrokerPath, Handler: h.delete},
{Method: "PATCH", Pattern: ServiceBrokerPath, Handler: h.update},
}
Expand Down
46 changes: 46 additions & 0 deletions api/handlers/service_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,52 @@ var _ = Describe("ServiceBroker", func() {
})
})

Describe("GET /v3/service_brokers/guid", func() {
BeforeEach(func() {
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{
CFResource: model.CFResource{
GUID: "broker-guid",
},
}, nil)

var err error
req, err = http.NewRequestWithContext(ctx, "GET", "/v3/service_brokers/broker-guid", nil)
Expect(err).NotTo(HaveOccurred())
})

It("gets the service broker", func() {
Expect(serviceBrokerRepo.GetServiceBrokerCallCount()).To(Equal(1))
_, actualAuthInfo, actualBrokerGUID := serviceBrokerRepo.GetServiceBrokerArgsForCall(0)
Expect(actualAuthInfo).To(Equal(authInfo))
Expect(actualBrokerGUID).To(Equal("broker-guid"))

Expect(rr).To(HaveHTTPStatus(http.StatusOK))
Expect(rr).To(HaveHTTPBody(SatisfyAll(
MatchJSONPath("$.guid", "broker-guid"),
)))
})

When("getting the service broker is not allowed", func() {
BeforeEach(func() {
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{}, apierrors.NewForbiddenError(nil, repositories.ServiceBrokerResourceType))
})

It("returns a not found error", func() {
expectNotFoundError(repositories.ServiceBrokerResourceType)
})
})

When("getting the service broker fails with an error", func() {
BeforeEach(func() {
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{}, errors.New("get-broker-err"))
})

It("returns an error", func() {
expectUnknownError()
})
})
})

Describe("DELETE /v3/service_brokers/guid", func() {
BeforeEach(func() {
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/service_brokers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ var _ = Describe("Service Brokers", func() {
})
})

Describe("Get", func() {
var (
result responseResource
brokerGUID string
)

BeforeEach(func() {
brokerGUID = createBroker(serviceBrokerURL)
})

AfterEach(func() {
broker.NewCatalogDeleter(rootNamespace).ForBrokerGUID(brokerGUID).Delete()
})

JustBeforeEach(func() {
resp, err = adminClient.R().SetResult(&result).Get("/v3/service_brokers/" + brokerGUID)
Expect(err).NotTo(HaveOccurred())
})

It("returns the service broker", func() {
Expect(resp).To(HaveRestyStatusCode(http.StatusOK))
Expect(result.GUID).To(Equal(brokerGUID))
})
})

Describe("Update", func() {
var brokerGUID string

Expand Down