diff options
author | Steve Abrams <sabrams@gitlab.com> | 2019-06-18 22:08:30 +0000 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2019-06-18 22:08:30 +0000 |
commit | 34a283f90a56914306f77384e7b54c2dbd2e467a (patch) | |
tree | 022132b6fa8aa927f0e5ac5cc3b1292ec4efe3f9 /lib/api | |
parent | 6fa900547dbd30b0db0070f87dbeb4b05d485b9b (diff) | |
download | gitlab-ce-34a283f90a56914306f77384e7b54c2dbd2e467a.tar.gz |
Add 2nd response for container api bulk delete
The bulk delete api endpoint for container registries can
only be called once per hour. If a user calls the endpoint more
than once per hour, they will now receive a 400 error with a
descriptive message.
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/container_registry.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/api/container_registry.rb b/lib/api/container_registry.rb index 7d9b5e1a598..7dad20a822a 100644 --- a/lib/api/container_registry.rb +++ b/lib/api/container_registry.rb @@ -68,6 +68,9 @@ module API delete ':id/registry/repositories/:repository_id/tags', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do authorize_admin_container_image! + message = 'This request has already been made. You can run this at most once an hour for a given container repository' + render_api_error!(message, 400) unless obtain_new_cleanup_container_lease + CleanupContainerRepositoryWorker.perform_async(current_user.id, repository.id, declared_params.except(:repository_id)) # rubocop: disable CodeReuse/ActiveRecord @@ -123,6 +126,13 @@ module API authorize! :admin_container_image, repository end + def obtain_new_cleanup_container_lease + Gitlab::ExclusiveLease + .new("container_repository:cleanup_tags:#{repository.id}", + timeout: 1.hour) + .try_obtain + end + def repository @repository ||= user_project.container_repositories.find(params[:repository_id]) end |