2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-31 07:08:09 -04:00
|
|
|
module Projects
|
|
|
|
module Registry
|
|
|
|
class RepositoriesController < ::Projects::Registry::ApplicationController
|
|
|
|
before_action :authorize_update_container_image!, only: [:destroy]
|
2017-04-03 06:49:54 -04:00
|
|
|
before_action :ensure_root_container_repository!, only: [:index]
|
2017-03-31 07:08:09 -04:00
|
|
|
|
|
|
|
def index
|
2017-09-19 11:38:55 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2020-04-27 20:09:33 -04:00
|
|
|
@images = ContainerRepositoriesFinder.new(user: current_user, subject: project, params: params.slice(:name))
|
|
|
|
.execute
|
2020-01-22 13:08:47 -05:00
|
|
|
|
|
|
|
track_event(:list_repositories)
|
|
|
|
|
2020-02-06 16:08:48 -05:00
|
|
|
serializer = ContainerRepositoriesSerializer
|
2017-09-21 06:21:50 -04:00
|
|
|
.new(project: project, current_user: current_user)
|
2020-02-06 16:08:48 -05:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
render json: serializer.with_pagination(request, response).represent(@images)
|
2017-09-19 11:38:55 -04:00
|
|
|
end
|
|
|
|
end
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
|
|
|
|
2020-02-06 16:08:48 -05:00
|
|
|
# The show action renders index to allow frontend routing to work on page refresh
|
|
|
|
def show
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
|
2017-03-31 07:08:09 -04:00
|
|
|
def destroy
|
2020-04-07 08:09:34 -04:00
|
|
|
image.delete_scheduled!
|
2020-02-14 16:09:08 -05:00
|
|
|
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) # rubocop:disable CodeReuse/Worker
|
2019-10-08 05:06:09 -04:00
|
|
|
track_event(:delete_repository)
|
2018-09-06 02:33:30 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { head :no_content }
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-31 07:56:07 -04:00
|
|
|
private
|
2017-03-31 07:08:09 -04:00
|
|
|
|
|
|
|
def image
|
2017-04-05 08:18:42 -04:00
|
|
|
@image ||= project.container_repositories.find(params[:id])
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
2017-04-03 06:49:54 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Container repository object for root project path.
|
|
|
|
#
|
|
|
|
# Needed to maintain a backwards compatibility.
|
|
|
|
#
|
|
|
|
def ensure_root_container_repository!
|
2018-09-06 02:33:30 -04:00
|
|
|
::ContainerRegistry::Path.new(@project.full_path).tap do |path|
|
2017-04-03 09:53:51 -04:00
|
|
|
break if path.has_repository?
|
2017-04-03 06:49:54 -04:00
|
|
|
|
2018-09-06 02:33:30 -04:00
|
|
|
::ContainerRepository.build_from_path(path).tap do |repository|
|
2017-04-05 08:44:35 -04:00
|
|
|
repository.save! if repository.has_tags?
|
2017-04-03 06:49:54 -04:00
|
|
|
end
|
|
|
|
end
|
2019-07-02 09:12:45 -04:00
|
|
|
rescue ContainerRegistry::Path::InvalidRegistryPathError
|
|
|
|
@character_error = true
|
2017-04-03 06:49:54 -04:00
|
|
|
end
|
2017-03-31 07:08:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|