Commit 596b43a7 authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

Policy doc: Generate a JAMF json file that can be consumed by JAMF Pro

Bug: 1058102
Change-Id: Idb9a212853c9826b654f76ae6aa14e7d776710df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119639Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Yann Dago <ydago@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754505}
parent a586cffe
...@@ -236,6 +236,8 @@ action("policy_templates") { ...@@ -236,6 +236,8 @@ action("policy_templates") {
rebase_path(policy_templates_plist_path, root_build_dir), rebase_path(policy_templates_plist_path, root_build_dir),
"--plist_strings", "--plist_strings",
rebase_path(policy_templates_plist_strings_path, root_build_dir), rebase_path(policy_templates_plist_strings_path, root_build_dir),
"--jamf",
rebase_path(policy_templates_jamf_path, root_build_dir),
"-D", "-D",
"mac_bundle_id=$chrome_mac_bundle_id", "mac_bundle_id=$chrome_mac_bundle_id",
] ]
......
...@@ -101,7 +101,11 @@ policy_templates_plist_path = ...@@ -101,7 +101,11 @@ policy_templates_plist_path =
"$policy_templates_base_dir/mac/app-Manifest.plist" "$policy_templates_base_dir/mac/app-Manifest.plist"
policy_templates_plist_strings_path = policy_templates_plist_strings_path =
"$policy_templates_base_dir/mac/strings/\${lang}.lproj/Localizable.strings" "$policy_templates_base_dir/mac/strings/\${lang}.lproj/Localizable.strings"
policy_templates_mac_outputs = [ policy_templates_plist_path ] policy_templates_jamf_path = "$policy_templates_base_dir/mac/jamf.json"
policy_templates_mac_outputs = [
policy_templates_plist_path,
policy_templates_jamf_path,
]
foreach(lang, mac_policy_templates_languages) { foreach(lang, mac_policy_templates_languages) {
policy_templates_mac_outputs += [ policy_templates_mac_outputs += [
"$policy_templates_base_dir/mac/strings/${lang}.lproj/Localizable.strings", "$policy_templates_base_dir/mac/strings/${lang}.lproj/Localizable.strings",
......
...@@ -22,7 +22,7 @@ from writers import adm_writer, adml_writer, admx_writer, \ ...@@ -22,7 +22,7 @@ from writers import adm_writer, adml_writer, admx_writer, \
google_admx_writer, google_adml_writer, \ google_admx_writer, google_adml_writer, \
android_policy_writer, reg_writer, doc_writer, \ android_policy_writer, reg_writer, doc_writer, \
doc_atomic_groups_writer , json_writer, plist_writer, \ doc_atomic_groups_writer , json_writer, plist_writer, \
plist_strings_writer, ios_app_config_writer plist_strings_writer, ios_app_config_writer, jamf_writer
def MacLanguageMap(lang): def MacLanguageMap(lang):
...@@ -65,6 +65,7 @@ _WRITER_DESCS = [ ...@@ -65,6 +65,7 @@ _WRITER_DESCS = [
WriterDesc('json', False, 'utf-8', None, False), WriterDesc('json', False, 'utf-8', None, False),
WriterDesc('plist', False, 'utf-8', None, False), WriterDesc('plist', False, 'utf-8', None, False),
WriterDesc('plist_strings', True, 'utf-8', MacLanguageMap, False), WriterDesc('plist_strings', True, 'utf-8', MacLanguageMap, False),
WriterDesc('jamf', False, 'utf-8', None, False),
WriterDesc('ios_app_config', False, 'utf-8', None, False), WriterDesc('ios_app_config', False, 'utf-8', None, False),
] ]
...@@ -184,6 +185,7 @@ def main(): ...@@ -184,6 +185,7 @@ def main():
parser.add_argument('--json', action='append', dest='json') parser.add_argument('--json', action='append', dest='json')
parser.add_argument('--plist', action='append', dest='plist') parser.add_argument('--plist', action='append', dest='plist')
parser.add_argument('--plist_strings', action='append', dest='plist_strings') parser.add_argument('--plist_strings', action='append', dest='plist_strings')
parser.add_argument('--jamf', action='append', dest='jamf')
parser.add_argument( parser.add_argument(
'--android_policy', action='append', dest='android_policy') '--android_policy', action='append', dest='android_policy')
parser.add_argument( parser.add_argument(
......
...@@ -26,6 +26,7 @@ class TestSuiteAll(unittest.TestSuite): ...@@ -26,6 +26,7 @@ class TestSuiteAll(unittest.TestSuite):
import writers.google_adml_writer_unittest import writers.google_adml_writer_unittest
import writers.google_admx_writer_unittest import writers.google_admx_writer_unittest
import writers.ios_app_config_writer_unittest import writers.ios_app_config_writer_unittest
import writers.jamf_writer_unittest
import writers.json_writer_unittest import writers.json_writer_unittest
import writers.plist_strings_writer_unittest import writers.plist_strings_writer_unittest
import writers.plist_writer_unittest import writers.plist_writer_unittest
...@@ -45,6 +46,7 @@ class TestSuiteAll(unittest.TestSuite): ...@@ -45,6 +46,7 @@ class TestSuiteAll(unittest.TestSuite):
writers.google_adml_writer_unittest.GoogleAdmlWriterUnittest, writers.google_adml_writer_unittest.GoogleAdmlWriterUnittest,
writers.google_admx_writer_unittest.GoogleAdmxWriterUnittest, writers.google_admx_writer_unittest.GoogleAdmxWriterUnittest,
writers.ios_app_config_writer_unittest.IOSAppConfigWriterUnitTests, writers.ios_app_config_writer_unittest.IOSAppConfigWriterUnitTests,
writers.jamf_writer_unittest.JamfWriterUnitTests,
writers.json_writer_unittest.JsonWriterUnittest, writers.json_writer_unittest.JsonWriterUnittest,
writers.plist_strings_writer_unittest.PListStringsWriterUnittest, writers.plist_strings_writer_unittest.PListStringsWriterUnittest,
writers.plist_writer_unittest.PListWriterUnittest, writers.plist_writer_unittest.PListWriterUnittest,
......
...@@ -54,8 +54,7 @@ def GetConfigurationForBuild(defines): ...@@ -54,8 +54,7 @@ def GetConfigurationForBuild(defines):
'mandatory_category_path': ['chromium_os'], 'mandatory_category_path': ['chromium_os'],
'recommended_category_path': ['chromium_os_recommended'], 'recommended_category_path': ['chromium_os_recommended'],
'category_path_strings': { 'category_path_strings': {
'chromium_os': 'chromium_os': 'Chromium OS',
'Chromium OS',
'chromium_os_recommended': 'chromium_os_recommended':
'Chromium OS - {doc_recommended}', 'Chromium OS - {doc_recommended}',
}, },
...@@ -65,7 +64,7 @@ def GetConfigurationForBuild(defines): ...@@ -65,7 +64,7 @@ def GetConfigurationForBuild(defines):
}, },
'admx_prefix': 'chromium', 'admx_prefix': 'chromium',
'linux_policy_path': '/etc/chromium/policies/', 'linux_policy_path': '/etc/chromium/policies/',
'ios_bundle_id': 'org.chromium', 'bundle_id': 'org.chromium',
} }
elif '_google_chrome' in defines: elif '_google_chrome' in defines:
config = { config = {
...@@ -80,15 +79,12 @@ def GetConfigurationForBuild(defines): ...@@ -80,15 +79,12 @@ def GetConfigurationForBuild(defines):
'Software\\Policies\\Google\\Chrome', 'Software\\Policies\\Google\\Chrome',
'reg_recommended_key_name': 'reg_recommended_key_name':
'Software\\Policies\\Google\\Chrome\\Recommended', 'Software\\Policies\\Google\\Chrome\\Recommended',
'mandatory_category_path': [ 'mandatory_category_path':
'Google:Cat_Google', 'googlechrome' ['Google:Cat_Google', 'googlechrome'],
], 'recommended_category_path':
'recommended_category_path': [ ['Google:Cat_Google', 'googlechrome_recommended'],
'Google:Cat_Google', 'googlechrome_recommended'
],
'category_path_strings': { 'category_path_strings': {
'googlechrome': 'googlechrome': 'Google Chrome',
'Google Chrome',
'googlechrome_recommended': 'googlechrome_recommended':
'Google Chrome - {doc_recommended}' 'Google Chrome - {doc_recommended}'
}, },
...@@ -100,12 +96,10 @@ def GetConfigurationForBuild(defines): ...@@ -100,12 +96,10 @@ def GetConfigurationForBuild(defines):
'Software\\Policies\\Google\\ChromeOS', 'Software\\Policies\\Google\\ChromeOS',
'reg_recommended_key_name': 'reg_recommended_key_name':
'Software\\Policies\\Google\\ChromeOS\\Recommended', 'Software\\Policies\\Google\\ChromeOS\\Recommended',
'mandatory_category_path': [ 'mandatory_category_path':
'Google:Cat_Google', 'googlechromeos' ['Google:Cat_Google', 'googlechromeos'],
], 'recommended_category_path':
'recommended_category_path': [ ['Google:Cat_Google', 'googlechromeos_recommended'],
'Google:Cat_Google', 'googlechromeos_recommended'
],
'category_path_strings': { 'category_path_strings': {
'googlechromeos': 'googlechromeos':
'Google Chrome OS', 'Google Chrome OS',
...@@ -126,7 +120,7 @@ def GetConfigurationForBuild(defines): ...@@ -126,7 +120,7 @@ def GetConfigurationForBuild(defines):
'Google': 'Google.Policies' # prefix: namespace 'Google': 'Google.Policies' # prefix: namespace
}, },
'linux_policy_path': '/etc/opt/chrome/policies/', 'linux_policy_path': '/etc/opt/chrome/policies/',
'ios_bundle_id': 'com.google.chrome', 'bundle_id': 'com.google.chrome',
} }
else: else:
raise Exception('Unknown build') raise Exception('Unknown build')
......
...@@ -27,8 +27,7 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter): ...@@ -27,8 +27,7 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter):
def BeginTemplate(self): def BeginTemplate(self):
self._app_config.attributes[ self._app_config.attributes[
'xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance' 'xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'
schema_location = '/%s/appconfig/appconfig.xsd' % ( schema_location = '/%s/appconfig/appconfig.xsd' % (self.config['bundle_id'])
self.config['ios_bundle_id'])
self._app_config.attributes[ self._app_config.attributes[
'xsi:noNamespaceSchemaLocation'] = schema_location 'xsi:noNamespaceSchemaLocation'] = schema_location
...@@ -36,7 +35,7 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter): ...@@ -36,7 +35,7 @@ class IOSAppConfigWriter(xml_formatted_writer.XMLFormattedWriter):
self.AddText(version, self.config['version']) self.AddText(version, self.config['version'])
bundle_id = self.AddElement(self._app_config, 'bundleId', {}) bundle_id = self.AddElement(self._app_config, 'bundleId', {})
self.AddText(bundle_id, self.config['ios_bundle_id']) self.AddText(bundle_id, self.config['bundle_id'])
self._policies = self.AddElement(self._app_config, 'dict', {}) self._policies = self.AddElement(self._app_config, 'dict', {})
def WritePolicy(self, policy): def WritePolicy(self, policy):
......
#!/usr/bin/env python
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json
from writers import template_writer
def GetWriter(config):
'''Factory method for creating JamfWriter objects.
See the constructor of TemplateWriter for description of
arguments.
'''
return JamfWriter(['mac'], config)
class JamfWriter(template_writer.TemplateWriter):
'''Simple writer that writes a jamf.json file.
'''
TYPE_TO_INPUT = {
'string': 'string',
'int': 'integer',
'int-enum': 'integer',
'string-enum': 'string',
'string-enum-list': 'array',
'main': 'boolean',
'list': 'array',
'dict': 'dictionary',
'external': 'dictionary',
}
def WriteTemplate(self, template):
'''Writes the given template definition.
Args:
template: Template definition to write.
Returns:
Generated output for the passed template definition.
'''
policies = [
policy for policy in template['policy_definitions']
if policy['type'] != 'group' and self.IsPolicySupported(policy)
]
output = {
'title': self.config['bundle_id'],
'description': self.config['app_name'],
'options': {
'remove_empty_properties': True
},
'properties': {}
}
for policy in policies:
output['properties'][policy['name']] = {
'title': policy['name'],
'description': policy['caption'],
'type': self.TYPE_TO_INPUT[policy['type']]
}
return json.dumps(output, indent=2, sort_keys=True, separators=(',', ': '))
#!/usr/bin/env python
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys
if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..'))
import unittest
from writers import writer_unittest_common
class JamfWriterUnitTests(writer_unittest_common.WriterUnittestCommon):
'''Unit tests for JamfWriter.'''
def _GetTestPolicyTemplate(self, policy_name, policy_type, policy_captio):
return '''
{
'policy_definitions': [
{
'name': '%s',
'type': '%s',
'supported_on':['chrome.mac:*-'],
'caption': '%s',
'desc': '',
'items': [{
'name': '',
'value': 1,
'caption': '',
}]
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}
''' % (policy_name, policy_type, policy_captio)
def _GetExpectedOutput(self, policy_name, policy_type, policy_captio):
return '''{
"description": "Google Chrome",
"options": {
"remove_empty_properties": true
},
"properties": {
"%s": {
"description": "%s",
"title": "%s",
"type": "%s"
}
},
"title": "com.google.chrome"
}''' % (policy_name, policy_captio, policy_name, policy_type)
def testStringPolicy(self):
policy_json = self._GetTestPolicyTemplate('stringPolicy', 'string',
'A string policy')
expected = self._GetExpectedOutput('stringPolicy', 'string',
'A string policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testIntPolicy(self):
policy_json = self._GetTestPolicyTemplate('intPolicy', 'int',
'An int policy')
expected = self._GetExpectedOutput('intPolicy', 'integer', 'An int policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testIntEnumPolicy(self):
policy_json = self._GetTestPolicyTemplate('intPolicy', 'int-enum',
'An int-enum policy')
expected = self._GetExpectedOutput('intPolicy', 'integer',
'An int-enum policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testStringEnumPolicy(self):
policy_json = self._GetTestPolicyTemplate('stringPolicy', 'string-enum',
'A string-enum policy')
expected = self._GetExpectedOutput('stringPolicy', 'string',
'A string-enum policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testStringEnumListPolicy(self):
policy_json = self._GetTestPolicyTemplate(
'stringPolicy', 'string-enum-list', 'A string-enum-list policy')
expected = self._GetExpectedOutput('stringPolicy', 'array',
'A string-enum-list policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testBooleanPolicy(self):
policy_json = self._GetTestPolicyTemplate('booleanPolicy', 'main',
'A boolean policy')
expected = self._GetExpectedOutput('booleanPolicy', 'boolean',
'A boolean policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testListPolicy(self):
policy_json = self._GetTestPolicyTemplate('listPolicy', 'list',
'A list policy')
expected = self._GetExpectedOutput('listPolicy', 'array', 'A list policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testDictPolicy(self):
policy_json = self._GetTestPolicyTemplate('dictPolicy', 'dict',
'A dict policy')
expected = self._GetExpectedOutput('dictPolicy', 'dictionary',
'A dict policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
def testExternalPolicy(self):
policy_json = self._GetTestPolicyTemplate('externalPolicy', 'external',
'A external policy')
expected = self._GetExpectedOutput('externalPolicy', 'dictionary',
'A external policy')
output = self.GetOutput(policy_json, {'_google_chrome': '1'}, 'jamf')
self.assertEquals(output.strip(), expected.strip())
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment