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
belongs_to :project
delegate :container_registry, :container_registry_allowed_paths,
:container_registry_path_with_namespace, to: :project
delegate :container_registry, to: :project
delegate :client, to: :container_registry
validates :manifest, presence: true
before_destroy :delete_tags
before_validation :update_token, on: :create
def update_token
paths = container_registry_allowed_paths << name_with_namespace
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('/')
def registry
# TODO, container registry with image access level
token = Auth::ContainerRegistryAuthenticationService.image_token(self)
end
def tag(tag)
......
......@@ -405,29 +405,23 @@ class Project < ActiveRecord::Base
@repository ||= Repository.new(path_with_namespace, self)
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
return unless Gitlab.config.registry.enabled
@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
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)
end
end
def container_registry_url
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
......
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