def get_rule_data_from_content(profile_id,
                               content_path,
                               ds_id="",
                               xccdf_id="",
                               tailoring_path=""):
    rules = common.get_fix_rules_pre(profile_id, content_path, ds_id, xccdf_id,
                                     tailoring_path)

    # parse and store rules with a clean RuleData instance
    rule_data = RuleData()
    for rule in rules.splitlines():
        rule_data.new_rule(rule)
    return rule_data
예제 #2
0
    def _select_profile(self, profile_id):
        """Selects the given profile."""

        if not profile_id:
            # no profile specified, nothing to do
            return False

        if self._using_ds:
            ds = self._current_ds_id
            xccdf = self._current_xccdf_id

            if not all((ds, xccdf, profile_id)):
                # something is not set -> do nothing
                return False
        else:
            ds = None
            xccdf = None

        # get pre-install fix rules from the content
        try:
            rules = common.get_fix_rules_pre(profile_id,
                                             self._addon_data.preinst_content_path,
                                             ds, xccdf,
                                             self._addon_data.preinst_tailoring_path)
        except common.OSCAPaddonError as exc:
            log.error(
                "Failed to get rules for the profile '{}': {}"
                .format(profile_id, str(exc)))
            self._set_error(
                "Failed to get rules for the profile '{}'"
                .format(profile_id))
            return False

        itr = self._profiles_store.get_iter_first()
        while itr:
            if self._profiles_store[itr][0] == profile_id:
                self._profiles_store.set_value(itr, 2, True)
            itr = self._profiles_store.iter_next(itr)

        # parse and store rules with a clean RuleData instance
        self._rule_data = rule_handling.RuleData()
        for rule in rules.splitlines():
            self._rule_data.new_rule(rule)

        # remember the active profile
        self._active_profile = profile_id

        return True
예제 #3
0
    def _select_profile(self, profile_id):
        """Selects the given profile."""

        if not profile_id:
            # no profile specified, nothing to do
            return False

        if self._using_ds:
            ds = self._current_ds_id
            xccdf = self._current_xccdf_id

            if not all((ds, xccdf, profile_id)):
                # something is not set -> do nothing
                return False
        else:
            ds = None
            xccdf = None

        # get pre-install fix rules from the content
        try:
            rules = common.get_fix_rules_pre(profile_id,
                                             self._addon_data.preinst_content_path,
                                             ds, xccdf,
                                             self._addon_data.preinst_tailoring_path)
        except common.OSCAPaddonError as exc:
            log.error(
                "Failed to get rules for the profile '{}': {}"
                .format(profile_id, str(exc)))
            self._set_error(
                "Failed to get rules for the profile '{}'"
                .format(profile_id))
            return False

        itr = self._profiles_store.get_iter_first()
        while itr:
            if self._profiles_store[itr][0] == profile_id:
                self._profiles_store.set_value(itr, 2, True)
            itr = self._profiles_store.iter_next(itr)

        # parse and store rules with a clean RuleData instance
        self._rule_data = rule_handling.RuleData()
        for rule in rules.splitlines():
            self._rule_data.new_rule(rule)

        # remember the active profile
        self._active_profile = profile_id

        return True
예제 #4
0
    def _fetch_content_and_initialize(self):
        """Fetch content and initialize from it"""

        data_fetch.fetch_data(self.content_url, self.raw_preinst_content_path,
                              self.certificates)
        # RPM is an archive at this phase
        if self.content_type in ("archive", "rpm"):
            # extract the content
            common.extract_data(self.raw_preinst_content_path,
                                common.INSTALLATION_CONTENT_DIR,
                                [self.content_path])

        rules = common.get_fix_rules_pre(self.profile_id,
                                         self.preinst_content_path,
                                         self.datastream_id, self.xccdf_id,
                                         self.preinst_tailoring_path)

        # parse and store rules with a clean RuleData instance
        self.rule_data = rule_handling.RuleData()
        for rule in rules.splitlines():
            self.rule_data.new_rule(rule)
예제 #5
0
    def _fetch_content_and_initialize(self):
        """Fetch content and initialize from it"""

        data_fetch.fetch_data(self.content_url, self.raw_preinst_content_path,
                              self.certificates)
        # RPM is an archive at this phase
        if self.content_type in ("archive", "rpm"):
            # extract the content
            common.extract_data(self.raw_preinst_content_path,
                                common.INSTALLATION_CONTENT_DIR,
                                [self.content_path])

        rules = common.get_fix_rules_pre(self.profile_id,
                                         self.preinst_content_path,
                                         self.datastream_id, self.xccdf_id,
                                         self.preinst_tailoring_path)

        # parse and store rules with a clean RuleData instance
        self.rule_data = rule_handling.RuleData()
        for rule in rules.splitlines():
            self.rule_data.new_rule(rule)