blob: 74a436e3352bfc3a7626e0dcf107c3cca54f7635 [file] [log] [blame]
Andrew Lambc89a70d2020-08-14 11:47:44 -06001#!/usr/bin/env python3
2# Copyright 2020 The Chromium OS Authors. All rights reserved.
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,
Andrew Lambc63626c2020-08-14 14:19:31 -060026 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.'),
Andrew Lambc89a70d2020-08-14 11:47:44 -060029 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
Andrew Lambc63626c2020-08-14 14:19:31 -060043 # 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.')
Andrew Lambc89a70d2020-08-14 11:47:44 -060050
51
52if __name__ == '__main__':
53 main()