| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 isinstance(settings.get('server_host'), basestring) and | 159 isinstance(settings.get('server_host'), basestring) and |
| 160 isinstance(settings.get('default_request_priority'), int) and | 160 isinstance(settings.get('default_request_priority'), int) and |
| 161 isinstance(settings.get('request_expiration_hours'), int) and | 161 isinstance(settings.get('request_expiration_hours'), int) and |
| 162 isinstance(settings.get('server_query_interval_seconds'), int) and | 162 isinstance(settings.get('server_query_interval_seconds'), int) and |
| 163 isinstance(settings.get('task_timeout_hours'), int) and | 163 isinstance(settings.get('task_timeout_hours'), int) and |
| 164 isinstance(settings.get('isolated_server'), basestring) and | 164 isinstance(settings.get('isolated_server'), basestring) and |
| 165 isinstance(settings.get('isolated_storage_url'), basestring) and | 165 isinstance(settings.get('isolated_storage_url'), basestring) and |
| 166 isinstance(settings.get('iterations_to_rerun'), int)) | 166 isinstance(settings.get('iterations_to_rerun'), int)) |
| 167 | 167 |
| 168 | 168 |
| 169 def _ValidateDownloadBuildDataSettings(settings): |
| 170 return (isinstance(settings, dict) and |
| 171 isinstance(settings.get('download_interval_seconds'), int) and |
| 172 isinstance(settings.get( |
| 173 'memcache_master_download_expiration_seconds'), int) and |
| 174 isinstance(settings.get('use_chrome_build_extract'), bool)) |
| 175 |
| 176 |
| 169 # Maps config properties to their validation functions. | 177 # Maps config properties to their validation functions. |
| 170 _CONFIG_VALIDATION_FUNCTIONS = { | 178 _CONFIG_VALIDATION_FUNCTIONS = { |
| 171 'steps_for_masters_rules': _ValidateMastersAndStepsRulesMapping, | 179 'steps_for_masters_rules': _ValidateMastersAndStepsRulesMapping, |
| 172 'builders_to_trybots': _ValidateTrybotMapping, | 180 'builders_to_trybots': _ValidateTrybotMapping, |
| 173 'try_job_settings': _ValidateTryJobSettings, | 181 'try_job_settings': _ValidateTryJobSettings, |
| 174 'swarming_settings': _ValidateSwarmingSettings | 182 'swarming_settings': _ValidateSwarmingSettings, |
| 183 'download_build_data_settings': _ValidateDownloadBuildDataSettings |
| 175 } | 184 } |
| 176 | 185 |
| 177 | 186 |
| 178 def _ConfigurationDictIsValid(configuration_dict): | 187 def _ConfigurationDictIsValid(configuration_dict): |
| 179 """Checks that each configuration setting is properly formatted. | 188 """Checks that each configuration setting is properly formatted. |
| 180 | 189 |
| 181 Args: | 190 Args: |
| 182 configuration_dict: A dictionary expected to map configuration properties | 191 configuration_dict: A dictionary expected to map configuration properties |
| 183 by name to their intended settings. For example, | 192 by name to their intended settings. For example, |
| 184 | 193 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 return self.CreateError( | 235 return self.CreateError( |
| 227 'The requested version is invalid or not found.', 400) | 236 'The requested version is invalid or not found.', 400) |
| 228 | 237 |
| 229 latest_version = settings.GetLatestVersionNumber() | 238 latest_version = settings.GetLatestVersionNumber() |
| 230 | 239 |
| 231 data = { | 240 data = { |
| 232 'masters': waterfall_config.GetStepsForMastersRules(settings), | 241 'masters': waterfall_config.GetStepsForMastersRules(settings), |
| 233 'builders': settings.builders_to_trybots, | 242 'builders': settings.builders_to_trybots, |
| 234 'try_job_settings': settings.try_job_settings, | 243 'try_job_settings': settings.try_job_settings, |
| 235 'swarming_settings': settings.swarming_settings, | 244 'swarming_settings': settings.swarming_settings, |
| 245 'download_build_data_settings': settings.download_build_data_settings, |
| 236 'version': settings.version, | 246 'version': settings.version, |
| 237 'latest_version': latest_version, | 247 'latest_version': latest_version, |
| 238 'updated_by': settings.updated_by, | 248 'updated_by': settings.updated_by, |
| 239 'updated_ts': _FormatTimestamp(settings.updated_ts) | 249 'updated_ts': _FormatTimestamp(settings.updated_ts) |
| 240 } | 250 } |
| 241 | 251 |
| 242 return {'template': 'config.html', 'data': data} | 252 return {'template': 'config.html', 'data': data} |
| 243 | 253 |
| 244 def HandlePost(self): | 254 def HandlePost(self): |
| 245 data = self.request.params.get('data') | 255 data = self.request.params.get('data') |
| 246 new_config_dict = json.loads(data) | 256 new_config_dict = json.loads(data) |
| 247 if not _ConfigurationDictIsValid(new_config_dict): # pragma: no cover | 257 if not _ConfigurationDictIsValid(new_config_dict): # pragma: no cover |
| 248 return self.CreateError( | 258 return self.CreateError( |
| 249 'New configuration settings is not properly formatted.', 400) | 259 'New configuration settings is not properly formatted.', 400) |
| 250 | 260 |
| 251 wf_config.FinditConfig.Get().Update(users.get_current_user(), | 261 wf_config.FinditConfig.Get().Update(users.get_current_user(), |
| 252 users.IsCurrentUserAdmin(), | 262 users.IsCurrentUserAdmin(), |
| 253 **new_config_dict) | 263 **new_config_dict) |
| 254 | 264 |
| 255 return self.HandleGet() | 265 return self.HandleGet() |
| OLD | NEW |