summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/container_image.rb17
-rw-r--r--app/services/auth/container_registry_authentication_service.rb7
2 files changed, 8 insertions, 16 deletions
diff --git a/app/models/container_image.rb b/app/models/container_image.rb
index 411617ccd71..6e9a060d7a8 100644
--- a/app/models/container_image.rb
+++ b/app/models/container_image.rb
@@ -1,6 +1,4 @@
class ContainerImage < ActiveRecord::Base
- include Routable
-
belongs_to :project
delegate :container_registry, to: :project
@@ -45,14 +43,13 @@ class ContainerImage < ActiveRecord::Base
end
end
- # rubocop:disable RedundantReturn
+ def self.from_path(full_path)
+ return unless full_path.include?('/')
- def self.split_namespace(full_path)
- image_name = full_path.split('/').last
- namespace = full_path.gsub(/(.*)(#{Regexp.escape('/' + image_name)})/, '\1')
- if namespace.count('/') < 1
- namespace, image_name = full_path, ""
- end
- return namespace, image_name
+ path = full_path[0...full_path.rindex('/')]
+ name = full_path[full_path.rindex('/')+1..-1]
+ project = Project.find_by_full_path(path)
+
+ self.new(name: name, path: path, project: project)
end
end
diff --git a/app/services/auth/container_registry_authentication_service.rb b/app/services/auth/container_registry_authentication_service.rb
index a3c8d77bf09..7e412040c7c 100644
--- a/app/services/auth/container_registry_authentication_service.rb
+++ b/app/services/auth/container_registry_authentication_service.rb
@@ -62,12 +62,7 @@ module Auth
end
def process_repository_access(type, name, actions)
- # Strips image name due to lack of
- # 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)
+ requested_project = ContainerImage.from_path(name).project
return unless requested_project
actions = actions.select do |action|