From 49ddb312dea5d298952ad460922ed3f518677214 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Thu, 11 Aug 2022 19:07:54 +0200 Subject: [PATCH] feat(server): added endpoint to remove package from arch-repo --- docs/api/source/includes/_repository.md | 29 +++++++++++++++++++++++++ src/repo/repo.v | 2 +- src/server/routes.v | 23 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/docs/api/source/includes/_repository.md b/docs/api/source/includes/_repository.md index fbbc329..9764e01 100644 --- a/docs/api/source/includes/_repository.md +++ b/docs/api/source/includes/_repository.md @@ -93,3 +93,32 @@ other already present arch-repos. Parameter | Description --------- | ----------- repo | Repository to publish package to + +## Remove package from arch-repo + + + +```shell +curl \ + -H 'X-Api-Key: secret' \ + -XDELETE \ + https://example.com/vieter/x86_64/mike +``` + +This endpoint allows you to remove a package from a given arch-repo. + +### HTTP Request + +`DELETE /:repo/:arch/:pkg` + +### URL Parameters + +Parameter | Description +--------- | ----------- +repo | Repository to delete package from +arch | Specific arch-repo to remove package from +pkg | Name of package to remove (without any version information) diff --git a/src/repo/repo.v b/src/repo/repo.v index c4b85c0..7de12cd 100644 --- a/src/repo/repo.v +++ b/src/repo/repo.v @@ -158,7 +158,7 @@ fn (r &RepoGroupManager) add_pkg_in_arch_repo(repo string, arch string, pkg &pac // remove_pkg_from_arch_repo removes a package from an arch-repo's database. It // returns false if the package wasn't present in the database. It also // optionally re-syncs the repo archives. -fn (r &RepoGroupManager) remove_pkg_from_arch_repo(repo string, arch string, pkg_name string, sync bool) ?bool { +pub fn (r &RepoGroupManager) remove_pkg_from_arch_repo(repo string, arch string, pkg_name string, sync bool) ?bool { repo_dir := os.join_path(r.repos_dir, repo, arch) // If the repository doesn't exist yet, the result is automatically false diff --git a/src/server/routes.v b/src/server/routes.v index fbf37df..3b86e20 100644 --- a/src/server/routes.v +++ b/src/server/routes.v @@ -57,6 +57,29 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re return app.file(full_path) } +['/:repo/:arch/:pkg'; delete] +fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result { + if !app.is_authorized() { + return app.json(http.Status.unauthorized, new_response('Unauthorized.')) + } + + res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or { + app.lerror('Error while deleting package: $err.msg()') + + return app.json(http.Status.internal_server_error, new_response('Failed to delete package.')) + } + + if res { + app.linfo("Removed package '$pkg' from '$repo/$arch'") + + return app.json(http.Status.ok, new_response('Package removed.')) + } else { + app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.") + + return app.json(http.Status.not_found, new_response('Package not found.')) + } +} + // put_package handles publishing a package to a repository. ['/:repo/publish'; post] fn (mut app App) put_package(repo string) web.Result {