| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Handles requests to the findit config page.""" | 5 """Handles requests to the findit config page.""" |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 | 8 |
| 9 from common.base_handler import BaseHandler | 9 from common.base_handler import BaseHandler |
| 10 from common.base_handler import Permission | 10 from common.base_handler import Permission |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 isinstance(settings.get('use_chrome_build_extract'), bool)) | 175 isinstance(settings.get('use_chrome_build_extract'), bool)) |
| 176 | 176 |
| 177 | 177 |
| 178 def _ValidateActionSettings(settings): | 178 def _ValidateActionSettings(settings): |
| 179 return (isinstance(settings, dict) and | 179 return (isinstance(settings, dict) and |
| 180 isinstance(settings.get('cr_notification_build_threshold'), int) and | 180 isinstance(settings.get('cr_notification_build_threshold'), int) and |
| 181 isinstance( | 181 isinstance( |
| 182 settings.get('cr_notification_latency_limit_minutes'), int)) | 182 settings.get('cr_notification_latency_limit_minutes'), int)) |
| 183 | 183 |
| 184 | 184 |
| 185 def _ValidateCheckFlakeSettings(settings): |
| 186 return (isinstance(settings, dict) and |
| 187 isinstance(settings.get('lower_flake_threshold'), float) and |
| 188 isinstance(settings.get('upper_flake_threshold'), float) and |
| 189 isinstance(settings.get('max_flake_in_a_row'), int) and |
| 190 isinstance(settings.get('max_stable_in_a_row'), int)) |
| 191 |
| 192 |
| 185 # Maps config properties to their validation functions. | 193 # Maps config properties to their validation functions. |
| 186 _CONFIG_VALIDATION_FUNCTIONS = { | 194 _CONFIG_VALIDATION_FUNCTIONS = { |
| 187 'steps_for_masters_rules': _ValidateMastersAndStepsRulesMapping, | 195 'steps_for_masters_rules': _ValidateMastersAndStepsRulesMapping, |
| 188 'builders_to_trybots': _ValidateTrybotMapping, | 196 'builders_to_trybots': _ValidateTrybotMapping, |
| 189 'try_job_settings': _ValidateTryJobSettings, | 197 'try_job_settings': _ValidateTryJobSettings, |
| 190 'swarming_settings': _ValidateSwarmingSettings, | 198 'swarming_settings': _ValidateSwarmingSettings, |
| 191 'download_build_data_settings': _ValidateDownloadBuildDataSettings, | 199 'download_build_data_settings': _ValidateDownloadBuildDataSettings, |
| 192 'action_settings': _ValidateActionSettings, | 200 'action_settings': _ValidateActionSettings, |
| 201 'check_flake_settings': _ValidateCheckFlakeSettings, |
| 193 } | 202 } |
| 194 | 203 |
| 195 | 204 |
| 196 def _ConfigurationDictIsValid(configuration_dict): | 205 def _ConfigurationDictIsValid(configuration_dict): |
| 197 """Checks that each configuration setting is properly formatted. | 206 """Checks that each configuration setting is properly formatted. |
| 198 | 207 |
| 199 Args: | 208 Args: |
| 200 configuration_dict: A dictionary expected to map configuration properties | 209 configuration_dict: A dictionary expected to map configuration properties |
| 201 by name to their intended settings. For example, | 210 by name to their intended settings. For example, |
| 202 | 211 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 255 |
| 247 latest_version = settings.GetLatestVersionNumber() | 256 latest_version = settings.GetLatestVersionNumber() |
| 248 | 257 |
| 249 data = { | 258 data = { |
| 250 'masters': waterfall_config.GetStepsForMastersRules(settings), | 259 'masters': waterfall_config.GetStepsForMastersRules(settings), |
| 251 'builders': settings.builders_to_trybots, | 260 'builders': settings.builders_to_trybots, |
| 252 'try_job_settings': settings.try_job_settings, | 261 'try_job_settings': settings.try_job_settings, |
| 253 'swarming_settings': settings.swarming_settings, | 262 'swarming_settings': settings.swarming_settings, |
| 254 'download_build_data_settings': settings.download_build_data_settings, | 263 'download_build_data_settings': settings.download_build_data_settings, |
| 255 'action_settings': settings.action_settings, | 264 'action_settings': settings.action_settings, |
| 265 'check_flake_settings': settings.check_flake_settings, |
| 256 'version': settings.version, | 266 'version': settings.version, |
| 257 'latest_version': latest_version, | 267 'latest_version': latest_version, |
| 258 'updated_by': settings.updated_by, | 268 'updated_by': settings.updated_by, |
| 259 'updated_ts': _FormatTimestamp(settings.updated_ts) | 269 'updated_ts': _FormatTimestamp(settings.updated_ts) |
| 260 } | 270 } |
| 261 | 271 |
| 262 return {'template': 'config.html', 'data': data} | 272 return {'template': 'config.html', 'data': data} |
| 263 | 273 |
| 264 def HandlePost(self): | 274 def HandlePost(self): |
| 265 data = self.request.params.get('data') | 275 data = self.request.params.get('data') |
| 266 new_config_dict = json.loads(data) | 276 new_config_dict = json.loads(data) |
| 267 if not _ConfigurationDictIsValid(new_config_dict): # pragma: no cover | 277 if not _ConfigurationDictIsValid(new_config_dict): # pragma: no cover |
| 268 return self.CreateError( | 278 return self.CreateError( |
| 269 'New configuration settings is not properly formatted.', 400) | 279 'New configuration settings is not properly formatted.', 400) |
| 270 | 280 |
| 271 wf_config.FinditConfig.Get().Update(users.get_current_user(), | 281 wf_config.FinditConfig.Get().Update(users.get_current_user(), |
| 272 users.IsCurrentUserAdmin(), | 282 users.IsCurrentUserAdmin(), |
| 273 **new_config_dict) | 283 **new_config_dict) |
| 274 | 284 |
| 275 return self.HandleGet() | 285 return self.HandleGet() |
| OLD | NEW |