@@ -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
832825def _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
854846def _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 ):
@@ -974,3 +963,29 @@ def audit(endpoint: Platform, audit_settings: types.ConfigSettings, **kwargs) ->
974963 pbs = endpoint .audit (audit_settings )
975964 "write_q" in kwargs and kwargs ["write_q" ].put (pbs )
976965 return pbs
966+
967+
968+ def old_to_new_json (old_json : dict [str , Any ]) -> dict [str , Any ]:
969+ """Converts sonar-config "plaform" section old JSON report format to new format"""
970+ if "plugins" in old_json :
971+ old_json ["plugins" ] = util .dict_to_list (old_json ["plugins" ], "key" )
972+ return old_json
973+
974+
975+ def global_settings_old_to_new_json (old_json : dict [str , Any ]) -> dict [str , Any ]:
976+ """Converts sonar-config "globalSettings" section old JSON report format to new format"""
977+ new_json = {}
978+ special_categories = (settings .LANGUAGES_SETTINGS , settings .DEVOPS_INTEGRATION , "permissions" , "permissionTemplates" )
979+ for categ in [cat for cat in settings .CATEGORIES if cat not in special_categories ]:
980+ new_json [categ ] = util .sort_list_by_key (util .dict_to_list (old_json [categ ], "key" ), "key" )
981+ for k , v in old_json [settings .LANGUAGES_SETTINGS ].items ():
982+ new_json [settings .LANGUAGES_SETTINGS ] = new_json .get (settings .LANGUAGES_SETTINGS , None ) or {}
983+ new_json [settings .LANGUAGES_SETTINGS ][k ] = util .sort_list_by_key (util .dict_to_list (v , "key" ), "key" )
984+ new_json [settings .LANGUAGES_SETTINGS ] = util .dict_to_list (new_json [settings .LANGUAGES_SETTINGS ], "language" , "settings" )
985+ new_json [settings .DEVOPS_INTEGRATION ] = util .dict_to_list (old_json [settings .DEVOPS_INTEGRATION ], "key" )
986+ new_json ["permissions" ] = util .perms_to_list (old_json ["permissions" ])
987+ for v in old_json ["permissionTemplates" ].values ():
988+ if "permissions" in v :
989+ v ["permissions" ] = util .perms_to_list (v ["permissions" ])
990+ new_json ["permissionTemplates" ] = util .dict_to_list (old_json ["permissionTemplates" ], "key" )
991+ return new_json
0 commit comments