|
40 | 40 | import sonar.utilities as util |
41 | 41 | from sonar.util import types, update_center |
42 | 42 | import sonar.util.constants as c |
| 43 | +import sonar.util.platform_helper as pfhelp |
43 | 44 |
|
44 | 45 | from sonar import errcodes, settings, devops, version, sif, exceptions, organizations |
45 | 46 | from sonar.permissions import permissions, global_permissions, permission_templates |
@@ -262,7 +263,7 @@ def delete(self, api: str, params: types.ApiParams = None, **kwargs) -> requests |
262 | 263 | def __run_request(self, request: callable, api: str, params: types.ApiParams = None, **kwargs) -> requests.Response: |
263 | 264 | """Makes an HTTP request to SonarQube""" |
264 | 265 | mute = kwargs.pop("mute", ()) |
265 | | - api = _normalize_api(api) |
| 266 | + api = pfhelp.normalize_api(api) |
266 | 267 | headers = {"user-agent": self._user_agent, "accept": _APP_JSON} | kwargs.get("headers", {}) |
267 | 268 | params = params or {} |
268 | 269 | with_org = kwargs.pop("with_organization", True) |
@@ -791,19 +792,6 @@ def set_standard_experience(self) -> bool: |
791 | 792 | this.context = Platform(os.getenv("SONAR_HOST_URL", "http://localhost:9000"), os.getenv("SONAR_TOKEN", "")) |
792 | 793 |
|
793 | 794 |
|
794 | | -def _normalize_api(api: str) -> str: |
795 | | - """Normalizes an API based on its multiple original forms""" |
796 | | - if api.startswith("/api/"): |
797 | | - pass |
798 | | - elif api.startswith("api/"): |
799 | | - api = "/" + api |
800 | | - elif api.startswith("/"): |
801 | | - api = "/api" + api |
802 | | - else: |
803 | | - api = "/api/" + api |
804 | | - return api |
805 | | - |
806 | | - |
807 | 795 | def _audit_setting_value(key: str, platform_settings: dict[str, Any], audit_settings: types.ConfigSettings, url: str) -> list[Problem]: |
808 | 796 | """Audits a particular platform setting is set to expected value""" |
809 | 797 | if (v := _get_multiple_values(4, audit_settings[key], "MEDIUM", "CONFIGURATION")) is None: |
@@ -963,29 +951,3 @@ def audit(endpoint: Platform, audit_settings: types.ConfigSettings, **kwargs) -> |
963 | 951 | pbs = endpoint.audit(audit_settings) |
964 | 952 | "write_q" in kwargs and kwargs["write_q"].put(pbs) |
965 | 953 | 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