Andrew Lamb | c89a70d | 2020-08-14 11:47:44 -0600 | [diff] [blame] | 1 | #!/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 | |
| 7 | import argparse |
| 8 | |
| 9 | from checker import io_utils |
| 10 | from chromiumos.config.payload import config_bundle_pb2 |
| 11 | from common import proto_utils |
| 12 | |
| 13 | |
| 14 | def 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 Lamb | c63626c | 2020-08-14 14:19:31 -0600 | [diff] [blame] | 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.'), |
Andrew Lamb | c89a70d | 2020-08-14 11:47:44 -0600 | [diff] [blame] | 29 | metavar='PATH') |
| 30 | return parser |
| 31 | |
| 32 | |
| 33 | def 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 Lamb | c63626c | 2020-08-14 14:19:31 -0600 | [diff] [blame] | 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.') |
Andrew Lamb | c89a70d | 2020-08-14 11:47:44 -0600 | [diff] [blame] | 50 | |
| 51 | |
| 52 | if __name__ == '__main__': |
| 53 | main() |