Change /compose/uploads/delete to /upload/delete
Remove the requirement to pass the compose uuid and the upload uuid -- only the upload uuid is needed.
This commit is contained in:
parent
577c56ebaa
commit
d16e8f5bfc
@ -490,11 +490,19 @@ def uuid_add_upload(cfg, uuid, upload_uuid):
|
||||
if status and status["queue_status"] == "FINISHED":
|
||||
uuid_ready_upload(cfg, uuid, upload_uuid)
|
||||
|
||||
def uuid_remove_upload(cfg, uuid, upload_uuid):
|
||||
uploads = uuid_get_uploads(cfg, uuid) - frozenset((upload_uuid,))
|
||||
with open(_upload_list_path(cfg, uuid), "w") as uploads_file:
|
||||
for upload in uploads:
|
||||
print(upload, file=uploads_file)
|
||||
def uuid_remove_upload(cfg, upload_uuid):
|
||||
for build_uuid in (os.path.basename(b) for b in glob(joinpaths(cfg.get("composer", "lib_dir"), "results/*"))):
|
||||
uploads = uuid_get_uploads(cfg, build_uuid)
|
||||
if upload_uuid not in uploads:
|
||||
continue
|
||||
|
||||
uploads = uploads - frozenset((upload_uuid,))
|
||||
with open(_upload_list_path(cfg, build_uuid), "w") as uploads_file:
|
||||
for upload in uploads:
|
||||
print(upload, file=uploads_file)
|
||||
return
|
||||
|
||||
raise RuntimeError(f"{upload_uuid} is not a valid upload id!")
|
||||
|
||||
def uuid_ready_upload(cfg, uuid, upload_uuid):
|
||||
status = uuid_status(cfg, uuid)
|
||||
|
@ -652,13 +652,13 @@ def v1_compose_uploads_schedule(compose_uuid):
|
||||
return jsonify(status=False, errors=[{"id": UPLOAD_ERROR, "msg": str(e)}]), 400
|
||||
return jsonify(status=True, upload_id=upload_id)
|
||||
|
||||
@v1_api.route("/compose/uploads/delete", defaults={"compose_uuid": "", "upload_uuid": ""}, methods=["DELETE"])
|
||||
@v1_api.route("/compose/uploads/delete/<compose_uuid>/<upload_uuid>", methods=["DELETE"])
|
||||
@checkparams([("compose_uuid", "", "no compose UUID given"), ("upload_uuid", "", "no upload UUID given")])
|
||||
def v1_compose_uploads_delete(compose_uuid, upload_uuid):
|
||||
@v1_api.route("/upload/delete", defaults={"upload_uuid": ""}, methods=["DELETE"])
|
||||
@v1_api.route("/upload/delete/<upload_uuid>", methods=["DELETE"])
|
||||
@checkparams([("upload_uuid", "", "no upload UUID given")])
|
||||
def v1_compose_uploads_delete(upload_uuid):
|
||||
"""Delete an upload and disassociate it from its compose
|
||||
|
||||
**DELETE /api/v1/uploads/delete/<compose_uuid>/<upload_uuid>**
|
||||
**DELETE /api/v1/upload/delete/<upload_uuid>**
|
||||
|
||||
Example response::
|
||||
|
||||
@ -667,15 +667,12 @@ def v1_compose_uploads_delete(compose_uuid, upload_uuid):
|
||||
"upload_id": "572eb0d0-5348-4600-9666-14526ba628bb"
|
||||
}
|
||||
"""
|
||||
if None in (VALID_API_STRING.match(compose_uuid), VALID_API_STRING.match(upload_uuid)):
|
||||
if VALID_API_STRING.match(upload_uuid) is None:
|
||||
error = {"id": INVALID_CHARS, "msg": "Invalid characters in API path"}
|
||||
return jsonify(status=False, errors=[error]), 400
|
||||
|
||||
if not uuid_status(api.config["COMPOSER_CFG"], compose_uuid):
|
||||
error = {"id": UNKNOWN_UUID, "msg": "%s is not a valid build uuid" % compose_uuid}
|
||||
return jsonify(status=False, errors=[error]), 400
|
||||
uuid_remove_upload(api.config["COMPOSER_CFG"], compose_uuid, upload_uuid)
|
||||
try:
|
||||
uuid_remove_upload(api.config["COMPOSER_CFG"], upload_uuid)
|
||||
delete_upload(api.config["COMPOSER_CFG"]["upload"], upload_uuid)
|
||||
except RuntimeError as error:
|
||||
return jsonify(status=False, errors=[{"id": UPLOAD_ERROR, "msg": str(error)}])
|
||||
|
@ -3693,7 +3693,7 @@ class ServerAPIV1TestCase(unittest.TestCase):
|
||||
self.assertTrue(len(data["upload_id"]) > 0)
|
||||
|
||||
# Delete this upload from this compose
|
||||
resp = self.server.delete("/api/v1/compose/uploads/delete/%s/%s" % (build_id, data["upload_id"]))
|
||||
resp = self.server.delete("/api/v1/upload/delete/%s" % data["upload_id"])
|
||||
data = json.loads(resp.data)
|
||||
self.assertNotEqual(data, None)
|
||||
self.assertEqual(data["status"], True, "Failed to delete upload: %s" % data)
|
||||
|
Loading…
Reference in New Issue
Block a user