OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Loads gatekeeper configuration files for use with gatekeeper_ng.py. | 6 """Loads gatekeeper configuration files for use with gatekeeper_ng.py. |
7 | 7 |
8 The gatekeeper json configuration file has two main sections: 'masters' | 8 The gatekeeper json configuration file has two main sections: 'masters' |
9 and 'categories.' The following shows the breakdown of a possible config, | 9 and 'categories.' The following shows the breakdown of a possible config, |
10 but note that all nodes are optional (including the root 'masters' and | 10 but note that all nodes are optional (including the root 'masters' and |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 gatekeeper_builder['forgiving_steps'] |= gatekeeper_builder[ | 240 gatekeeper_builder['forgiving_steps'] |= gatekeeper_builder[ |
241 'closing_steps'] | 241 'closing_steps'] |
242 gatekeeper_builder['forgiving_optional'] |= gatekeeper_builder[ | 242 gatekeeper_builder['forgiving_optional'] |= gatekeeper_builder[ |
243 'closing_optional'] | 243 'closing_optional'] |
244 gatekeeper_builder['closing_steps'] = set([]) | 244 gatekeeper_builder['closing_steps'] = set([]) |
245 gatekeeper_builder['closing_optional'] = set([]) | 245 gatekeeper_builder['closing_optional'] = set([]) |
246 | 246 |
247 return gatekeeper_config | 247 return gatekeeper_config |
248 | 248 |
249 | 249 |
| 250 def load_gatekeeper_tree_config(filename): |
| 251 """Loads and verifies tree config json, returned loaded config json.""" |
| 252 with open(filename) as f: |
| 253 trees_config = json.load(f) |
| 254 |
| 255 tree_config_keys = ['masters', |
| 256 'build-db', |
| 257 'open-tree', |
| 258 'password-file', |
| 259 'revision-properties', |
| 260 'set-status', |
| 261 'status-url', |
| 262 'track-revisions'] |
| 263 |
| 264 for tree_name, tree_config in trees_config.iteritems(): |
| 265 allowed_keys(tree_config, *tree_config_keys) |
| 266 assert isinstance(tree_name, basestring) |
| 267 |
| 268 masters = tree_config.get('masters', []) |
| 269 assert isinstance(masters, list) |
| 270 assert all(isinstance(master, basestring) for master in masters) |
| 271 |
| 272 assert isinstance(tree_config.get('build-db', ''), basestring) |
| 273 assert isinstance(tree_config.get('open-tree', True), bool) |
| 274 assert isinstance(tree_config.get('password-file', ''), basestring) |
| 275 assert isinstance(tree_config.get('revision-properties', ''), basestring) |
| 276 assert isinstance(tree_config.get('set-status', True), bool) |
| 277 assert isinstance(tree_config.get('status-url', ''), basestring) |
| 278 assert isinstance(tree_config.get('track-revisions', True), bool) |
| 279 |
| 280 return trees_config |
| 281 |
250 def gatekeeper_section_hash(gatekeeper_section): | 282 def gatekeeper_section_hash(gatekeeper_section): |
251 st = cStringIO.StringIO() | 283 st = cStringIO.StringIO() |
252 flatten_to_json(gatekeeper_section, st) | 284 flatten_to_json(gatekeeper_section, st) |
253 return hashlib.sha256(st.getvalue()).hexdigest() | 285 return hashlib.sha256(st.getvalue()).hexdigest() |
254 | 286 |
255 | 287 |
256 def inject_hashes(gatekeeper_config): | 288 def inject_hashes(gatekeeper_config): |
257 new_config = copy.deepcopy(gatekeeper_config) | 289 new_config = copy.deepcopy(gatekeeper_config) |
258 for master in new_config.values(): | 290 for master in new_config.values(): |
259 for section in master: | 291 for section in master: |
(...skipping 30 matching lines...) Expand all Loading... |
290 gatekeeper_config = inject_hashes(gatekeeper_config) | 322 gatekeeper_config = inject_hashes(gatekeeper_config) |
291 | 323 |
292 flatten_to_json(gatekeeper_config, sys.stdout) | 324 flatten_to_json(gatekeeper_config, sys.stdout) |
293 print | 325 print |
294 | 326 |
295 return 0 | 327 return 0 |
296 | 328 |
297 | 329 |
298 if __name__ == '__main__': | 330 if __name__ == '__main__': |
299 sys.exit(main()) | 331 sys.exit(main()) |
OLD | NEW |