app/controllers/katello/api/v2/repositories_controller.rb in katello-3.12.3 vs app/controllers/katello/api/v2/repositories_controller.rb in katello-3.13.0.rc1
- old
+ new
@@ -1,10 +1,10 @@
module Katello
class Api::V2::RepositoriesController < Api::V2::ApiController # rubocop:disable Metrics/ClassLength
include Katello::Concerns::FilteredAutoCompleteSearch
- wrap_parameters :repository, :include => RootRepository.attribute_names
+ wrap_parameters :repository, :include => RootRepository.attribute_names.concat([:ignore_global_proxy])
CONTENT_CREDENTIAL_GPG_KEY_TYPE = "gpg_key".freeze
CONTENT_CREDENTIAL_SSL_CA_CERT_TYPE = "ssl_ca_cert".freeze
CONTENT_CREDENTIAL_SSL_CLIENT_CERT_TYPE = "ssl_client_cert".freeze
CONTENT_CREDENTIAL_SSL_CLIENT_KEY_TYPE = "ssl_client_key".freeze
@@ -22,11 +22,11 @@
before_action :error_on_rh_repo, :only => [:destroy]
before_action(:only => [:create, :update]) { find_content_credential CONTENT_CREDENTIAL_GPG_KEY_TYPE }
before_action(:only => [:create, :update]) { find_content_credential CONTENT_CREDENTIAL_SSL_CA_CERT_TYPE }
before_action(:only => [:create, :update]) { find_content_credential CONTENT_CREDENTIAL_SSL_CLIENT_CERT_TYPE }
before_action(:only => [:create, :update]) { find_content_credential CONTENT_CREDENTIAL_SSL_CLIENT_KEY_TYPE }
-
+ before_action :check_ignore_global_proxy, :only => [ :update, :create ]
skip_before_action :authorize, :only => [:gpg_key_content]
skip_before_action :check_content_type, :only => [:upload_content]
def custom_index_relation(collection)
collection.includes(:product)
@@ -50,12 +50,15 @@
param :ostree_upstream_sync_policy, ::Katello::RootRepository::OSTREE_UPSTREAM_SYNC_POLICIES, :desc => N_("policies for syncing upstream ostree repositories")
param :ostree_upstream_sync_depth, :number, :desc => N_("if a custom sync policy is chosen for ostree repositories then a 'depth' value must be provided")
param :deb_releases, String, :desc => N_("comma separated list of releases to be synched from deb-archive")
param :deb_components, String, :desc => N_("comma separated list of repo components to be synched from deb-archive")
param :deb_architectures, String, :desc => N_("comma separated list of architectures to be synched from deb-archive")
- param :ignore_global_proxy, :bool, :desc => N_("if true, will ignore the globally configured proxy when syncing")
+ param :ignore_global_proxy, :bool, :desc => N_("if true, will ignore the globally configured proxy when syncing"), :deprecated => true
param :ignorable_content, Array, :desc => N_("List of content units to ignore while syncing a yum repository. Must be subset of %s") % RootRepository::IGNORABLE_CONTENT_UNIT_TYPES.join(",")
+ param :ansible_collection_whitelist, String, :desc => N_("Name of collection to sync from URL")
+ param :http_proxy_policy, ::Katello::RootRepository::HTTP_PROXY_POLICIES, :desc => N_("policies for http proxy for content sync")
+ param :http_proxy_id, :number, :desc => N_("ID of a HTTP Proxy")
end
def_param_group :repo_create do
param :label, String, :required => false
param :product_id, :number, :required => true, :desc => N_("Product the repository belongs to")
@@ -75,19 +78,22 @@
param :content_view_version_id, :number, :desc => N_("ID of a content view version to show repositories in")
param :deb_id, String, :desc => N_("Id of a deb package to find repositories that contain the deb")
param :erratum_id, String, :desc => N_("Id of an erratum to find repositories that contain the erratum")
param :rpm_id, String, :desc => N_("Id of a rpm package to find repositories that contain the rpm")
param :file_id, String, :desc => N_("Id of a file to find repositories that contain the file")
+ param :ansible_collection_id, String, :desc => N_("Id of an ansible collection to find repositories that contain the ansible collection")
param :ostree_branch_id, String, :desc => N_("Id of an ostree branch to find repositories that contain that branch")
param :library, :bool, :desc => N_("show repositories in Library and the default content view")
+ param :archived, :bool, :desc => N_("show archived repositories")
param :content_type, RepositoryTypeManager.repository_types.keys, :desc => N_("limit to only repositories of this type")
param :name, String, :desc => N_("name of the repository"), :required => false
param :label, String, :desc => N_("label of the repository"), :required => false
param :description, String, :desc => N_("description of the repository")
param :available_for, String, :desc => N_("interpret specified object to return only Repositories that can be associated with specified object. Only 'content_view' & 'content_view_version' are supported."),
:required => false
param_group :search, Api::V2::ApiController
+ add_scoped_search_description_for(Repository)
def index
base_args = [index_relation.distinct, :name, :asc]
options = {:includes => [:environment, {:root => [:gpg_key, :product]}]}
respond_to do |format|
@@ -130,10 +136,11 @@
end
def index_relation_content_view(query)
if params[:content_view_version_id]
query = query.where(:content_view_version_id => params[:content_view_version_id])
+ query = query.archived if ::Foreman::Cast.to_bool params[:archived]
query = Katello::Repository.where(:id => query.select(:library_instance_id)) if params[:library]
elsif params[:content_view_id]
query = filter_by_content_view(query, params[:content_view_id], params[:environment_id], params[:available_for] == 'content_view')
end
query
@@ -178,10 +185,15 @@
if params[:file_id]
query = query.joins(:files)
.where("#{FileUnit.table_name}.id" => FileUnit.with_identifiers(params[:file_id]))
end
+ if params[:ansible_collection_id]
+ query = query.joins(:ansible_collections)
+ .where("#{AnsibleCollection.table_name}.id" => AnsibleCollection.with_identifiers(params[:ansible_collection_id]))
+ end
+
if params[:ostree_branch_id]
query = query.joins(:ostree_branches)
.where("#{OstreeBranch.table_name}.id" => OstreeBranch.with_identifiers(params[:ostree_branch_id]))
end
@@ -308,10 +320,11 @@
param :id, :number, :required => true, :desc => N_("repository ID")
param :name, String, :required => false
param_group :repo
def update
repo_params = repository_params
+
sync_task(::Actions::Katello::Repository::Update, @repository.root, repo_params)
respond_for_show(:resource => @repository)
end
api :DELETE, "/repositories/:id", N_("Destroy a custom repository")
@@ -326,29 +339,31 @@
api :PUT, "/repositories/:id/remove_puppet_modules"
api :PUT, "/repositories/:id/remove_content"
desc "Remove content from a repository"
param :id, :number, :required => true, :desc => "repository ID"
param 'ids', Array, :required => true, :desc => "Array of content ids to remove"
+ param :content_type, RepositoryTypeManager.removable_content_types.map(&:label), :required => false, :desc => N_("content type ('deb', 'docker_manifest', 'file', 'ostree', 'puppet_module', 'rpm', 'srpm')")
param 'sync_capsule', :bool, :desc => N_("Whether or not to sync an external capsule after upload. Default: true")
def remove_content
sync_capsule = ::Foreman::Cast.to_bool(params.fetch(:sync_capsule, true))
fail _("No content ids provided") if @content.blank?
- respond_for_async :resource => sync_task(::Actions::Katello::Repository::RemoveContent, @repository, @content, sync_capsule: sync_capsule)
+ respond_for_async :resource => sync_task(::Actions::Katello::Repository::RemoveContent, @repository, @content, content_type: params[:content_type], sync_capsule: sync_capsule)
end
api :POST, "/repositories/:id/upload_content", N_("Upload content into the repository")
param :id, :number, :required => true, :desc => N_("repository ID")
param :content, File, :required => true, :desc => N_("Content files to upload. Can be a single file or array of files.")
+ param :content_type, RepositoryTypeManager.uploadable_content_types.map(&:label), :required => false, :desc => N_("content type ('deb', 'docker_manifest', 'file', 'ostree', 'puppet_module', 'rpm', 'srpm')")
def upload_content
fail Katello::Errors::InvalidRepositoryContent, _("Cannot upload Container Image content.") if @repository.docker?
filepaths = Array.wrap(params[:content]).compact.collect do |content|
{path: content.path, filename: content.original_filename}
end
if !filepaths.blank?
- sync_task(::Actions::Katello::Repository::UploadFiles, @repository, filepaths)
+ sync_task(::Actions::Katello::Repository::UploadFiles, @repository, filepaths, params[:content_type])
render :json => {:status => "success", :filenames => filepaths.map { |item| item[:filename] }}
else
fail HttpErrors::BadRequest, _("No file uploaded")
end
rescue Katello::Errors::InvalidRepositoryContent => error
@@ -365,10 +380,11 @@
param :id, :number, :required => true, :desc => N_("Repository id")
param :upload_ids, Array, :desc => N_("Array of upload ids to import"), :deprecated => true
param :async, :bool, desc: N_("Do not wait for the ImportUpload action to finish. Default: false")
param 'publish_repository', :bool, :desc => N_("Whether or not to regenerate the repository on disk. Default: true")
param 'sync_capsule', :bool, :desc => N_("Whether or not to sync an external capsule after upload. Default: true")
+ param :content_type, RepositoryTypeManager.uploadable_content_types.map(&:label), :required => false, :desc => N_("content type ('deb', 'docker_manifest', 'file', 'ostree', 'puppet_module', 'rpm', 'srpm')")
param :uploads, Array, :desc => N_("Array of uploads to import") do
param 'id', String, :required => true
param 'size', String
param 'checksum', String
param 'name', String, :desc => N_("Needs to only be set for file repositories or docker tags")
@@ -393,11 +409,11 @@
begin
respond_for_async(resource: send(
async ? :async_task : :sync_task,
::Actions::Katello::Repository::ImportUpload, @repository, uploads,
- generate_metadata: generate_metadata, sync_capsule: sync_capsule))
+ generate_metadata: generate_metadata, sync_capsule: sync_capsule, content_type: params[:content_type]))
rescue => e
raise HttpErrors::BadRequest, e.message
end
end
@@ -442,23 +458,36 @@
end
end
def repository_params
keys = [:download_policy, :mirror_on_sync, :arch, :verify_ssl_on_sync, :upstream_password, :upstream_username,
- :ostree_upstream_sync_depth, :ostree_upstream_sync_policy, :ignore_global_proxy,
- :deb_releases, :deb_components, :deb_architectures, :description, {:ignorable_content => []}
+ :ostree_upstream_sync_depth, :ostree_upstream_sync_policy,
+ :deb_releases, :deb_components, :deb_architectures, :description, :http_proxy_policy, :http_proxy_id,
+ {:ignorable_content => []}
]
keys += [{:docker_tags_whitelist => []}, :docker_upstream_name] if params[:action] == 'create' || @repository&.docker?
+ keys += [:ansible_collection_whitelist] if params[:action] == 'create' || @repository&.ansible_collection?
keys += [:label, :content_type] if params[:action] == "create"
if params[:action] == 'create' || @repository.custom?
keys += [:url, :gpg_key_id, :ssl_ca_cert_id, :ssl_client_cert_id, :ssl_client_key_id, :unprotected, :name,
:checksum_type]
end
params.require(:repository).permit(*keys).to_h.with_indifferent_access
end
+ def check_ignore_global_proxy
+ if params.key?(:ignore_global_proxy)
+ ::Foreman::Deprecation.api_deprecation_warning("The parameter ignore_global_proxy will be removed in a future Katello release. Please update to use the http_proxy_policy parameter.")
+ if ::Foreman::Cast.to_bool(params[:ignore_global_proxy])
+ params[:repository][:http_proxy_policy] = RootRepository::NO_DEFAULT_HTTP_PROXY
+ else
+ params[:repository][:http_proxy_policy] = RootRepository::GLOBAL_DEFAULT_HTTP_PROXY
+ end
+ end
+ end
+
def get_content_credential(repo_params, content_type)
credential_value = @product.send(content_type)
unless repo_params["#{content_type}_id".to_sym].blank?
credential_value = instance_variable_get("@#{content_type}")
@@ -469,19 +498,21 @@
# rubocop:disable Metrics/CyclomaticComplexity
def construct_repo_from_params(repo_params)
root = @product.add_repo(repo_params.slice(:label, :name, :description, :url, :content_type, :arch, :unprotected,
:gpg_key, :ssl_ca_cert, :ssl_client_cert, :ssl_client_key,
- :checksum_type, :download_policy).to_h.with_indifferent_access)
+ :checksum_type, :download_policy, :http_proxy_policy).to_h.with_indifferent_access)
root.docker_upstream_name = repo_params[:docker_upstream_name] if repo_params[:docker_upstream_name]
root.docker_tags_whitelist = repo_params.fetch(:docker_tags_whitelist, []) if root.docker?
root.mirror_on_sync = ::Foreman::Cast.to_bool(repo_params[:mirror_on_sync]) if repo_params.key?(:mirror_on_sync)
- root.ignore_global_proxy = ::Foreman::Cast.to_bool(repo_params[:ignore_global_proxy]) if repo_params.key?(:ignore_global_proxy)
root.verify_ssl_on_sync = ::Foreman::Cast.to_bool(repo_params[:verify_ssl_on_sync]) if repo_params.key?(:verify_ssl_on_sync)
root.upstream_username = repo_params[:upstream_username] if repo_params.key?(:upstream_username)
root.upstream_password = repo_params[:upstream_password] if repo_params.key?(:upstream_password)
root.ignorable_content = repo_params[:ignorable_content] if root.yum? && repo_params.key?(:ignorable_content)
+ root.ansible_collection_whitelist = repo_params[:ansible_collection_whitelist] if root.ansible_collection?
+ root.http_proxy_policy = repo_params[:http_proxy_policy] if repo_params.key?(:http_proxy_policy)
+ root.http_proxy_id = repo_params[:http_proxy_id] if repo_params.key?(:http_proxy_id)
if root.ostree?
root.ostree_upstream_sync_policy = repo_params[:ostree_upstream_sync_policy]
root.ostree_upstream_sync_depth = repo_params[:ostree_upstream_sync_depth]
end
@@ -510,10 +541,14 @@
def find_organization_from_product
@organization = @product.organization
end
def find_content
- @content = @repository.units_for_removal(params[:ids])
+ if params[:content_type]
+ @content = @repository.units_for_removal(params[:ids], params[:content_type])
+ else
+ @content = @repository.units_for_removal(params[:ids])
+ end
end
def filter_by_content_view(query, content_view_id, environment_id, is_available_for)
if is_available_for
params[:library] = true