• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env vpython3
2# Copyright 2020 The ChromiumOS Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Filters a ConfigBundle based on PublicReplication messages."""
6
7import argparse
8
9from checker import io_utils
10from chromiumos.config.payload import config_bundle_pb2
11from common import proto_utils
12
13
14def argument_parser():
15  """Returns an ArgumentParser for the script."""
16  parser = argparse.ArgumentParser(description=__doc__)
17  parser.add_argument(
18      '--input',
19      required=True,
20      help=('Path to the private config json proto e.g. '
21            '.../chromiumos/src/project/project1/generated/config.jsonproto.'),
22      metavar='PATH')
23  parser.add_argument(
24      '--output',
25      required=True,
26      help=('Path to the output the filtered public json proto. Note that if '
27            'filtering for public fields produces an empty ConfigBundle, no '
28            'output is written.'),
29      metavar='PATH')
30  return parser
31
32
33def main():
34  """Runs the script."""
35  parser = argument_parser()
36  args = parser.parse_args()
37
38  private_config = io_utils.read_config(args.input)
39  public_config = config_bundle_pb2.ConfigBundle()
40
41  proto_utils.apply_public_replication(private_config, public_config)
42
43  # Skip writing an empty ConfigBundle.
44  if public_config != config_bundle_pb2.ConfigBundle():
45    io_utils.write_message_json(public_config, args.output)
46  else:
47    print(
48        'Filtering for public fields produced an empty ConfigBundle, skipping '
49        'writing output.')
50
51
52if __name__ == '__main__':
53  main()
54