From 3bfc05be5ee5b0262857febf90fc7e1f17895d4e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 29 Mar 2017 13:01:48 +0200 Subject: Use container repository path inside auth service --- app/models/container_repository.rb | 7 ------- .../auth/container_registry_authentication_service.rb | 12 ++++++++---- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'app') diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index b128069ca0e..98acf49c939 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -58,11 +58,4 @@ class ContainerRepository < ActiveRecord::Base client.delete_repository_tag(self.path, digest) end end - - # TODO, we will return a new ContainerRepository object here - # - def self.project_from_path(repository_path) - ContainerRegistry::Path.new(repository_path) - .repository_project - end end diff --git a/app/services/auth/container_registry_authentication_service.rb b/app/services/auth/container_registry_authentication_service.rb index 3d151c6a357..7a2ec9664c1 100644 --- a/app/services/auth/container_registry_authentication_service.rb +++ b/app/services/auth/container_registry_authentication_service.rb @@ -56,13 +56,15 @@ module Auth def process_scope(scope) type, name, actions = scope.split(':', 3) actions = actions.split(',') + path = ContainerRegistry::Path.new(name) + return unless type == 'repository' - process_repository_access(type, name, actions) + process_repository_access(type, path, actions) end - def process_repository_access(type, name, actions) - requested_project = ContainerRepository.project_from_path(name) + def process_repository_access(type, path, actions) + requested_project = path.repository_project return unless requested_project @@ -70,7 +72,9 @@ module Auth can_access?(requested_project, action) end - { type: type, name: name, actions: actions } if actions.present? + return unless actions.present? + + { type: type, name: path.to_s, actions: actions } end def can_access?(requested_project, requested_action) -- cgit v1.2.1