Skip to content

Commit 1a39573

Browse files
committed
Fixes #1346
1 parent b59e5dd commit 1a39573

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cli/migration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import sys
2525

2626
from cli import options
27-
from sonar import exceptions, errcodes, utilities
27+
from sonar import exceptions, errcodes, utilities, version
2828
import sonar.logging as log
2929
from sonar import platform, rules, qualityprofiles, qualitygates, users, groups
3030
from sonar import projects, portfolios, applications
@@ -143,6 +143,7 @@ def main() -> None:
143143
kwargs = utilities.convert_args(__parse_args("Extract SonarQube platform configuration"))
144144
endpoint = platform.Platform(**kwargs)
145145
endpoint.verify_connection()
146+
endpoint.set_user_agent(f"sonar-migration {version.MIGRATION_TOOL_VERSION}")
146147
except (options.ArgumentsError, exceptions.ObjectNotFound) as e:
147148
utilities.exit_fatal(e.message, e.errcode)
148149

sonar/platform.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
_NON_EXISTING_SETTING_SKIPPED = "Setting %s does not exist, skipping..."
5454
_HTTP_ERROR = "%s Error: %s HTTP status code %d - %s"
5555

56-
_SONAR_TOOLS_AGENT = {"user-agent": f"sonar-tools {version.PACKAGE_VERSION}"}
56+
_SONAR_TOOLS_AGENT = f"sonar-tools {version.PACKAGE_VERSION}"
5757
_UPDATE_CENTER = "https://raw.githubusercontent.com/SonarSource/sonar-update-center-properties/master/update-center-source.properties"
5858

5959
LTA = None
@@ -88,6 +88,7 @@ def __init__(self, url: str, token: str, org: str = None, cert_file: Optional[st
8888
self.http_timeout = int(http_timeout)
8989
self.organization = org
9090
self.__is_sonarcloud = util.is_sonarcloud_url(self.url)
91+
self._user_agent = _SONAR_TOOLS_AGENT
9192

9293
def __str__(self) -> str:
9394
"""
@@ -136,6 +137,9 @@ def user_data(self) -> types.ApiPayload:
136137
self.__user_data = json.loads(self.get("api/users/current").text)
137138
return self.__user_data
138139

140+
def set_user_agent(self, user_agent: str) -> None:
141+
self._user_agent = user_agent
142+
139143
def server_id(self) -> str:
140144
"""
141145
Returns the SonarQube instance server id
@@ -210,7 +214,7 @@ def __run_request(
210214
) -> requests.Response:
211215
"""Makes an HTTP request to SonarQube"""
212216
api = _normalize_api(api)
213-
headers = _SONAR_TOOLS_AGENT
217+
headers = {"user-agent": self._user_agent}
214218
if params is None:
215219
params = {}
216220
if self.is_sonarcloud():

0 commit comments

Comments
 (0)