Commit 896b13b9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor splitting container image full path

[ci skip]
parent 95e2c019
class ContainerImage < ActiveRecord::Base class ContainerImage < ActiveRecord::Base
include Routable
belongs_to :project belongs_to :project
delegate :container_registry, to: :project delegate :container_registry, to: :project
...@@ -45,14 +43,13 @@ class ContainerImage < ActiveRecord::Base ...@@ -45,14 +43,13 @@ class ContainerImage < ActiveRecord::Base
end end
end end
# rubocop:disable RedundantReturn def self.from_path(full_path)
return unless full_path.include?('/')
def self.split_namespace(full_path) path = full_path[0...full_path.rindex('/')]
image_name = full_path.split('/').last name = full_path[full_path.rindex('/')+1..-1]
namespace = full_path.gsub(/(.*)(#{Regexp.escape('/' + image_name)})/, '\1') project = Project.find_by_full_path(path)
if namespace.count('/') < 1
namespace, image_name = full_path, "" self.new(name: name, path: path, project: project)
end
return namespace, image_name
end end
end end
...@@ -62,12 +62,7 @@ module Auth ...@@ -62,12 +62,7 @@ module Auth
end end
def process_repository_access(type, name, actions) def process_repository_access(type, name, actions)
# Strips image name due to lack of requested_project = ContainerImage.from_path(name).project
# per image authentication.
# Removes only last occurence in light
# of future nested groups
namespace, a = ContainerImage::split_namespace(name)
requested_project = Project.find_by_full_path(namespace)
return unless requested_project return unless requested_project
actions = actions.select do |action| actions = actions.select do |action|
......
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