Skip to content

Commit

Permalink
move validation calls
Browse files Browse the repository at this point in the history
  • Loading branch information
killianmuldoon committed May 31, 2022
1 parent 32a4219 commit 518a919
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions internal/runtime/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,20 @@ func (c *client) CallAllExtensions(ctx context.Context, hook runtimecatalog.Hook
if err != nil {
return errors.Wrap(err, "failed to compute GroupVersionHook")
}
// Make sure the request is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateRequest(gvh, request); err != nil {
return errors.Wrapf(err, "request object is invalid for hook %s", gvh)
}
// Make sure the response is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateResponse(gvh, response); err != nil {
return errors.Wrapf(err, "response object is invalid for hook %s", gvh)
}
registrations, err := c.registry.List(gvh.GroupHook())
if err != nil {
return errors.Wrapf(err, "failed to retrieve ExtensionHandlers for %s", gvh.GroupHook())
}
responses := []runtimehooksv1.ResponseObject{}
for _, registration := range registrations {
// Make sure the request is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateRequest(registration.GroupVersionHook, request); err != nil {
return errors.Wrapf(err, "request object is invalid for hook %s", registration.GroupVersionHook)
}
// Make sure the response is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateResponse(registration.GroupVersionHook, response); err != nil {
return errors.Wrapf(err, "response object is invalid for hook %s", registration.GroupVersionHook)
}
// Creates a new instance of the response parameter.
responseObject, err := c.catalog.NewResponse(gvh)
if err != nil {
Expand Down Expand Up @@ -227,21 +227,21 @@ func (c *client) CallExtension(ctx context.Context, hook runtimecatalog.Hook, na
if err != nil {
return errors.Wrap(err, "failed to compute GroupVersionHook")
}
// Make sure the request is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateRequest(hookGVH, request); err != nil {
return errors.Wrapf(err, "request object is invalid for hook %s", hookGVH)
}
// Make sure the response is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateResponse(hookGVH, response); err != nil {
return errors.Wrapf(err, "response object is invalid for hook %s", hookGVH)
}
registration, err := c.registry.Get(name)
if err != nil {
return errors.Wrapf(err, "failed to retrieve ExtensionHandler with name %q", name)
}
if hookGVH.GroupHook() != registration.GroupVersionHook.GroupHook() {
return errors.Errorf("ExtensionHandler %q does not match group %s, hook %s", name, hookGVH.Group, hookGVH.Hook)
}
// Make sure the request is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateRequest(registration.GroupVersionHook, request); err != nil {
return errors.Wrapf(err, "request object is invalid for hook %s", registration.GroupVersionHook)
}
// Make sure the response is compatible with the version of the hook expected by the ExtensionHandler.
if err := c.catalog.ValidateResponse(registration.GroupVersionHook, response); err != nil {
return errors.Wrapf(err, "response object is invalid for hook %s", registration.GroupVersionHook)
}
var timeoutDuration time.Duration
if registration.TimeoutSeconds != nil {
timeoutDuration = time.Duration(*registration.TimeoutSeconds) * time.Second
Expand Down

0 comments on commit 518a919

Please sign in to comment.