From a9656eec24d0730a48d7d15d793d70bac6f05d58 Mon Sep 17 00:00:00 2001 From: PagesCoffy Date: Wed, 6 Dec 2023 12:06:01 +0000 Subject: [PATCH] Use Basic Auth for Sonarqube Onpremise (#262) --- integrations/sonarqube/CHANGELOG.md | 7 +++++++ integrations/sonarqube/client.py | 9 +++++++-- integrations/sonarqube/pyproject.toml | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/integrations/sonarqube/CHANGELOG.md b/integrations/sonarqube/CHANGELOG.md index 7fc12155fa..befc43967d 100644 --- a/integrations/sonarqube/CHANGELOG.md +++ b/integrations/sonarqube/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +# Port_Ocean 0.1.17 (2023-12-06) + +### Bug Fixes + +- Corrected SonarQube On-Premise authentication to resolve 401 error codes previously experienced by users. This fix now properly utilizes Basic authentication (#17) + + # Port_Ocean 0.1.16 (2023-12-05) ### Bug Fixes diff --git a/integrations/sonarqube/client.py b/integrations/sonarqube/client.py index 144442f7f7..88182e54fb 100644 --- a/integrations/sonarqube/client.py +++ b/integrations/sonarqube/client.py @@ -1,5 +1,5 @@ from typing import Any, Optional, AsyncGenerator, cast - +import base64 import httpx from loguru import logger @@ -48,9 +48,14 @@ def api_auth_params(self) -> dict[str, Any]: "Content-Type": "application/json", } } + + auth_message = f"{self.api_key}:" + auth_bytes = auth_message.encode("ascii") + b64_bytes = base64.b64encode(auth_bytes) + b64_message = b64_bytes.decode("ascii") return { - "auth": (self.api_key, ""), "headers": { + "Authorization": f"Basic {b64_message}", "Content-Type": "application/json", }, } diff --git a/integrations/sonarqube/pyproject.toml b/integrations/sonarqube/pyproject.toml index 9d619878de..fa0eaf4114 100644 --- a/integrations/sonarqube/pyproject.toml +++ b/integrations/sonarqube/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sonarqube" -version = "0.1.16" +version = "0.1.17" description = "SonarQube projects and code quality analysis integration" authors = ["Port Team "]