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

Unified Diff: chrome/app/policy/syntax_check_policy_template_json.py

Issue 10826061: Added schemas to policy templates. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app/policy/syntax_check_policy_template_json.py
diff --git a/chrome/app/policy/syntax_check_policy_template_json.py b/chrome/app/policy/syntax_check_policy_template_json.py
index 75862d7fd1873b29f88c5eaf8bc8b9dc6642e6f8..ee2c913fcc2c8a2db00052ed0c992766cdb955aa 100755
--- a/chrome/app/policy/syntax_check_policy_template_json.py
+++ b/chrome/app/policy/syntax_check_policy_template_json.py
@@ -19,6 +19,16 @@ TRAILING_WHITESPACE = re.compile('.*?([ \t]+)$')
# Matches all non-empty strings that contain no whitespaces.
NO_WHITESPACE = re.compile('[^\s]+$')
+# Convert a 'type' to its corresponding schema type.
+TYPE_TO_SCHEMA = {
+ 'int': 'integer',
Mattias Nissler (ping if slow) 2012/07/31 11:46:34 Suggestion: You could just put the entire expected
Joao da Silva 2012/07/31 12:56:48 'dicts' and the '-enums' have extra fields that ar
+ 'list': 'array',
+ 'dict': 'object',
+ 'main': 'boolean',
+ 'string': 'string',
+ 'int-enum': 'integer',
+ 'string-enum': 'string',
+}
class PolicyTemplateChecker(object):
@@ -112,6 +122,15 @@ class PolicyTemplateChecker(object):
if (i + 1) not in policy_ids:
self._Error('No policy with id: %s' % (i + 1))
+ def _CheckPolicySchema(self, policy, policy_type):
+ '''Checks that the 'schema' field matches the 'type' field.'''
+ self._CheckContains(policy, 'schema', dict)
+ if isinstance(policy.get('schema'), dict):
+ self._CheckContains(policy['schema'], 'type', str)
+ if policy['schema'].get('type') != TYPE_TO_SCHEMA[policy_type]:
+ self._Error('Schema type must match the existing type for policy %s' %
+ policy.get('name'))
Mattias Nissler (ping if slow) 2012/07/31 11:46:34 nit: Elsewhere in this file, the continuation is a
Joao da Silva 2012/07/31 12:56:48 Done.
+
def _CheckPolicy(self, policy, is_in_group, policy_ids):
if not isinstance(policy, dict):
self._Error('Each policy must be a dictionary.', 'policy', None, policy)
@@ -122,7 +141,7 @@ class PolicyTemplateChecker(object):
if key not in ('name', 'type', 'caption', 'desc', 'device_only',
'supported_on', 'label', 'policies', 'items',
'example_value', 'features', 'deprecated', 'future',
- 'id'):
+ 'id', 'schema'):
self.warning_count += 1
print ('In policy %s: Warning: Unknown key: %s' %
(policy.get('name'), key))
@@ -181,6 +200,11 @@ class PolicyTemplateChecker(object):
id = self._CheckContains(policy, 'id', int)
self._AddPolicyID(id, policy_ids, policy)
+ # 'schema' is the new 'type'.
+ # TODO(joaodasilva): remove the 'type' checks once 'schema' is used
+ # everywhere.
+ self._CheckPolicySchema(policy, policy_type)
+
# Each policy must have a supported_on list.
supported_on = self._CheckContains(policy, 'supported_on', list)
if supported_on is not None:
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698