| Index: appengine/swarming/server/config.py
|
| diff --git a/appengine/swarming/server/config.py b/appengine/swarming/server/config.py
|
| index 0615f9484db15cad2f114a4cf93e9d0d0e7367b8..8c7f205ca1836def97d8bf1bc9e2ac1b10d15215 100644
|
| --- a/appengine/swarming/server/config.py
|
| +++ b/appengine/swarming/server/config.py
|
| @@ -6,6 +6,7 @@
|
|
|
| import logging
|
| import posixpath
|
| +import re
|
|
|
| from components import config
|
| from components import gitiles
|
| @@ -14,11 +15,12 @@ from components import utils
|
| from components.config import validation
|
|
|
| from proto import config_pb2
|
| -from server import task_request
|
|
|
| +import cipd
|
|
|
| SETTINGS_CFG_FILENAME = 'settings.cfg'
|
| SECONDS_IN_YEAR = 60 * 60 * 24 * 365
|
| +NAMESPACE_RE = re.compile(r'^[a-z0-9A-Z\-._]+$')
|
|
|
|
|
| ConfigApi = config.ConfigApi
|
| @@ -32,10 +34,26 @@ def validate_isolate_settings(cfg, ctx):
|
| if not cfg.default_server.startswith(('https://', 'http://')):
|
| ctx.error('default_server must start with "https://" or "http://"')
|
|
|
| - if not task_request.NAMESPACE_RE.match(cfg.default_namespace):
|
| + if not NAMESPACE_RE.match(cfg.default_namespace):
|
| ctx.error('invalid namespace "%s"', cfg.default_namespace)
|
|
|
|
|
| +def validate_cipd_settings(cfg, ctx=None):
|
| + """Validates CipdSettings message stored in settings.cfg."""
|
| + ctx = ctx or validation.Context.raise_on_error()
|
| + if not cfg.server_host:
|
| + ctx.error('server_host is not set')
|
| +
|
| + if not cipd.is_valid_package_name_template(cfg.client_package_name):
|
| + ctx.error('invalid client_package_name "%s"', cfg.client_package_name)
|
| + elif cipd.PARAM_PLATFORM not in cfg.client_package_name:
|
| + ctx.error(
|
| + 'client_package_name does not use %s parameter', cipd.PARAM_PLATFORM)
|
| +
|
| + if not cipd.is_valid_version(cfg.client_package_version):
|
| + ctx.error('invalid client_package_version "%s"', cfg.client_package_version)
|
| +
|
| +
|
| @validation.self_rule(SETTINGS_CFG_FILENAME, config_pb2.SettingsCfg)
|
| def validate_settings(cfg, ctx):
|
| """Validates settings.cfg file against proto message schema."""
|
| @@ -54,6 +72,10 @@ def validate_settings(cfg, ctx):
|
| with ctx.prefix('isolate: '):
|
| validate_isolate_settings(cfg.isolate, ctx)
|
|
|
| + if cfg.HasField('cipd'):
|
| + with ctx.prefix('cipd: '):
|
| + validate_cipd_settings(cfg.cipd, ctx)
|
| +
|
|
|
| @utils.memcache('config:get_configs_url', time=60)
|
| def _get_configs_url():
|
|
|