Skip to content

Commit 5a553ee

Browse files
committed
Quality pass
1 parent b91471c commit 5a553ee

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

sonar/platform.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,7 @@ def __urlstring(self, api: str, params: types.ApiParams, data: Optional[str] = N
465465
return url
466466

467467
def webhooks(self) -> dict[str, webhooks.WebHook]:
468-
"""
469-
:return: the list of global webhooks
470-
"""
468+
"""Returns the list of global webhooks"""
471469
return webhooks.get_list(self)
472470

473471
def export(self, export_settings: types.ConfigSettings, full: bool = False) -> types.ObjectJsonRepr:
@@ -476,19 +474,16 @@ def export(self, export_settings: types.ConfigSettings, full: bool = False) -> t
476474
:param full: Whether to also export properties that cannot be set, defaults to False
477475
:type full: bool, optional
478476
:return: dict of all properties with their values
479-
:rtype: dict
480477
"""
481478
log.info("Exporting platform global settings")
482479
json_data = {}
480+
settings_list = self.__settings(include_not_set=export_settings.get("EXPORT_DEFAULTS", False)).values()
481+
settings_list = [s for s in settings_list if s.is_global() and not s.is_internal()]
483482
for s in self.__settings(include_not_set=export_settings.get("EXPORT_DEFAULTS", False)).values():
484-
if s.is_internal():
485-
continue
486483
(categ, subcateg) = s.category()
487484
if self.is_sonarcloud() and categ == settings.THIRD_PARTY_SETTINGS:
488485
# What is reported as 3rd part are SonarQube Cloud internal settings
489486
continue
490-
if not s.is_global():
491-
continue
492487
util.update_json(json_data, categ, subcateg, s.to_json(export_settings.get("INLINE_LISTS", True)))
493488

494489
hooks = {}
@@ -650,8 +645,7 @@ def _audit_logs(self, audit_settings: types.ConfigSettings) -> list[Problem]:
650645
if rule is not None:
651646
problems.append(Problem(rule, f"{self.local_url}/admin/system", logfile, line))
652647
logs = self.get("system/logs", params={"name": "deprecation"}).text
653-
nb_deprecation = len(logs.splitlines())
654-
if nb_deprecation > 0:
648+
if (nb_deprecation := len(logs.splitlines())) > 0:
655649
rule = get_rule(RuleId.DEPRECATION_WARNINGS)
656650
problems.append(Problem(rule, f"{self.local_url}/admin/system", nb_deprecation))
657651
return problems
@@ -810,10 +804,9 @@ def _normalize_api(api: str) -> str:
810804
return api
811805

812806

813-
def _audit_setting_value(key: str, platform_settings: dict[str, any], audit_settings: types.ConfigSettings, url: str) -> list[Problem]:
807+
def _audit_setting_value(key: str, platform_settings: dict[str, Any], audit_settings: types.ConfigSettings, url: str) -> list[Problem]:
814808
"""Audits a particular platform setting is set to expected value"""
815-
v = _get_multiple_values(4, audit_settings[key], "MEDIUM", "CONFIGURATION")
816-
if v is None:
809+
if (v := _get_multiple_values(4, audit_settings[key], "MEDIUM", "CONFIGURATION")) is None:
817810
log.error(WRONG_CONFIG_MSG, key, audit_settings[key])
818811
return []
819812
if v[0] not in platform_settings:
@@ -830,11 +823,10 @@ def _audit_setting_value(key: str, platform_settings: dict[str, any], audit_sett
830823

831824

832825
def _audit_setting_in_range(
833-
key: str, platform_settings: dict[str, any], audit_settings: types.ConfigSettings, sq_version: tuple[int, int, int], url: str
826+
key: str, platform_settings: dict[str, Any], audit_settings: types.ConfigSettings, sq_version: tuple[int, int, int], url: str
834827
) -> list[Problem]:
835828
"""Audits a particular platform setting is within expected range of values"""
836-
v = _get_multiple_values(5, audit_settings[key], "MEDIUM", "CONFIGURATION")
837-
if v is None:
829+
if (v := _get_multiple_values(5, audit_settings[key], "MEDIUM", "CONFIGURATION")) is None:
838830
log.error(WRONG_CONFIG_MSG, key, audit_settings[key])
839831
return []
840832
if v[0] not in platform_settings:
@@ -852,11 +844,10 @@ def _audit_setting_in_range(
852844

853845

854846
def _audit_setting_set(
855-
key: str, check_is_set: bool, platform_settings: dict[str, any], audit_settings: types.ConfigSettings, url: str
847+
key: str, check_is_set: bool, platform_settings: dict[str, Any], audit_settings: types.ConfigSettings, url: str
856848
) -> list[Problem]:
857849
"""Audits that a setting is set or not set"""
858-
v = _get_multiple_values(3, audit_settings[key], "MEDIUM", "CONFIGURATION")
859-
if v is None:
850+
if (v := _get_multiple_values(3, audit_settings[key], "MEDIUM", "CONFIGURATION")) is None:
860851
log.error(WRONG_CONFIG_MSG, key, audit_settings[key])
861852
return []
862853
log.info("Auditing whether setting %s is set or not", v[0])
@@ -928,7 +919,6 @@ def import_config(endpoint: Platform, config_data: types.ObjectJsonRepr, key_lis
928919
:param Platform endpoint: reference to the SonarQube platform
929920
:param ObjectJsonRepr config_data: the configuration to import
930921
:param KeyList key_list: Unused
931-
:return: Nothing
932922
"""
933923
return endpoint.import_config(config_data)
934924

@@ -948,7 +938,6 @@ def export(endpoint: Platform, export_settings: types.ConfigSettings, **kwargs)
948938
:param Platform endpoint: reference to the SonarQube platform
949939
:param ConfigSettings export_settings: Export parameters
950940
:return: Platform settings
951-
:rtype: ObjectJsonRepr
952941
"""
953942
exp = endpoint.export(export_settings)
954943
if write_q := kwargs.get("write_q", None):

0 commit comments

Comments
 (0)