summaryrefslogtreecommitdiffstats
path: root/chromium/components/policy/tools/template_writers/writers/chromeos_admx_writer.py
blob: c9f1c2c5052515c1160e1dcdf8c6d3e0c388570b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# Copyright 2017 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 base64

from writers import admx_writer
from writers.admx_writer import AdmxElementType


def GetWriter(config):
  '''Factory method for creating ADMXWriter objects for the Chrome OS platform
  See the constructor of TemplateWriter for description of arguments.
  '''
  return ChromeOSADMXWriter(['chrome_os'], config)


class ChromeOSADMXWriter(admx_writer.ADMXWriter):
  '''Class for generating Chrome OS policy templates in the ADMX format.
  It is used by PolicyTemplateGenerator to write ADMX files.
  '''

  # Overridden.
  def GetClass(self, policy):
    is_device_only = 'device_only' in policy and policy['device_only']
    return 'Machine' if is_device_only else 'User'

  # Overridden.
  # These ADMX templates are used to generate GPO for Active Directory managed
  # Chrome OS devices.
  def IsPolicySupported(self, policy):
    return self.IsCrOSManagementSupported(policy, 'active_directory') and \
           super(ChromeOSADMXWriter, self).IsPolicySupported(policy)

  # Overridden.
  def _GetAdmxElementType(self, policy):
    return AdmxElementType.GetType(policy, allow_multi_strings=True)