Build API: Add version fetching endpoint.

BUG=chromium:979814
TEST=ran endpoint manually

Change-Id: Ifd400e6d7f92286f8313927fa5200e011a1fa395
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1682829
Commit-Queue: Alex Klein <saklein@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Evan Hernandez <evanhernandez@chromium.org>
Auto-Submit: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/api.py b/api/controller/api.py
index d1171d0..3a91baa 100644
--- a/api/controller/api.py
+++ b/api/controller/api.py
@@ -9,9 +9,24 @@
 
 from chromite.api import router as router_lib
 
+# API version number.
+# The major version MUST be updated on breaking changes.
+VERSION_MAJOR = 1
+# The minor and bug versions are not currently utilized, but put in place
+# to simplify future requirements.
+VERSION_MINOR = 0
+VERSION_BUG = 0
+
 
 def GetMethods(_input_proto, output_proto):
   """List all of the registered methods."""
   router = router_lib.GetRouter()
   for method in router.ListMethods():
     output_proto.methods.add().method = method
+
+
+def GetVersion(_input_proto, output_proto):
+  """Get the Build API major version number."""
+  output_proto.version.major = VERSION_MAJOR
+  output_proto.version.minor = VERSION_MINOR
+  output_proto.version.bug = VERSION_BUG
diff --git a/api/controller/api_unittest b/api/controller/api_unittest
new file mode 120000
index 0000000..ef3e37b
--- /dev/null
+++ b/api/controller/api_unittest
@@ -0,0 +1 @@
+../../scripts/wrapper.py
\ No newline at end of file
diff --git a/api/controller/api_unittest.py b/api/controller/api_unittest.py
new file mode 100644
index 0000000..63d136c
--- /dev/null
+++ b/api/controller/api_unittest.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""API controller tests."""
+
+from __future__ import print_function
+
+from chromite.api import router
+from chromite.api.controller import api as api_controller
+from chromite.api.gen.chromite.api import api_pb2
+from chromite.lib import cros_test_lib
+
+
+class GetMethodsTest(cros_test_lib.MockTestCase):
+  """GetMethods tests."""
+
+  def testGetMethods(self):
+    """Simple GetMethods sanity check."""
+    methods = ['foo', 'bar']
+    self.PatchObject(router.Router, 'ListMethods', return_value=methods)
+
+    request = api_pb2.MethodGetRequest()
+    response = api_pb2.MethodGetResponse()
+
+    api_controller.GetMethods(request, response)
+
+    self.assertItemsEqual(methods, [m.method for m in response.methods])
+
+
+class GetVersionTest(cros_test_lib.MockTestCase):
+  """GetVersion tests."""
+
+  def testGetVersion(self):
+    """Simple GetVersion sanity check."""
+    self.PatchObject(api_controller, 'VERSION_MAJOR', new=1)
+    self.PatchObject(api_controller, 'VERSION_MINOR', new=2)
+    self.PatchObject(api_controller, 'VERSION_BUG', new=3)
+
+    request = api_pb2.VersionGetRequest()
+    response = api_pb2.VersionGetResponse()
+
+    api_controller.GetVersion(request, response)
+
+    self.assertEqual(response.version.major, 1)
+    self.assertEqual(response.version.minor, 2)
+    self.assertEqual(response.version.bug, 3)