summaryrefslogtreecommitdiff
path: root/lib/api/container_repositories.rb
blob: f2dd1fa21fd24b4b47fdf347ddacf6b3c33d67eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

module API
  class ContainerRepositories < ::API::Base
    include Gitlab::Utils::StrongMemoize
    include ::API::Helpers::ContainerRegistryHelpers

    helpers ::API::Helpers::PackagesHelpers

    before { authenticate! }

    feature_category :container_registry
    urgency :low

    namespace 'registry' do
      params do
        requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
      end
      resource :repositories, requirements: { id: /[0-9]*/ } do
        desc 'Get a container repository' do
          detail 'This feature was introduced in GitLab 13.6.'
          success Entities::ContainerRegistry::Repository
        end
        params do
          optional :tags, type: Boolean, default: false, desc: 'Determines if tags should be included'
          optional :tags_count, type: Boolean, default: false, desc: 'Determines if the tags count should be included'
          optional :size, type: Boolean, default: false, desc: 'Determines if the size should be included'
        end
        get ':id' do
          authorize!(:read_container_image, repository)

          present repository,
                  with: Entities::ContainerRegistry::Repository,
                  tags: params[:tags],
                  tags_count: params[:tags_count],
                  size: params[:size],
                  user: current_user
        end
      end
    end

    helpers do
      def repository
        strong_memoize(:repository) do
          ContainerRepository.find(params[:id])
        end
      end
    end
  end
end