made it so anyone can upload packages (who has permission)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
match response.status_code:
|
||||
case 401:
|
||||
console.print("[b red]digpkg: failed to publish mineral: authentication failed[/]")
|
||||
sys.exit(1)
|
||||
elif response.status_code == 400:
|
||||
case 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:
|
||||
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![/]")
|
||||
|
||||
"""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![/]")"""
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user