feat(server): added endpoint to remove package from arch-repo

main
Jef Roosens 2022-08-11 19:07:54 +02:00
parent 8a2b121cc7
commit 49ddb312de
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 53 additions and 1 deletions

View File

@ -93,3 +93,32 @@ other already present arch-repos.
Parameter | Description Parameter | Description
--------- | ----------- --------- | -----------
repo | Repository to publish package to repo | Repository to publish package to
## Remove package from arch-repo
<aside class="notice">
This endpoint requests authentication.
</aside>
```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)

View File

@ -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 // 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 // returns false if the package wasn't present in the database. It also
// optionally re-syncs the repo archives. // 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) repo_dir := os.join_path(r.repos_dir, repo, arch)
// If the repository doesn't exist yet, the result is automatically false // If the repository doesn't exist yet, the result is automatically false

View File

@ -57,6 +57,29 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re
return app.file(full_path) 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. // put_package handles publishing a package to a repository.
['/:repo/publish'; post] ['/:repo/publish'; post]
fn (mut app App) put_package(repo string) web.Result { fn (mut app App) put_package(repo string) web.Result {