Skip to content

Commit

Permalink
backend: add support for pulp domains
Browse files Browse the repository at this point in the history
The pulp.stage.devshift.net instance has domains enabled while our STG
instance has them disabled. As long as it is easy to support both
cases, I'd do that.
  • Loading branch information
FrostyX committed Jun 24, 2024
1 parent 06d270a commit a5d1d5b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/copr_backend/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ def url(self, endpoint):
"""
A fully qualified URL for a given API endpoint
"""
return self.config["base_url"] + self.config["api_root"] + endpoint
domain = self.config["domain"]
if domain == "default":
domain = ""

relative = os.path.normpath("/".join([
self.config["api_root"],
domain,
endpoint,
]))

# Normpath removes the trailing slash. If it was there, put it back
if endpoint[-1] == "/":
relative += "/"
return self.config["base_url"] + relative

@property
def request_params(self):
Expand Down
37 changes: 37 additions & 0 deletions backend/tests/test_pulp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Test Pulp client
"""

from copr_backend.pulp import PulpClient


class TestPulp:

def setup_method(self, _method):
self.config = {
"api_root": "/pulp/",
"base_url": "http://pulp.fpo:24817",
"cert": "",
"domain": "default",
"dry_run": False,
"format": "json",
"key": "",
"password": "1234",
"timeout": 0,
"username": "admin",
"verbose": 0,
"verify_ssl": True,
}

def test_url(self):
client = PulpClient(self.config)
assert self.config["domain"] == "default"
assert client.url("api/v3/artifacts/")\
== "http://pulp.fpo:24817/pulp/api/v3/artifacts/"

assert client.url("api/v3/repositories/rpm/rpm/?")\
== "http://pulp.fpo:24817/pulp/api/v3/repositories/rpm/rpm/?"

self.config["domain"] = "copr"
assert client.url("api/v3/artifacts/")\
== "http://pulp.fpo:24817/pulp/copr/api/v3/artifacts/"

0 comments on commit a5d1d5b

Please sign in to comment.