def __init__(self, name, just_clear=False): """ :param name: name of the addon :type name: str """ if not just_clear: # do not call the parent's __init__ more than once AddonData.__init__(self, name) # values specifying the content self.content_type = "" self.content_url = "" self.datastream_id = "" self.xccdf_id = "" self.profile_id = "" self.content_path = "" self.cpe_path = "" self.tailoring_path = "" # additional values self.fingerprint = "" # certificate to verify HTTPS connection or signed data self.certificates = "" # internal values self.rule_data = rule_handling.RuleData() self.dry_run = False
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
def clear_all(data): data.content_type = "" data.content_url = "" data.datastream_id = "" data.xccdf_id = "" data.profile_id = "" data.content_path = "" data.cpe_path = "" data.tailoring_path = "" data.fingerprint = "" data.certificates = "" # internal values data.rule_data = rule_handling.RuleData() data.dry_run = False
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)
def rule_data(): return rule_handling.RuleData()
def setUp(self): self.rule_data = rule_handling.RuleData() self.ksdata_mock = mock.Mock() self.storage_mock = mock.Mock()
def setUp(self): self.rule_data = rule_handling.RuleData()