Skip to content

Commit

Permalink
Merge branch 'main' into delete_plan_visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
klapkov authored Dec 10, 2024
2 parents f5df5f7 + d8705f9 commit a31e6c6
Show file tree
Hide file tree
Showing 32 changed files with 897 additions and 102 deletions.
78 changes: 78 additions & 0 deletions api/handlers/fake/cfservice_offering_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions api/handlers/fake/cfservice_plan_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
19 changes: 19 additions & 0 deletions api/handlers/service_offering.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
type CFServiceOfferingRepository interface {
GetServiceOffering(context.Context, authorization.Info, string) (repositories.ServiceOfferingRecord, error)
ListOfferings(context.Context, authorization.Info, repositories.ListServiceOfferingMessage) ([]repositories.ServiceOfferingRecord, error)
DeleteOffering(context.Context, authorization.Info, repositories.DeleteServiceOfferingMessage) error
}

type ServiceOffering struct {
Expand Down Expand Up @@ -103,6 +104,23 @@ func (h *ServiceOffering) list(r *http.Request) (*routing.Response, error) {
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForList(presenter.ForServiceOffering, serviceOfferingList, h.serverURL, *r.URL, includedResources...)), nil
}

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

payload := new(payloads.ServiceOfferingDelete)
if err := h.requestValidator.DecodeAndValidateURLValues(r, payload); err != nil {
return nil, apierrors.LogAndReturn(logger, err, "Unable to decode request query parameters")
}

serviceOfferingGUID := routing.URLParam(r, "guid")
if err := h.serviceOfferingRepo.DeleteOffering(r.Context(), authInfo, payload.ToMessage(serviceOfferingGUID)); err != nil {
return nil, apierrors.LogAndReturn(logger, err, "failed to delete service offering: %s", serviceOfferingGUID)
}

return routing.NewResponse(http.StatusNoContent), nil
}

func (h *ServiceOffering) UnauthenticatedRoutes() []routing.Route {
return nil
}
Expand All @@ -111,5 +129,6 @@ func (h *ServiceOffering) AuthenticatedRoutes() []routing.Route {
return []routing.Route{
{Method: "GET", Pattern: ServiceOfferingPath, Handler: h.get},
{Method: "GET", Pattern: ServiceOfferingsPath, Handler: h.list},
{Method: "DELETE", Pattern: ServiceOfferingPath, Handler: h.delete},
}
}
Loading

0 comments on commit a31e6c6

Please sign in to comment.