Commit 3bfc05be authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use container repository path inside auth service

parent 06bae003
...@@ -58,11 +58,4 @@ class ContainerRepository < ActiveRecord::Base ...@@ -58,11 +58,4 @@ class ContainerRepository < ActiveRecord::Base
client.delete_repository_tag(self.path, digest) client.delete_repository_tag(self.path, digest)
end end
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 end
...@@ -56,13 +56,15 @@ module Auth ...@@ -56,13 +56,15 @@ module Auth
def process_scope(scope) def process_scope(scope)
type, name, actions = scope.split(':', 3) type, name, actions = scope.split(':', 3)
actions = actions.split(',') actions = actions.split(',')
path = ContainerRegistry::Path.new(name)
return unless type == 'repository' return unless type == 'repository'
process_repository_access(type, name, actions) process_repository_access(type, path, actions)
end end
def process_repository_access(type, name, actions) def process_repository_access(type, path, actions)
requested_project = ContainerRepository.project_from_path(name) requested_project = path.repository_project
return unless requested_project return unless requested_project
...@@ -70,7 +72,9 @@ module Auth ...@@ -70,7 +72,9 @@ module Auth
can_access?(requested_project, action) can_access?(requested_project, action)
end end
{ type: type, name: name, actions: actions } if actions.present? return unless actions.present?
{ type: type, name: path.to_s, actions: actions }
end end
def can_access?(requested_project, requested_action) def can_access?(requested_project, requested_action)
......
...@@ -9,8 +9,8 @@ describe ContainerRegistry::Path do ...@@ -9,8 +9,8 @@ describe ContainerRegistry::Path do
it 'return all project-like components in reverse order' do it 'return all project-like components in reverse order' do
expect(subject.components).to eq %w[path/to/some/project expect(subject.components).to eq %w[path/to/some/project
path/to/some path/to/some
path/to] path/to]
end end
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