diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-29 14:01:48 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-29 14:02:46 +0300 |
commit | 3bfc05be5ee5b0262857febf90fc7e1f17895d4e (patch) | |
tree | 5952d96a2b88cf55c774631d583a845307d3a932 | |
parent | 06bae00365cda6930063b98fde1a9b804f2ae3bc (diff) |
Use container repository path inside auth service
-rw-r--r-- | app/models/container_repository.rb | 7 | ||||
-rw-r--r-- | app/services/auth/container_registry_authentication_service.rb | 12 | ||||
-rw-r--r-- | spec/lib/container_registry/path_spec.rb | 4 |
3 files changed, 10 insertions, 13 deletions
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) diff --git a/spec/lib/container_registry/path_spec.rb b/spec/lib/container_registry/path_spec.rb index a680a0adcb2..6384850eb19 100644 --- a/spec/lib/container_registry/path_spec.rb +++ b/spec/lib/container_registry/path_spec.rb @@ -9,8 +9,8 @@ describe ContainerRegistry::Path do it 'return all project-like components in reverse order' do expect(subject.components).to eq %w[path/to/some/project - path/to/some - path/to] + path/to/some + path/to] end end |