diff --git a/sonar/portfolios.py b/sonar/portfolios.py index faaed9688..0f61b6834 100644 --- a/sonar/portfolios.py +++ b/sonar/portfolios.py @@ -625,9 +625,8 @@ def get_list(endpoint: pf.Platform, key_list: types.KeyList = None, use_cache: b """ with _CLASS_LOCK: if key_list is None or len(key_list) == 0 or not use_cache: - log.info("Listing portfolios") + log.debug("Listing portfolios") object_list = search(endpoint=endpoint) - log.info("List = %s", ", ".join(list(object_list.keys()))) return object_list object_list = {} for key in util.csv_to_list(key_list): diff --git a/sonar/rules.py b/sonar/rules.py index ebe8ab2eb..0670732a9 100644 --- a/sonar/rules.py +++ b/sonar/rules.py @@ -223,9 +223,10 @@ def get_object(endpoint: platform.Platform, key: str) -> Optional[Rule]: return None -def export_all(endpoint: platform.Platform, full: bool = False) -> types.ObjectJsonRepr: +def export(endpoint: platform.Platform, export_settings: types.ConfigSettings, key_list: types.KeyList = None) -> types.ObjectJsonRepr: """Returns a JSON export of all rules""" log.info("Exporting rules") + full = export_settings.get("FULL_EXPORT", False) rule_list, other_rules, instantiated_rules, extended_rules = {}, {}, {}, {} for rule_key, rule in get_list(endpoint=endpoint).items(): rule_export = rule.export(full) @@ -251,57 +252,6 @@ def export_all(endpoint: platform.Platform, full: bool = False) -> types.ObjectJ return rule_list -def export_instantiated(endpoint: platform.Platform, full: bool = False) -> Optional[types.ObjectJsonRepr]: - """Returns a JSON of all instantiated rules""" - rule_list = {} - for template_key in get_list(endpoint=endpoint, is_template="true"): - for rule_key, rule in get_list(endpoint=endpoint, template_key=template_key).items(): - rule_list[rule_key] = rule.export(full) - return rule_list if len(rule_list) > 0 else None - - -def export_customized(endpoint: platform.Platform, full: bool = False) -> Optional[types.ObjectJsonRepr]: - """Returns a JSON export of all customized rules (custom tags or description added)""" - rule_list = {} - for rule_key, rule in get_list(endpoint=endpoint, is_template="false").items(): - if rule.tags is None and rule.custom_desc is None: - continue - if full: - rule_list[rule_key] = rule.export(full) - continue - rule_list[rule_key] = {} - if rule.tags: - rule_list[rule_key]["tags"] = utilities.list_to_csv(rule.tags, ", ") - if rule.custom_desc: - rule_list[rule_key]["description"] = rule.custom_desc - return rule_list if len(rule_list) > 0 else None - - -def export_needed(endpoint: platform.Platform, instantiated: bool = True, extended: bool = True, full: bool = False) -> types.ObjectJsonRepr: - """Returns a JSON export selected / needed rules""" - rule_list = {} - if instantiated: - rule_list["instantiated"] = export_instantiated(endpoint, full) - if extended: - rule_list["extended"] = export_customized(endpoint, full) - return utilities.remove_nones(rule_list) - - -def export(endpoint: platform.Platform, export_settings: types.ConfigSettings, key_list: types.KeyList = None) -> types.ObjectJsonRepr: - """Returns a dict of rules for export - :param Platform endpoint: The SonarQube Platform object to connect to - :param ConfigSettings export_settings: parameters to export - :param KeyList key_list: Unused - :return: a dict of rules with their JSON representation - :rtype: ObjectJsonRepr - """ - log.info("Exporting rules") - # if standard: - return export_all(endpoint, export_settings["FULL_EXPORT"]) - # else: - # return export_needed(endpoint, instantiated, extended, export_settings["FULL_EXPORT"]) - - def import_config(endpoint: platform.Platform, config_data: types.ObjectJsonRepr, key_list: types.KeyList = None) -> bool: """Imports a sonar-config configuration""" if "rules" not in config_data: diff --git a/test/test_rules.py b/test/test_rules.py index d5f2ba11b..5b89270e9 100644 --- a/test/test_rules.py +++ b/test/test_rules.py @@ -153,9 +153,9 @@ def test_get_rule_cache() -> None: def test_export_not_full() -> None: """test_export_not_full""" - rule_list = rules.export_all(endpoint=util.SQ, full=False) + rule_list = rules.export(endpoint=util.SQ, export_settings={"FULL_EXPORT": False}) assert len(rule_list["extended"]) > 0 - rule_list = rules.export_all(endpoint=util.SQ, full=True) + rule_list = rules.export(endpoint=util.SQ, export_settings={"FULL_EXPORT": True}) assert len(rule_list["extended"]) > 0 @@ -170,7 +170,7 @@ def test_get_nonexisting_rule() -> None: def test_export_all() -> None: """test_export_all""" - rule_list = rules.export_all(endpoint=util.SQ, full=True) + rule_list = rules.export(endpoint=util.SQ, export_settings={"FULL_EXPORT": True}) if util.SQ.version() < (10, 0, 0) and util.SQ.edition() == "community": assert len(rule_list.get("standard", {})) > 2800 else: