components/policy/tools/template_writers/writers/jamf_writer.py
def WriteTemplate(self, template):
    '''Writes the given template definition.

    Args:
      template: Template definition to write.

    Returns:
      Generated output for the passed template definition.
    '''
    # Keep track of all items that can be referred to by an id.
    # This is used for '$ref' fields in the policy templates.
    ref_ids_schemas = {}
    policies = []
    for policy_def in template['policy_definitions']:
      # Iterate over all policies, even the policies contained inside a policy
      # group.
      if policy_def['type'] == 'group':
        policies += policy_def['policies']
      else:
        policies += [policy_def]

    for policy in policies:
      if policy['type'] == 'int-enum' or policy['type'] == 'string-enum':
        self.RecordEnumIds(policy, ref_ids_schemas)
      elif 'schema' in policy:
        if 'id' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema'], ref_ids_schemas)
        if 'items' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema']['items'],
                                      ref_ids_schemas)
        if 'properties' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema']['properties'],
                                      ref_ids_schemas)
        if 'patternProperties' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema']['patternProperties'],
                                      ref_ids_schemas)

    policies = [policy for policy in policies if self.IsPolicySupported(policy)]
    output = {
        'title': self.config['bundle_id'],
        'version': self.config['version'].split(".", 1)[0],
        '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']]
      }

      policy_output = output['properties'][policy['name']]
      if policy['id'] in self.POLICY_ID_TO_INPUT:
        policy_output['type'] = self.POLICY_ID_TO_INPUT[policy['id']]

      policy_type = policy_output['type']
      if policy['type'] == 'int-enum' or policy['type'] == 'string-enum':
        policy_output['options'] = {
            'enum_titles': [item['name'] for item in policy['items']]
        }
        policy_output['enum'] = [item['value'] for item in policy['items']]
      elif policy['type'] == 'int' and 'schema' in policy:
        if 'minimum' in policy['schema']:
          policy_output['minimum'] = policy['schema']['minimum']
        if 'maximum' in policy['schema']:
          policy_output['maximum'] = policy['schema']['maximum']
      elif policy['type'] == 'list':
        policy_output['items'] = policy['schema']['items']
      elif policy['type'] == 'string-enum-list' or policy[
          'type'] == 'int-enum-list':
        policy_output['items'] = {
            'type': policy['schema']['items']['type'],
            'options': {
                'enum_titles': [item['name'] for item in policy['items']]
            },
            'enum': [item['value'] for item in policy['items']]
        }
      elif policy_output['type'] == 'object' and policy['type'] != 'external':
        policy_output['type'] = policy['schema']['type']
        if policy_output['type'] == 'array':
          policy_output['items'] = policy['schema']['items']
          self.WriteRefItems(policy_output['items'], policy_output['items'], [],
                             ref_ids_schemas, set())
        elif policy_output['type'] == 'object':
          policy_output['properties'] = policy['schema']['properties']
          self.WriteRefItems(policy_output['properties'],
                             policy_output['properties'], [], ref_ids_schemas,
                             set())

    return json.dumps(output, indent=2, sort_keys=True, separators=(',', ': '))
Writes the given template definition.

    Args:
      template: Template definition to write.

    Returns:
      Generated output for the passed template definition.
    
Writes the given template definition.
Writes the given template definition .
def WriteTemplate(self, template):
    ref_ids_schemas = {}
    policies = []
    for policy_def in template['policy_definitions']:
      if policy_def['type'] == 'group':
        policies += policy_def['policies']
      else:
        policies += [policy_def]
    for policy in policies:
      if policy['type'] == 'int-enum' or policy['type'] == 'string-enum':
        self.RecordEnumIds(policy, ref_ids_schemas)
      elif 'schema' in policy:
        if 'id' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema'], ref_ids_schemas)
        if 'items' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema']['items'],
                                      ref_ids_schemas)
        if 'properties' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema']['properties'],
                                      ref_ids_schemas)
        if 'patternProperties' in policy['schema']:
          self.RecordKnownPropertyIds(policy['schema']['patternProperties'],
                                      ref_ids_schemas)
    policies = [policy for policy in policies if self.IsPolicySupported(policy)]
    output = {
        'title': self.config['bundle_id'],
        'version': self.config['version'].split(".", 1)[0],
        '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']]
      }
      policy_output = output['properties'][policy['name']]
      if policy['id'] in self.POLICY_ID_TO_INPUT:
        policy_output['type'] = self.POLICY_ID_TO_INPUT[policy['id']]
      policy_type = policy_output['type']
      if policy['type'] == 'int-enum' or policy['type'] == 'string-enum':
        policy_output['options'] = {
            'enum_titles': [item['name'] for item in policy['items']]
        }
        policy_output['enum'] = [item['value'] for item in policy['items']]
      elif policy['type'] == 'int' and 'schema' in policy:
        if 'minimum' in policy['schema']:
          policy_output['minimum'] = policy['schema']['minimum']
        if 'maximum' in policy['schema']:
          policy_output['maximum'] = policy['schema']['maximum']
      elif policy['type'] == 'list':
        policy_output['items'] = policy['schema']['items']
      elif policy['type'] == 'string-enum-list' or policy[
          'type'] == 'int-enum-list':
        policy_output['items'] = {
            'type': policy['schema']['items']['type'],
            'options': {
                'enum_titles': [item['name'] for item in policy['items']]
            },
            'enum': [item['value'] for item in policy['items']]
        }
      elif policy_output['type'] == 'object' and policy['type'] != 'external':
        policy_output['type'] = policy['schema']['type']
        if policy_output['type'] == 'array':
          policy_output['items'] = policy['schema']['items']
          self.WriteRefItems(policy_output['items'], policy_output['items'], [],
                             ref_ids_schemas, set())
        elif policy_output['type'] == 'object':
          policy_output['properties'] = policy['schema']['properties']
          self.WriteRefItems(policy_output['properties'],
                             policy_output['properties'], [], ref_ids_schemas,
                             set())
    return json.dumps(output, indent=2, sort_keys=True, separators=(',', ': '))
