Skip to content

Commit

Permalink
Refs #37552 - translate container registry errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Jun 12, 2024
1 parent 0bc1605 commit a57bdee
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions app/controllers/katello/api/registry/registry_proxies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def check_blob_push_field_syntax(props)
unless props[:valid_format]
return render_podman_error(
"NAME_INVALID",
"Invalid format. Container pushes should follow 'organization_label/product_label/name' OR 'id/organization_id/product_id/name' schema.",
_("Invalid format. Container pushes should follow 'organization_label/product_label/name' OR 'id/organization_id/product_id/name' schema."),
:bad_request
)
end
Expand All @@ -156,7 +156,7 @@ def check_blob_push_org_label(props)
unless org_label.present? && org_label.length > 0
return render_podman_error(
"NAME_INVALID",
"Invalid format. Organization label cannot be blank.",
_("Invalid format. Organization label cannot be blank."),
:bad_request
)
end
Expand All @@ -173,11 +173,11 @@ def check_blob_push_org_label(props)
unless root_repos.empty?
return render_podman_error(
"NAME_INVALID",
"Due to a change in your organizations, this container name has become "\
_("Due to a change in your organizations, this container name has become "\
"ambiguous (org name '#{org_label}'). If you wish to continue using this "\
"container name, destroy the organization in conflict with '#{o.name} (id "\
"#{o.id}). If you wish to keep both orgs, destroy '#{o.label}/#{prod.label}/"\
"#{root_repos.first.label}' and retry your push using the id format.",
"#{root_repos.first.label}' and retry your push using the id format."),
:conflict
)
end
Expand All @@ -188,14 +188,14 @@ def check_blob_push_org_label(props)
# Otherwise tell them to try pushing with ID format
return render_podman_error(
"NAME_INVALID",
"Organization label '#{org_label}' is ambiguous. Try using an id-based container name.",
_("Organization label '#{org_label}' is ambiguous. Try using an id-based container name."),
:conflict
)
end
if org.length == 0
return render_podman_error(
"NAME_UNKNOWN",
"Organization not found: '#{org_label}'",
_("Organization not found: '#{org_label}'"),
:not_found
)
end
Expand All @@ -208,15 +208,15 @@ def check_blob_push_org_id(props)
unless org_id.present? && org_id == org_id.to_i.to_s
return render_podman_error(
"NAME_INVALID",
"Invalid format. Organization id must be an integer without leading zeros.",
_("Invalid format. Organization id must be an integer without leading zeros."),
:bad_request
)
end
@organization = Organization.find_by_id(org_id.to_i)
if @organization.nil?
return render_podman_error(
"NAME_UNKNOWN",
"Organization id not found: '#{org_id}'",
_("Organization id not found: '#{org_id}'"),
:not_found
)
end
Expand All @@ -228,7 +228,7 @@ def check_blob_push_product_label(props)
unless prod_label.present? && prod_label.length > 0
return render_podman_error(
"NAME_INVALID",
"Invalid format. Product label cannot be blank.",
_("Invalid format. Product label cannot be blank."),
:bad_request
)
end
Expand All @@ -243,11 +243,11 @@ def check_blob_push_product_label(props)
unless root_repos.empty?
return render_podman_error(
"NAME_INVALID",
"Due to a change in your products, this container name has become ambiguous "\
_("Due to a change in your products, this container name has become ambiguous "\
"(product name '#{prod_label}'). If you wish to continue using this container "\
"name, destroy the product in conflict with '#{prod.name}' (id #{prod.id}). If "\
"you wish to keep both products, destroy '#{@organization.label}/#{prod.label}/"\
"#{root_repos.first.label}' and retry your push using the id format.",
"#{root_repos.first.label}' and retry your push using the id format."),
:conflict
)
end
Expand All @@ -256,14 +256,14 @@ def check_blob_push_product_label(props)

return render_podman_error(
"NAME_INVALID",
"Product label '#{prod_label}' is ambiguous. Try using an id-based container name.",
_("Product label '#{prod_label}' is ambiguous. Try using an id-based container name."),
:conflict
)
end
if product.length == 0
return render_podman_error(
"NAME_UNKNOWN",
"Product not found: '#{prod_label}'",
_("Product not found: '#{prod_label}'"),
:not_found
)
end
Expand All @@ -276,15 +276,15 @@ def check_blob_push_product_id(props)
unless prod_id.present? && prod_id == prod_id.to_i.to_s
return render_podman_error(
"NAME_INVALID",
"Invalid format. Product id must be an integer without leading zeros.",
_("Invalid format. Product id must be an integer without leading zeros."),
:bad_request
)
end
@product = @organization.products.find_by_id(prod_id.to_i)
if @product.nil?
return render_podman_error(
"NAME_UNKNOWN",
"Product id not found: '#{prod_id}'",
_("Product id not found: '#{prod_id}'"),
:not_found
)
end
Expand All @@ -303,7 +303,7 @@ def check_blob_push_container(props)
unless props[:name].present? && props[:name].length > 0
return render_podman_error(
"NAME_INVALID",
"Invalid format. Container name cannot be blank.",
_("Invalid format. Container name cannot be blank."),
:bad_request
)
end
Expand All @@ -321,7 +321,7 @@ def check_blob_push_container(props)
if !root_repo.nil? && @container_push_name_format != root_repo.container_push_name_format
return render_podman_error(
"NAME_INVALID",
"Repository name '#{@container_name}' already exists in this product using a different naming scheme. Please retry your request with the #{root_repo.container_push_name_format} format or destroy and recreate the repository using your preferred schema.",
_("Repository name '#{@container_name}' already exists in this product using a different naming scheme. Please retry your request with the #{root_repo.container_push_name_format} format or destroy and recreate the repository using your preferred schema."),
:conflict
)
end
Expand Down Expand Up @@ -362,7 +362,7 @@ def blob_push_cleanup
unless root_repo.present? && instance_repo.present?
return render_podman_error(
"BLOB_UPLOAD_UNKNOWN",
"Could not locate local uploaded repository for content indexing.",
_("Could not locate local uploaded repository for content indexing."),
:not_found
)
end
Expand All @@ -379,15 +379,15 @@ def blob_push_cleanup
if latest_version_href.empty? || pulp_repo_href.empty?
return render_podman_error(
"BLOB_UPLOAD_UNKNOWN",
"Could not locate repository properties for content indexing.",
_("Could not locate repository properties for content indexing."),
:not_found
)
end

if pulp_distribution_href.empty?
return render_podman_error(
"BLOB_UPLOAD_UNKNOWN",
"Could not locate Pulp distribution.",
_("Could not locate Pulp distribution."),
:not_found
)
end
Expand Down Expand Up @@ -749,7 +749,7 @@ def confirm_push_settings
return true if SETTINGS.dig(:katello, :container_image_registry, :allow_push)
render_podman_error(
"UNSUPPORTED",
"Registry push is not enabled. To enable, add ':katello:'->':container_image_registry:'->':allow_push: true' in the katello settings file.",
_("Registry push is not enabled. To enable, add ':katello:'->':container_image_registry:'->':allow_push: true' in the katello settings file."),
:unprocessable_entity
)
end
Expand Down Expand Up @@ -785,7 +785,7 @@ def render_podman_error(code, message, status = :bad_request)
end

def item_not_found(item)
render_podman_error("NAME_UNKNOWN", "#{item} was not found!", :not_found)
render_podman_error("NAME_UNKNOWN", _("#{item} was not found!"), :not_found)
end
end
end

0 comments on commit a57bdee

Please sign in to comment.