Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: appengine/swarming/server/config.py

Issue 1946253003: swarming: refactor cipd input (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@default-isolate-server
Patch Set: fix import google.protobuf Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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():

Powered by Google App Engine
This is Rietveld 408576698