Esempio n. 1
0
    def ReadArtifactDefinitionValues(self, artifact_definition_values):
        """Reads an artifact definition from a dictionary.

    Args:
      artifact_definition_values (dict[str, object]): artifact definition
          values.

    Returns:
      ArtifactDefinition: an artifact definition.

    Raises:
      FormatError: if the format of the artifact definition is not set
          or incorrect.
    """
        if not artifact_definition_values:
            raise errors.FormatError('Missing artifact definition values.')

        different_keys = (set(artifact_definition_values) -
                          definitions.TOP_LEVEL_KEYS)
        if different_keys:
            different_keys = ', '.join(different_keys)
            raise errors.FormatError(
                'Undefined keys: {0:s}'.format(different_keys))

        name = artifact_definition_values.get('name', None)
        if not name:
            raise errors.FormatError(
                'Invalid artifact definition missing name.')

        # The description is assumed to be mandatory.
        description = artifact_definition_values.get('doc', None)
        if not description:
            raise errors.FormatError(
                'Invalid artifact definition: {0:s} missing description.'.
                format(name))

        artifact_definition = artifact.ArtifactDefinition(
            name, description=description)

        if artifact_definition_values.get('collectors', []):
            raise errors.FormatError(
                'Invalid artifact definition: {0:s} still uses collectors.'.
                format(name))

        # TODO: check conditions.
        artifact_definition.conditions = artifact_definition_values.get(
            'conditions', [])
        artifact_definition.provides = artifact_definition_values.get(
            'provides', [])
        self._ReadLabels(artifact_definition_values, artifact_definition, name)
        self._ReadSupportedOS(artifact_definition_values, artifact_definition,
                              name)
        artifact_definition.urls = artifact_definition_values.get('urls', [])
        self._ReadSources(artifact_definition_values, artifact_definition,
                          name)

        return artifact_definition
Esempio n. 2
0
    def _ReadArtifactDefinition(self, yaml_definition):
        """Reads an artifact definition.

    Args:
      yaml_definition: the YAML artifact definition.
 
    Returns:
      An artifact definition (instance of ArtifactDefinition).

    Raises:
      FormatError: if the format of the YAML artifact definition is not set
                   or incorrect.
    """
        if not yaml_definition:
            raise errors.FormatError(u'Missing YAML definition.')

        name = yaml_definition.get('name', None)
        if not name:
            raise errors.FormatError(
                u'Invalid artifact definition missing name.')

        # The description is assumed to be mandatory.
        description = yaml_definition.get('doc', None)
        if not description:
            raise errors.FormatError(
                u'Invalid artifact definition missing description.')

        artifact_definition = artifact.ArtifactDefinition(
            name, description=description)

        for collector in yaml_definition.get('collectors', []):
            type_indicator = collector.get('collector_type', None)
            if not type_indicator:
                raise errors.FormatError(
                    u'Invalid artifact definition collector missing type.')

            arguments = collector.get('args', None)
            collector_definition = artifact_definition.AppendCollector(
                type_indicator, arguments)

            if collector_definition:
                collector_definition.conditions = collector.get(
                    'conditions', [])
                collector_definition.returned_types = collector.get(
                    'returned_types', [])
                self._ReadSupportedOS(yaml_definition, collector_definition,
                                      name)

        # TODO: check conditions.
        artifact_definition.conditions = yaml_definition.get('conditions', [])
        artifact_definition.provides = yaml_definition.get('provides', [])
        self._ReadLabels(yaml_definition, artifact_definition, name)
        self._ReadSupportedOS(yaml_definition, artifact_definition, name)
        artifact_definition.urls = yaml_definition.get('urls', [])

        return artifact_definition
Esempio n. 3
0
  def _ReadArtifactDefinition(self, yaml_definition):
    """Reads an artifact definition.

    Args:
      yaml_definition: the YAML artifact definition.

    Returns:
      An artifact definition (instance of ArtifactDefinition).

    Raises:
      FormatError: if the format of the YAML artifact definition is not set
                   or incorrect.
    """
    if not yaml_definition:
      raise errors.FormatError(u'Missing YAML definition.')

    name = yaml_definition.get(u'name', None)
    if not name:
      raise errors.FormatError(u'Invalid artifact definition missing name.')

    # The description is assumed to be mandatory.
    description = yaml_definition.get(u'doc', None)
    if not description:
      raise errors.FormatError(
          u'Invalid artifact definition: {0:s} missing description.'.format(
              name))

    artifact_definition = artifact.ArtifactDefinition(
        name, description=description)

    if yaml_definition.get(u'collectors', []):
      raise errors.FormatError(
          u'Invalid artifact definition: {0:s} still uses collectors.'.format(
              name))

    for source in yaml_definition.get(u'sources', []):
      type_indicator = source.get(u'type', None)
      if not type_indicator:
        raise errors.FormatError(
            u'Invalid artifact definition: {0:s} source type.'.format(name))

      attributes = source.get(u'attributes', None)
      try:
        source_type = artifact_definition.AppendSource(
            type_indicator, attributes)
      except errors.FormatError as exception:
        raise errors.FormatError(
            u'Invalid artifact definition: {0:s}. {1:s}'.format(
                name, exception))

      # TODO: deprecate these left overs from the collector definition.
      if source_type:
        source_type.conditions = source.get(u'conditions', [])
        source_type.returned_types = source.get(u'returned_types', [])
        self._ReadSupportedOS(yaml_definition, source_type, name)

    # TODO: check conditions.
    artifact_definition.conditions = yaml_definition.get(u'conditions', [])
    artifact_definition.provides = yaml_definition.get(u'provides', [])
    self._ReadLabels(yaml_definition, artifact_definition, name)
    self._ReadSupportedOS(yaml_definition, artifact_definition, name)
    artifact_definition.urls = yaml_definition.get(u'urls', [])

    return artifact_definition