-
Notifications
You must be signed in to change notification settings - Fork 65
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_offerings/:guid #3579
Conversation
Describe("include broker field", func() { | ||
BeforeEach(func() { | ||
serviceBrokerRepo.ListServiceBrokersReturns([]repositories.ServiceBrokerRecord{{ | ||
ServiceBroker: services.ServiceBroker{ | ||
Name: "broker-name", | ||
}, | ||
CFResource: model.CFResource{ | ||
GUID: "broker-guid", | ||
}, | ||
}}, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need this, since we already test the include broker field in the ListServiceOfferings test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks a bit of a duplication. I would recommend having two whens: When("including broker name"
and When("including broker guid
that verify that proper broker fields are being returns. Error cases, as you have pointed out, are already covered in other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we use the generic include resolver as advised above testing becomes simpler too, for example
Entry("invalid service broker field", "fields[service_broker]=foo", MatchError(ContainSubstring("value must be one of: guid, name"))), | ||
) | ||
|
||
It("returns an error if a unsupported param is passed", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That it
could be an entry in the invalid query
table above. Here is a similar example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/presenter/service_offering.go
Outdated
@@ -54,3 +59,10 @@ func ForServiceOffering(serviceOffering repositories.ServiceOfferingRecord, base | |||
}, | |||
} | |||
} | |||
|
|||
func ForServiceOfferingWithIncluded(serviceOffering repositories.ServiceOfferingRecord, baseURL url.URL, includes ...model.IncludedResource) ServiceOfferingWithIncludedResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest adding the Included
field to the ServiceOfferingResponse
type rather than coming up with a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I took this approach, but this would mean that we would have to change the way it is handled in the list endpoint as well - https://github.com/cloudfoundry/korifi/blob/main/api/handlers/service_offering.go#L72. There we handle the "includes" with the ForList presenter and including it in the ForServiceOffering() would change ForList as well. Since only the LIST and GET endpoints for service offerings include fields, it did not seem right - https://v3-apidocs.cloudfoundry.org/version/3.180.0/index.html#fields-parameter. What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if the field is annotated with omitempty
, then I believe it should be not visible in the response. If I am correct, then
- the
get
handler would set it on theServiceOfferingResponse
object - the
list
handler would not, it would use the includes asForList
argument. As theIncludes
would not be set on theServiceOfferingResponse
object, they would be just omited in the response resources. TL;DR I believe that changing the list endpoint would not be necessary.
Or am I overlooking something?
|
||
if err = userClient.Get(ctx, client.ObjectKeyFromObject(offering), offering); err != nil { | ||
if k8serrors.IsForbidden(err) { | ||
return ServiceOfferingRecord{}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not be ignoring the forbidden error on Get
. Instead, we should translate it to korifi forbidden error. You have actually done that below.
Lets just get rid of the forbidden check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/handlers/service_offering.go
Outdated
return nil, apierrors.LogAndReturn(logger, err, "failed to get service offering: %s", serviceOfferingGUID) | ||
} | ||
|
||
brokerIncludes, err := h.getBrokerIncludes(r.Context(), authInfo, []repositories.ServiceOfferingRecord{serviceOffering}, payload.IncludeBrokerFields, h.serverURL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case should I replace the implementation on the list handler as well ?
Describe("include broker field", func() { | ||
BeforeEach(func() { | ||
serviceBrokerRepo.ListServiceBrokersReturns([]repositories.ServiceBrokerRecord{{ | ||
ServiceBroker: services.ServiceBroker{ | ||
Name: "broker-name", | ||
}, | ||
CFResource: model.CFResource{ | ||
GUID: "broker-guid", | ||
}, | ||
}}, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we use the generic include resolver as advised above testing becomes simpler too, for example
api/payloads/service_offering.go
Outdated
@@ -10,6 +10,25 @@ import ( | |||
jellidation "github.com/jellydator/validation" | |||
) | |||
|
|||
type ServiceOfferingGet struct { | |||
IncludeBrokerFields []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using the IncludeReourceRule
type as we do for plans
3ac24cd
to
5166ac1
Compare
Requested chages are done
Is there a related GitHub Issue?
#3578
What is this change about?
Here we add GetServiceOffering - GET v3/service_offerings/:guid
Does this PR introduce a breaking change?
no
Acceptance Steps
Tag your pair, your PM, and/or team