Commit 95e2c019 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Clean code related to accessing registry from project

[ci skip]
parent 29c34267
...@@ -3,36 +3,16 @@ class ContainerImage < ActiveRecord::Base ...@@ -3,36 +3,16 @@ class ContainerImage < ActiveRecord::Base
belongs_to :project belongs_to :project
delegate :container_registry, :container_registry_allowed_paths, delegate :container_registry, to: :project
:container_registry_path_with_namespace, to: :project
delegate :client, to: :container_registry delegate :client, to: :container_registry
validates :manifest, presence: true validates :manifest, presence: true
before_destroy :delete_tags before_destroy :delete_tags
before_validation :update_token, on: :create def registry
def update_token # TODO, container registry with image access level
paths = container_registry_allowed_paths << name_with_namespace token = Auth::ContainerRegistryAuthenticationService.image_token(self)
token = Auth::ContainerRegistryAuthenticationService.full_access_token(paths)
client.update_token(token)
end
def parent
project
end
def parent_changed?
project_id_changed?
end
# def path
# [container_registry.path, name_with_namespace].compact.join('/')
# end
def name_with_namespace
[container_registry_path_with_namespace, name].reject(&:blank?).join('/')
end end
def tag(tag) def tag(tag)
......
...@@ -405,29 +405,23 @@ class Project < ActiveRecord::Base ...@@ -405,29 +405,23 @@ class Project < ActiveRecord::Base
@repository ||= Repository.new(path_with_namespace, self) @repository ||= Repository.new(path_with_namespace, self)
end end
def container_registry_path_with_namespace
path_with_namespace.downcase
end
def container_registry_allowed_paths
@container_registry_allowed_paths ||= [container_registry_path_with_namespace] +
container_images.map { |i| i.name_with_namespace }
end
def container_registry def container_registry
return unless Gitlab.config.registry.enabled return unless Gitlab.config.registry.enabled
@container_registry ||= begin @container_registry ||= begin
token = Auth::ContainerRegistryAuthenticationService.full_access_token(container_registry_allowed_paths) token = Auth::ContainerRegistryAuthenticationService.full_access_token(project)
url = Gitlab.config.registry.api_url url = Gitlab.config.registry.api_url
host_port = Gitlab.config.registry.host_port host_port = Gitlab.config.registry.host_port
# TODO, move configuration vars into ContainerRegistry::Registry, clean
# this method up afterwards
ContainerRegistry::Registry.new(url, token: token, path: host_port) ContainerRegistry::Registry.new(url, token: token, path: host_port)
end end
end end
def container_registry_url def container_registry_url
if Gitlab.config.registry.enabled if Gitlab.config.registry.enabled
"#{Gitlab.config.registry.host_port}/#{container_registry_path_with_namespace}" "#{Gitlab.config.registry.host_port}/#{path_with_namespace.downcase}"
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment