blob: 78113681bf82fde3dd9bbf90cc5e36d9fbd85360 [file] [log] [blame]
Alex Klein54e38e32019-06-21 14:54:17 -06001# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""API information controller."""
6
Alex Klein5dffe5e2021-02-19 15:50:00 -07007import os
8
Alex Klein076841b2019-08-29 15:19:39 -06009from chromite.api import faux
Alex Klein54e38e32019-06-21 14:54:17 -060010from chromite.api import router as router_lib
Alex Klein231d2da2019-07-22 16:44:45 -060011from chromite.api import validate
Alex Klein5dffe5e2021-02-19 15:50:00 -070012from chromite.lib import constants
13from chromite.lib import cros_build_lib
Alex Klein54e38e32019-06-21 14:54:17 -060014
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040015
Alex Klein104b0672019-06-28 15:43:00 -060016# API version number.
17# The major version MUST be updated on breaking changes.
18VERSION_MAJOR = 1
19# The minor and bug versions are not currently utilized, but put in place
20# to simplify future requirements.
21VERSION_MINOR = 0
22VERSION_BUG = 0
23
Alex Klein54e38e32019-06-21 14:54:17 -060024
Alex Kleinf725e102021-02-19 15:48:54 -070025def _CompileProtoSuccess(_input_proto, output_proto, _config):
26 """Mock success response for CompileProto."""
27 output_proto.modified_files.add().path = '/code/chromite/api/gen/foo_pb2.py'
28
29
30@faux.success(_CompileProtoSuccess)
31@faux.empty_error
32@validate.validation_complete
Alex Klein5dffe5e2021-02-19 15:50:00 -070033def CompileProto(_input_proto, output_proto, _config):
Alex Kleinf725e102021-02-19 15:48:54 -070034 """Compile the Build API proto, returning the list of modified files."""
Alex Klein5dffe5e2021-02-19 15:50:00 -070035 cmd = [os.path.join(constants.CHROMITE_DIR, 'api', 'compile_build_api_proto')]
36 cros_build_lib.run(cmd)
37 result = cros_build_lib.run(['git', 'status', '--porcelain=v1'],
38 cwd=constants.CHROMITE_DIR, capture_output=True,
39 encoding='utf-8')
40 for line in result.stdout.splitlines():
41 if not line:
42 continue
43 path = line.split()[-1]
44 output_proto.modified_files.add().path = os.path.join(
45 constants.CHROMITE_DIR, path)
Alex Kleinf725e102021-02-19 15:48:54 -070046
47
Alex Klein076841b2019-08-29 15:19:39 -060048@faux.all_empty
Alex Klein231d2da2019-07-22 16:44:45 -060049@validate.validation_complete
50def GetMethods(_input_proto, output_proto, _config):
Alex Klein54e38e32019-06-21 14:54:17 -060051 """List all of the registered methods."""
52 router = router_lib.GetRouter()
53 for method in router.ListMethods():
54 output_proto.methods.add().method = method
Alex Klein104b0672019-06-28 15:43:00 -060055
56
Alex Klein231d2da2019-07-22 16:44:45 -060057@validate.validation_complete
58def GetVersion(_input_proto, output_proto, _config):
Alex Klein104b0672019-06-28 15:43:00 -060059 """Get the Build API major version number."""
60 output_proto.version.major = VERSION_MAJOR
61 output_proto.version.minor = VERSION_MINOR
62 output_proto.version.bug = VERSION_BUG