Use container repository path inside auth service
This commit is contained in:
parent
06bae00365
commit
3bfc05be5e
3 changed files with 10 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue