Skip to content

Commit

Permalink
Use urllib.parse.urljoin on multiple places
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaarreell committed Aug 28, 2024
1 parent b279d32 commit d5f0e81
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions newa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,19 +444,25 @@ class ErrataTool:

def fetch_info(self, erratum_id: str) -> JSON:
return get_request(
url=f"{self.url}/advisory/{Q(erratum_id)}.json",
url=urllib.parse.urljoin(
self.url,
f"/advisory/{Q(erratum_id)}.json"),
krb=True,
response_content=ResponseContentType.JSON)

def fetch_releases(self, erratum_id: str) -> JSON:
return get_request(
url=f"{self.url}/advisory/{Q(erratum_id)}/builds.json",
url=urllib.parse.urljoin(
self.url,
f"/advisory/{Q(erratum_id)}/builds.json"),
krb=True,
response_content=ResponseContentType.JSON)

def fetch_blocking_errata(self, erratum_id: str) -> JSON:
return get_request(
url=f"{self.url}/errata/blocking_errata_for/{Q(erratum_id)}.json",
url=urllib.parse.urljoin(
self.url,
f"/errata/blocking_errata_for/{Q(erratum_id)}.json"),
# not using krb=True due to an authentization error/bug, we did auth already
# krb=True,
response_content=ResponseContentType.JSON)
Expand Down Expand Up @@ -541,17 +547,21 @@ def get_errata(self, event: Event, process_blocking_errata: bool = True) -> list
blocking_builds=blocking_builds,
archs=Arch.architectures(list(archs)),
components=components,
url=f"{self.url}/advisory/{event.id}"))
url=urllib.parse.urljoin(self.url, f"/advisory/{event.id}")))
else:
raise Exception(f"No builds found in ER#{event.id}")

return errata

def get_blocking_errata(self, erratum_id: str) -> list[Erratum]:
blockers = list(self.fetch_blocking_errata(erratum_id).keys())
# FIXME: cowardly evaluating just the 1st level of blocking errata
# to avoid possible recursion
errata = [self.get_errata(Event(type_=EventType.ERRATUM, id=e),
process_blocking_errata=False) for e in blockers]
if errata:
# each get_errata() call may return a list of objects so we need
# to turn this list of list into a single list
return reduce(lambda l1, l2: l1 + l2, errata)
return []

Expand Down Expand Up @@ -1349,14 +1359,16 @@ class ReportPortal:
project: str

def get_launch_url(self, launch_id: str) -> str:
return f"{self.url}/ui/#{Q(self.project)}/launches/all/{Q(launch_id)}"
return urllib.parse.urljoin(
self.url, f"/ui/#{Q(self.project)}/launches/all/{Q(launch_id)}")

def get_request(self,
path: str,
params: Optional[dict[str, str]] = None,
version: int = 1) -> JSON:
url = urllib.parse.urljoin(
self.url, f'/api/v{version}/{Q(self.project)}/{Q(path.lstrip("/"))}')
self.url,
f'/api/v{version}/{Q(self.project)}/{Q(path.lstrip("/"))}')
if params:
url = f'{url}?{urllib.parse.urlencode(params)}'
headers = {"Authorization": f"bearer {self.token}", "Content-Type": "application/json"}
Expand All @@ -1369,7 +1381,9 @@ def post_request(self,
path: str,
json: JSON,
version: int = 1) -> JSON:
url = f'{self.url}/api/v{version}/{Q(self.project)}/{Q(path.lstrip("/"))}'
url = urllib.parse.urljoin(
self.url,
f'/api/v{version}/{Q(self.project)}/{Q(path.lstrip("/"))}')
headers = {"Authorization": f"bearer {self.token}", "Content-Type": "application/json"}
req = requests.post(url, headers=headers, json=json)
if req.status_code == 200:
Expand Down

0 comments on commit d5f0e81

Please sign in to comment.