Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: allow to prefix packages with a + #460

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions asu/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rq import Connection, Queue

from .build import build
from .common import get_request_hash
from .common import get_request_hash, remove_prefix

bp = Blueprint("api", __name__, url_prefix="/api")

Expand Down Expand Up @@ -84,7 +84,7 @@ def validate_packages(req):
else:
tr.add(p)

req["packages"] = tr
req["packages"] = list(map(lambda x: remove_prefix(x, "+"), sorted(tr)))

# store request packages temporary in Redis and create a diff
temp = str(uuid4())
Expand Down
15 changes: 15 additions & 0 deletions asu/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,18 @@ def verify_usign(sig_file: Path, msg_file: Path, pub_key: str) -> bool:
return True
except nacl.exceptions.CryptoError:
return False


def remove_prefix(text, prefix):
"""Remove prefix from text

TODO: remove once 3.8 is dropped

Args:
text (str): text to remove prefix from
prefix (str): prefix to remove

Returns:
str: text without prefix
"""
return text[text.startswith(prefix) and len(prefix) :]
6 changes: 6 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ def test_verify_usign():
os.close(sig_fd)
os.unlink(msg_path)
os.unlink(sig_path)


def test_remove_prefix():
assert remove_prefix("test", "test") == ""
assert remove_prefix("+test", "+") == "test"
assert remove_prefix("++test", "+") == "+test"