@@ -223,9 +223,10 @@ def get_object(endpoint: platform.Platform, key: str) -> Optional[Rule]:
223223 return None
224224
225225
226- def export_all (endpoint : platform .Platform , full : bool = False ) -> types .ObjectJsonRepr :
226+ def export (endpoint : platform .Platform , export_settings : types . ConfigSettings , key_list : types . KeyList = None ) -> types .ObjectJsonRepr :
227227 """Returns a JSON export of all rules"""
228228 log .info ("Exporting rules" )
229+ full = export_settings .get ("FULL_EXPORT" , False )
229230 rule_list , other_rules , instantiated_rules , extended_rules = {}, {}, {}, {}
230231 for rule_key , rule in get_list (endpoint = endpoint ).items ():
231232 rule_export = rule .export (full )
@@ -251,57 +252,6 @@ def export_all(endpoint: platform.Platform, full: bool = False) -> types.ObjectJ
251252 return rule_list
252253
253254
254- def export_instantiated (endpoint : platform .Platform , full : bool = False ) -> Optional [types .ObjectJsonRepr ]:
255- """Returns a JSON of all instantiated rules"""
256- rule_list = {}
257- for template_key in get_list (endpoint = endpoint , is_template = "true" ):
258- for rule_key , rule in get_list (endpoint = endpoint , template_key = template_key ).items ():
259- rule_list [rule_key ] = rule .export (full )
260- return rule_list if len (rule_list ) > 0 else None
261-
262-
263- def export_customized (endpoint : platform .Platform , full : bool = False ) -> Optional [types .ObjectJsonRepr ]:
264- """Returns a JSON export of all customized rules (custom tags or description added)"""
265- rule_list = {}
266- for rule_key , rule in get_list (endpoint = endpoint , is_template = "false" ).items ():
267- if rule .tags is None and rule .custom_desc is None :
268- continue
269- if full :
270- rule_list [rule_key ] = rule .export (full )
271- continue
272- rule_list [rule_key ] = {}
273- if rule .tags :
274- rule_list [rule_key ]["tags" ] = utilities .list_to_csv (rule .tags , ", " )
275- if rule .custom_desc :
276- rule_list [rule_key ]["description" ] = rule .custom_desc
277- return rule_list if len (rule_list ) > 0 else None
278-
279-
280- def export_needed (endpoint : platform .Platform , instantiated : bool = True , extended : bool = True , full : bool = False ) -> types .ObjectJsonRepr :
281- """Returns a JSON export selected / needed rules"""
282- rule_list = {}
283- if instantiated :
284- rule_list ["instantiated" ] = export_instantiated (endpoint , full )
285- if extended :
286- rule_list ["extended" ] = export_customized (endpoint , full )
287- return utilities .remove_nones (rule_list )
288-
289-
290- def export (endpoint : platform .Platform , export_settings : types .ConfigSettings , key_list : types .KeyList = None ) -> types .ObjectJsonRepr :
291- """Returns a dict of rules for export
292- :param Platform endpoint: The SonarQube Platform object to connect to
293- :param ConfigSettings export_settings: parameters to export
294- :param KeyList key_list: Unused
295- :return: a dict of rules with their JSON representation
296- :rtype: ObjectJsonRepr
297- """
298- log .info ("Exporting rules" )
299- # if standard:
300- return export_all (endpoint , export_settings ["FULL_EXPORT" ])
301- # else:
302- # return export_needed(endpoint, instantiated, extended, export_settings["FULL_EXPORT"])
303-
304-
305255def import_config (endpoint : platform .Platform , config_data : types .ObjectJsonRepr , key_list : types .KeyList = None ) -> bool :
306256 """Imports a sonar-config configuration"""
307257 if "rules" not in config_data :
0 commit comments