def WriteTemplate ( self , template ) : ref_ids_schemas = { } policies = [ ] for policy_def in template [ 'policy_definitions' ] : if policy_def [ 'type' ] == 'group' : policies += policy_def [ 'policies' ] else : policies += [ policy_def ] for policy in policies : if policy [ 'type' ] == 'int-enum' or policy [ 'type' ] == 'string-enum' : self . RecordEnumIds ( policy , ref_ids_schemas ) elif 'schema' in policy : if 'id' in policy [ 'schema' ] : self . RecordKnownPropertyIds ( policy [ 'schema' ] , ref_ids_schemas ) if 'items' in policy [ 'schema' ] : self . RecordKnownPropertyIds ( policy [ 'schema' ] [ 'items' ] , ref_ids_schemas ) if 'properties' in policy [ 'schema' ] : self . RecordKnownPropertyIds ( policy [ 'schema' ] [ 'properties' ] , ref_ids_schemas ) if 'patternProperties' in policy [ 'schema' ] : self . RecordKnownPropertyIds ( policy [ 'schema' ] [ 'patternProperties' ] , ref_ids_schemas ) policies = [ policy for policy in policies if self . IsPolicySupported ( policy ) ] output = { 'title' : self . config [ 'bundle_id' ] , 'version' : self . config [ 'version' ] . split ( "." , 1 ) [ 0 ] , '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' ] ] } policy_output = output [ 'properties' ] [ policy [ 'name' ] ] if policy [ 'id' ] in self . POLICY_ID_TO_INPUT : policy_output [ 'type' ] = self . POLICY_ID_TO_INPUT [ policy [ 'id' ] ] policy_type = policy_output [ 'type' ] if policy [ 'type' ] == 'int-enum' or policy [ 'type' ] == 'string-enum' : policy_output [ 'options' ] = { 'enum_titles' : [ item [ 'name' ] for item in policy [ 'items' ] ] } policy_output [ 'enum' ] = [ item [ 'value' ] for item in policy [ 'items' ] ] elif policy [ 'type' ] == 'int' and 'schema' in policy : if 'minimum' in policy [ 'schema' ] : policy_output [ 'minimum' ] = policy [ 'schema' ] [ 'minimum' ] if 'maximum' in policy [ 'schema' ] : policy_output [ 'maximum' ] = policy [ 'schema' ] [ 'maximum' ] elif policy [ 'type' ] == 'list' : policy_output [ 'items' ] = policy [ 'schema' ] [ 'items' ] elif policy [ 'type' ] == 'string-enum-list' or policy [ 'type' ] == 'int-enum-list' : policy_output [ 'items' ] = { 'type' : policy [ 'schema' ] [ 'items' ] [ 'type' ] , 'options' : { 'enum_titles' : [ item [ 'name' ] for item in policy [ 'items' ] ] } , 'enum' : [ item [ 'value' ] for item in policy [ 'items' ] ] } elif policy_output [ 'type' ] == 'object' and policy [ 'type' ] != 'external' : policy_output [ 'type' ] = policy [ 'schema' ] [ 'type' ] if policy_output [ 'type' ] == 'array' : policy_output [ 'items' ] = policy [ 'schema' ] [ 'items' ] self . WriteRefItems ( policy_output [ 'items' ] , policy_output [ 'items' ] , [ ] , ref_ids_schemas , set ( ) ) elif policy_output [ 'type' ] == 'object' : policy_output [ 'properties' ] = policy [ 'schema' ] [ 'properties' ] self . WriteRefItems ( policy_output [ 'properties' ] , policy_output [ 'properties' ] , [ ] , ref_ids_schemas , set ( ) ) return json . dumps ( output , indent = 2 , sort_keys = True , separators = ( ',' , ': ' ) )
Writes the given template definition.
Writes the given template definition .
'''Writes the given template definition.

    Args:
      template: Template definition to write.

    Returns:
      Generated output for the passed template definition.
    ''' # Keep track of all items that can be referred to by an id. # This is used for '$ref' fields in the policy templates. # Iterate over all policies, even the policies contained inside a policy # group.
Generated output for the passed template definition.
Generated output for the passed template definition .
self
template
Template definition to write.
Template definition to write .