Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/rules_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main() -> int:
params = {}
if options.LANGUAGES in kwargs:
params = {"languages": util.list_to_csv(kwargs[options.LANGUAGES])}
rule_list = rules.get_list(endpoint=endpoint, **params)
rule_list = rules.get_list(endpoint=endpoint, use_cache=False, **params)

try:
if fmt == "csv":
Expand Down
10 changes: 4 additions & 6 deletions sonar/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ def count(endpoint: platform.Platform, **params) -> int:
return json.loads(endpoint.get(Rule.SEARCH_API, params={**params, "ps": 1}).text)["total"]


def get_list(endpoint: platform.Platform, **params) -> dict[str, Rule]:
def get_list(endpoint: platform.Platform, use_cache: bool = True, **params) -> dict[str, Rule]:
"""Returns a list of rules corresponding to certain csearch filters"""
if len(_OBJECTS) < 100:
if not use_cache or params or len(_OBJECTS) < 100:
return search(endpoint, include_external="false", **params)
return _OBJECTS

Expand All @@ -276,7 +276,7 @@ def export(endpoint: platform.Platform, export_settings: types.ConfigSettings, k
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():
for rule_key, rule in get_list(endpoint=endpoint, use_cache=False).items():
rule_export = rule.export(full)
if rule.template_key is not None:
instantiated_rules[rule_key] = rule_export
Expand Down Expand Up @@ -310,7 +310,7 @@ def import_config(endpoint: platform.Platform, config_data: types.ObjectJsonRepr
if endpoint.is_sonarcloud():
raise exceptions.UnsupportedOperation("Can't import rules in SonarCloud")
log.info("Importing customized (custom tags, extended description) rules")
get_list(endpoint=endpoint)
get_list(endpoint=endpoint, use_cache=False)
for key, custom in config_data["rules"].get("extended", {}).items():
try:
rule = Rule.get_object(endpoint, key)
Expand All @@ -320,8 +320,6 @@ def import_config(endpoint: platform.Platform, config_data: types.ObjectJsonRepr
rule.set_description(custom.get("description", ""))
rule.set_tags(utilities.csv_to_list(custom.get("tags", None)))

log.debug("get_list from import")
get_list(endpoint=endpoint, templates=True)
log.info("Importing custom rules (instantiated from rule templates)")
for key, instantiation_data in config_data["rules"].get("instantiated", {}).items():
try:
Expand Down