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/scripts/build_api.py b/scripts/build_api.py
index 44c3218..d2fdaa8 100644
--- a/scripts/build_api.py
+++ b/scripts/build_api.py
@@ -9,6 +9,7 @@
 
 import os
 
+from chromite.api import api_config as api_config_lib
 from chromite.api import router as router_lib
 from chromite.lib import commandline
 from chromite.lib import cros_build_lib
@@ -29,6 +30,12 @@
   parser.add_argument(
       '--output-json', type='path', required=True,
       help='The path to which the result protobuf message should be written.')
+  # Run configuration options.
+  parser.add_argument(
+      '--validate-only', action='store_true', default=False,
+      help='When set, only runs the argument validation logic. Calls produce'
+           'a return code of 0 iff the arguments comprise a valid call to the'
+           'endpoint, or 1 otherwise.')
 
   return parser
 
@@ -60,6 +67,8 @@
   if not os.path.exists(opts.input_json):
     parser.error('Input file does not exist.')
 
+  opts.config = api_config_lib.ApiConfig(validate_only=opts.validate_only)
+
   opts.Freeze()
   return opts
 
@@ -71,7 +80,7 @@
 
   try:
     return router.Route(opts.service, opts.method, opts.input_json,
-                        opts.output_json)
+                        opts.output_json, opts.config)
   except router_lib.Error as e:
     # Handle router_lib.Error derivatives nicely, but let anything else bubble
     # up.