diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-09 00:09:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-09 00:09:09 +0300 |
commit | 83fc2f3dc81052cad76addb44726876ba1d0f156 (patch) | |
tree | 1d58eedea14b1462b40bc5b02c9561e5a128ac0b /app/services/update_container_registry_info_service.rb | |
parent | 1d3086ebb41758289c1184dc5ad1462c81e1a1f9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/update_container_registry_info_service.rb')
-rw-r--r-- | app/services/update_container_registry_info_service.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/services/update_container_registry_info_service.rb b/app/services/update_container_registry_info_service.rb new file mode 100644 index 00000000000..531335839a9 --- /dev/null +++ b/app/services/update_container_registry_info_service.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class UpdateContainerRegistryInfoService + def execute + registry_config = Gitlab.config.registry + return unless registry_config.enabled && registry_config.api_url.presence + + # registry_info will query the /v2 route of the registry API. This route + # requires authentication, but not authorization (the response has no body, + # only headers that show the version of the registry). There might be no + # associated user when running this (e.g. from a rake task or a cron job), + # so we need to generate a valid JWT token with no access permissions to + # authenticate as a trusted client. + token = Auth::ContainerRegistryAuthenticationService.access_token([], []) + client = ContainerRegistry::Client.new(registry_config.api_url, token: token) + info = client.registry_info + + Gitlab::CurrentSettings.update!( + container_registry_vendor: info[:vendor] || '', + container_registry_version: info[:version] || '', + container_registry_features: info[:features] || [] + ) + end +end |