Skip to content

Commit

Permalink
package release deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ImShyMike committed Jan 28, 2025
1 parent c10be40 commit 94f1a84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eryx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version of the package."""

CURRENT_VERSION = "0.5.1"
CURRENT_VERSION = "0.5.2"
9 changes: 8 additions & 1 deletion eryx/packages/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ def delete_package(package: str, server: str) -> None:

key = get_key(server)

package_name, version = package.split("@") if "@" in package else (package, None)

while True:
answer = input(
f"Are you sure you want to delete '{package}'\n"
Expand All @@ -391,10 +393,15 @@ def delete_package(package: str, server: str) -> None:

try:
response = None
payload = (
{"package": package_name}
if not version
else {"package": package_name, "version": version}
)
response = requests.post(
f"{server}/api/delete",
headers={"X-API-Key": str(key), "Content-Type": "application/json"},
data=json.dumps({"package": package}).encode("utf-8"),
data=json.dumps(payload).encode("utf-8"),
timeout=5,
)
response.raise_for_status()
Expand Down
18 changes: 18 additions & 0 deletions package-index/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def delete_package():
return jsonify({"error": "Missing JSON data"}), 400

package = json_data.get("package")
version = json_data.get("version")
api_key = request.headers.get("X-API-Key")

if not api_key:
Expand All @@ -484,6 +485,23 @@ def delete_package():
if (not package.author_id == user.id) and (not user.is_admin):
return jsonify({"error": "You are not the owner of this package"}), 403

if version:
release = get_release_by_version(package.id, version)
if not release:
return jsonify({"error": "Release not found"}), 404

db.session.delete(release)
db.session.commit()

try:
client.remove_object(PACKAGES_BUCKET, release.file_path)
except S3Error as e:
print("Failed to delete file", e)
return jsonify({"error": "Failed to delete package"}), 500

return jsonify({"message": "Release deleted successfully"}), 200

# If version is not specified
for release in package.releases.all():
db.session.delete(release)
try:
Expand Down

0 comments on commit 94f1a84

Please sign in to comment.