Validates tag names and tags#bulk_destroy
This commit is contained in:
parent
786133d314
commit
c2d1fbe507
|
@ -29,7 +29,16 @@ module Projects
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_destroy
|
def bulk_destroy
|
||||||
|
unless params[:ids].present?
|
||||||
|
head :bad_request
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@tags = (params[:ids] || []).map { |tag_name| image.tag(tag_name) }
|
@tags = (params[:ids] || []).map { |tag_name| image.tag(tag_name) }
|
||||||
|
unless @tags.all? { |tag| tag.valid_name? }
|
||||||
|
head :bad_request
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
success_count = 0
|
success_count = 0
|
||||||
@tags.each do |tag|
|
@tags.each do |tag|
|
||||||
|
|
|
@ -6,6 +6,9 @@ module ContainerRegistry
|
||||||
|
|
||||||
attr_reader :repository, :name
|
attr_reader :repository, :name
|
||||||
|
|
||||||
|
# https://github.com/docker/distribution/commit/3150937b9f2b1b5b096b2634d0e7c44d4a0f89fb
|
||||||
|
TAG_NAME_REGEX = /^[\w][\w.-]{0,127}$/.freeze
|
||||||
|
|
||||||
delegate :registry, :client, to: :repository
|
delegate :registry, :client, to: :repository
|
||||||
delegate :revision, :short_revision, to: :config_blob, allow_nil: true
|
delegate :revision, :short_revision, to: :config_blob, allow_nil: true
|
||||||
|
|
||||||
|
@ -13,6 +16,10 @@ module ContainerRegistry
|
||||||
@repository, @name = repository, name
|
@repository, @name = repository, name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid_name?
|
||||||
|
!name.match(TAG_NAME_REGEX).nil?
|
||||||
|
end
|
||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
manifest.present?
|
manifest.present?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue