From 81c33d100fa126accab749d82b9782ce2c72dc49 Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Mon, 19 Jan 2026 06:27:44 +1100 Subject: [PATCH] made it so anyone can upload packages (who has permission) --- src/install.py | 2 +- src/publish.py | 52 ++++++++++++++++++++++++++++++++++++++------------ src/remove.py | 2 +- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/install.py b/src/install.py index 000692b..b3e1dc5 100644 --- a/src/install.py +++ b/src/install.py @@ -35,7 +35,7 @@ def install(args): with console.status("Downloading tarball...", spinner="bouncingBall", spinner_style="blue") as status: while retries_left > 0: # grab the tar ball - response = requests.get(f"https://chookspace.com/api/packages/SpookyDervish/generic/{package_name}/{version}/mineral.tar") + response = requests.get(f"https://chookspace.com/api/packages/ground/generic/{package_name}/{version}/mineral.tar") # check response code for errors if response.status_code == 404: # package doesn't exist diff --git a/src/publish.py b/src/publish.py index eaa25b8..817fdce 100644 --- a/src/publish.py +++ b/src/publish.py @@ -39,8 +39,21 @@ def publish(args): console.print() - with console.status("Compressing...", spinner="bouncingBall", spinner_style="blue") as status: + with console.status("Authenticating...", spinner="bouncingBall", spinner_style="blue") as status: + # check if we have permission to link the package to the repo + repo_perms_request = requests.get( + url=f"https://chookspace.com/api/v1/users/{username}/orgs/ground/permissions", + auth=HTTPBasicAuth(username, password) + ) + if repo_perms_request.status_code == 401: + console.print(f"[b red]digpkg: failed to publish mineral: checking authorization failed: invalid password[/b red]") + sys.exit(1) + elif not repo_perms_request.ok: + console.print(f"[b red]digpkg: failed to publish mineral: checking authorization failed: {repo_perms_request.content.decode()}[/b red]") + sys.exit(1) + # compress to a tar file + console.status("Compressing") f = tempfile.TemporaryFile(mode="wb+") with tarfile.open(fileobj=f, mode="w:gz") as tar_file: tar_file.add(args.folder_path, arcname=os.path.basename(args.folder_path)) @@ -52,22 +65,37 @@ def publish(args): # send the request status.update("Uploading...") response = requests.put( - url=f"https://chookspace.com/api/packages/{username}/generic/{mineral_name}/{version}/mineral.tar", + url=f"https://chookspace.com/api/packages/ground/generic/{mineral_name}/{version}/mineral.tar", data=f, auth=HTTPBasicAuth(username, password) ) f.close() - if response.status_code == 401: - console.print("[b red]digpkg: failed to publish mineral: authentication failed[/]") - sys.exit(1) - elif response.status_code == 400: - console.print("[b red]digpkg: failed to publish mineral: the package name or version number are invalid[/]") - sys.exit(1) - elif response.status_code == 409: - console.print("[b red]digpkg: failed to publish mineral: that version number is already in use[/]") - sys.exit(1) + match response.status_code: + case 401: + console.print("[b red]digpkg: failed to publish mineral: authentication failed[/]") + sys.exit(1) + case 400: + console.print("[b red]digpkg: failed to publish mineral: the package name or version number are invalid[/]") + sys.exit(1) + case 409: + console.print("[b red]digpkg: failed to publish mineral: that version number is already in use[/]") + sys.exit(1) response.raise_for_status() - console.print("[d][:white_check_mark:] Uploaded![/]") \ No newline at end of file + console.print("[d][:white_check_mark:] Uploaded![/]") + + """console.status("Linking tomineral_name repo...") + + print(mineral_name) + link_package_response = requests.post( + url=f"https://chookspace.com/api/v1/packages/ground/general/request/general/link/Digpkg", + auth=HTTPBasicAuth(username, password) + ) + + if not link_package_response.ok: + console.print(f"[b red]digpkg: failed to link to repo: {link_package_response.content.decode()}[/b red]") + sys.exit(1) + + console.print("[d][:white_check_mark:] Linked![/]")""" \ No newline at end of file diff --git a/src/remove.py b/src/remove.py index 9b50663..948540b 100644 --- a/src/remove.py +++ b/src/remove.py @@ -30,7 +30,7 @@ def remove(args): # send the request response = requests.delete( - url=f"https://chookspace.com/api/packages/{username}/generic/{mineral_name}/{version}", + url=f"https://chookspace.com/api/packages/ground/generic/{mineral_name}/{version}", auth=HTTPBasicAuth(username, password) )