Build API: Add validate-only functionality.
Add the ability to request only validating the call arguments.
The validation-only call allow testing calls against branched
code, and more quickly verifying inputs than by running the
full endpoint.
This is only the core functionality for the validation.
BUG=chromium:987263
TEST=run_tests
Cq-Depend: chromium:1726253
Change-Id: I235443b0e7f29409d0229fabb9a22927c56c7ebf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1726252
Commit-Queue: Alex Klein <saklein@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: David Burger <dburger@chromium.org>
Reviewed-by: Evan Hernandez <evanhernandez@chromium.org>
diff --git a/api/validate.py b/api/validate.py
index 230eedc..a42b5d3 100644
--- a/api/validate.py
+++ b/api/validate.py
@@ -38,6 +38,7 @@
return value
+
#pylint: disable=docstring-misnamed-args
def exists(*fields):
"""Validate that the paths in |fields| exist.
@@ -88,3 +89,20 @@
return _require
return decorator
+
+
+def validation_complete(func):
+ """Automatically skip the endpoint when called after all other validators.
+
+ This decorator MUST be applied after all other validate decorators.
+ The config can be checked manually if there is non-decorator validation, but
+ this is much cleaner if it is all done in decorators.
+ """
+ def _validate_only(request, response, configs, *args, **kwargs):
+ if configs.validate_only:
+ # Avoid calling the endpoint.
+ return 0
+ else:
+ return func(request, response, configs, *args, **kwargs)
+
+ return _validate_only