-
Notifications
You must be signed in to change notification settings - Fork 89
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
[scd] factor out parameter validation for oir upsert method #1089
[scd] factor out parameter validation for oir upsert method #1089
Conversation
bc92dcc
to
8524493
Compare
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.
Nice, thanks! That's indeed a good first step in cutting up this function. With this construct it will also be easy when it makes sense to start factoring away some logic into functions of validOIRUpsertParams
I just have some minor comments.
subscriptionID dssmodels.ID | ||
} | ||
|
||
func (a *Server) validateAndReturnUpsertParams( |
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.
Pass AllowHTTPBaseUrls
as a param to avoid attaching this to Server
?
upsertParams, err := a.validateAndReturnUpsertParams(authorizedManager, entityid, ovn, params) | ||
if err != nil { | ||
// Important note: | ||
// - stacktrace.Propagate sets NoCode as the code for the error | ||
// - subsequently, stacktrace.GetCode(err) only looks into the first error in the stack and returns NoCode if the error has no code | ||
// - therefore, we need to explicitly use stacktrace.PropagateWithCode if we want the calling logic | ||
// to be able to retrieve the code of the error | ||
// TODO we can consider fixing this in the stacktrace library | ||
return nil, nil, stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), "Failed to validate Operational Intent Reference upsert parameters") |
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.
Here I suggest making validateAndReturnUpsertParams
purely a validation function by:
- move out of
validateAndReturnUpsertParams
the two cases of errorsdsserr.PermissionDenied
- never returning any code within
validateAndReturnUpsertParams
- if
err != nil
set the codedsserr.BadRequest
That makes it clear this function validates the input to create the op intent and any error implies bad input. That should also enable passing the manager instead of the whole authorizedManager
.
eb4a8b5
to
9030146
Compare
9030146
to
f041be8
Compare
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.
LGTM - thanks
A first small step towards #1088.
This takes care of moving the parameter validation to a submethod. It is not yet improving anything with respect to the core business logic, but allows readers to more directly focus on the code of what
upsertOperationalIntentReference
does.Note about the usage of the
stacktrace
library and our dependency on error codes: as we use the error codes to decide what HTTP response to send back, it is important that we properly propagate them when we move logic one or several layers of method calls.