Skip to content

Commit

Permalink
backend: don't use custom urlencode for Pulp queries
Browse files Browse the repository at this point in the history
The reasoning for doing so was based on a wrong premise.

> The standard urlencode would change the slashes to %2F making Pulp to
> not find the project when filtering by name.

The reason why Pulp couldn't find any project wasn't becaues of
encoded slashes but because of a bug that I fixed in cc12c9.
  • Loading branch information
FrostyX authored and praiskup committed Jul 9, 2024
1 parent 0bf5ff7 commit 160a1da
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions backend/copr_backend/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import tomllib
import requests
from six.moves.urllib.parse import urlencode


class PulpClient:
Expand Down Expand Up @@ -91,7 +92,7 @@ def get_repository(self, name):
# There is no endpoint for querying a single repository by its name,
# even Pulp CLI does this workaround
url = self.url("api/v3/repositories/rpm/rpm/?")
url += self._urlencode({"name": name, "offset": 0, "limit": 1})
url += urlencode({"name": name, "offset": 0, "limit": 1})
return requests.get(url, **self.request_params)

def get_distribution(self, name):
Expand All @@ -102,7 +103,7 @@ def get_distribution(self, name):
# There is no endpoint for querying a single repository by its name,
# even Pulp CLI does this workaround
url = self.url("api/v3/distributions/rpm/rpm/?")
url += self._urlencode({"name": name, "offset": 0, "limit": 1})
url += urlencode({"name": name, "offset": 0, "limit": 1})
return requests.get(url, **self.request_params)

def get_task(self, task):
Expand All @@ -111,15 +112,6 @@ def get_task(self, task):
"""
url = self.config["base_url"] + task
return requests.get(url, **self.request_params)
def _urlencode(self, query):
"""
Join a dict into URL query string but don't encode special characters
https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
Our repository names are e.g. frostyx/test-pulp/fedora-39-x86_64.
The standard urlencode would change the slashes to %2F making Pulp to
not find the project when filtering by name.
"""
return "&".join([f"{k}={v}" for k, v in query.items()])

def create_distribution(self, name, repository, basepath=None):
"""
Expand Down

0 comments on commit 160a1da

Please sign in to comment.