diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-11 21:09:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-11 21:09:46 +0300 |
commit | 5da842297dfad0ce52724aa4fd7f19b1307b7a11 (patch) | |
tree | 24f5a79281ea348ac0a43e462f84d4216b7c60c8 /lib | |
parent | 046d6f52772ada2e08af58627f03bc18e0c932b5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/container_repositories.rb | 2 | ||||
-rw-r--r-- | lib/api/group_container_repositories.rb | 1 | ||||
-rw-r--r-- | lib/api/helpers.rb | 4 | ||||
-rw-r--r-- | lib/api/helpers/container_registry_helpers.rb | 15 | ||||
-rw-r--r-- | lib/api/project_container_repositories.rb | 2 | ||||
-rw-r--r-- | lib/api/repositories.rb | 3 | ||||
-rw-r--r-- | lib/container_registry/client.rb | 9 |
7 files changed, 33 insertions, 3 deletions
diff --git a/lib/api/container_repositories.rb b/lib/api/container_repositories.rb index c84527f26e7..9cd3e449687 100644 --- a/lib/api/container_repositories.rb +++ b/lib/api/container_repositories.rb @@ -3,6 +3,8 @@ module API class ContainerRepositories < ::API::Base include Gitlab::Utils::StrongMemoize + include ::API::Helpers::ContainerRegistryHelpers + helpers ::API::Helpers::PackagesHelpers before { authenticate! } diff --git a/lib/api/group_container_repositories.rb b/lib/api/group_container_repositories.rb index 96175f31696..55e18fd1370 100644 --- a/lib/api/group_container_repositories.rb +++ b/lib/api/group_container_repositories.rb @@ -3,6 +3,7 @@ module API class GroupContainerRepositories < ::API::Base include PaginationParams + include ::API::Helpers::ContainerRegistryHelpers helpers ::API::Helpers::PackagesHelpers diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index ff3590d6c13..f9ba5ba8186 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -430,8 +430,8 @@ module API render_api_error!('406 Not Acceptable', 406) end - def service_unavailable! - render_api_error!('503 Service Unavailable', 503) + def service_unavailable!(message = nil) + render_api_error!(message || '503 Service Unavailable', 503) end def conflict!(message = nil) diff --git a/lib/api/helpers/container_registry_helpers.rb b/lib/api/helpers/container_registry_helpers.rb new file mode 100644 index 00000000000..9c844e364eb --- /dev/null +++ b/lib/api/helpers/container_registry_helpers.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module API + module Helpers + module ContainerRegistryHelpers + extend ActiveSupport::Concern + + included do + rescue_from Faraday::Error, ContainerRegistry::Path::InvalidRegistryPathError do |e| + service_unavailable!('We are having trouble connecting to the Container Registry. If this error persists, please review the troubleshooting documentation.') + end + end + end + end +end diff --git a/lib/api/project_container_repositories.rb b/lib/api/project_container_repositories.rb index 28cfa9e3ae0..82b6082c3fe 100644 --- a/lib/api/project_container_repositories.rb +++ b/lib/api/project_container_repositories.rb @@ -3,6 +3,8 @@ module API class ProjectContainerRepositories < ::API::Base include PaginationParams + include ::API::Helpers::ContainerRegistryHelpers + helpers ::API::Helpers::PackagesHelpers REPOSITORY_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge( diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 3c9255e3117..1aa76906b3d 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -101,6 +101,7 @@ module API params do optional :sha, type: String, desc: 'The commit sha of the archive to be downloaded' optional :format, type: String, desc: 'The archive format' + optional :path, type: String, desc: 'Subfolder of the repository to be downloaded' end get ':id/repository/archive', requirements: { format: Gitlab::PathRegex.archive_formats_regex } do if archive_rate_limit_reached?(current_user, user_project) @@ -109,7 +110,7 @@ module API not_acceptable! if Gitlab::HotlinkingDetector.intercept_hotlinking?(request) - send_git_archive user_project.repository, ref: params[:sha], format: params[:format], append_sha: true + send_git_archive user_project.repository, ref: params[:sha], format: params[:format], append_sha: true, path: params[:path] rescue StandardError not_found!('File') end diff --git a/lib/container_registry/client.rb b/lib/container_registry/client.rb index cc692140301..46399224a5d 100644 --- a/lib/container_registry/client.rb +++ b/lib/container_registry/client.rb @@ -51,6 +51,15 @@ module ContainerRegistry client.supports_tag_delete? end + def self.registry_info + registry_config = Gitlab.config.registry + return unless registry_config.enabled && registry_config.api_url.present? + + token = Auth::ContainerRegistryAuthenticationService.access_token([], []) + client = new(registry_config.api_url, token: token) + client.registry_info + end + def initialize(base_uri, options = {}) @base_uri = base_uri @options = options |