app/controllers/katello/api/v2/repositories_controller.rb in katello-4.3.0.rc4 vs app/controllers/katello/api/v2/repositories_controller.rb in katello-4.3.0

- old
+ new

@@ -5,11 +5,11 @@ generic_repo_wrap_params = [] RepositoryTypeManager.generic_remote_options(defined_only: true).each do |option| generic_repo_wrap_params << option.name end - repo_wrap_params = RootRepository.attribute_names.concat([:ignore_global_proxy]) + generic_repo_wrap_params + repo_wrap_params = RootRepository.attribute_names.concat([:ignore_global_proxy, :mirror_on_sync]) + generic_repo_wrap_params wrap_parameters :repository, :include => repo_wrap_params CONTENT_CREDENTIAL_GPG_KEY_TYPE = "gpg_key".freeze CONTENT_CREDENTIAL_SSL_CA_CERT_TYPE = "ssl_ca_cert".freeze @@ -51,11 +51,12 @@ param :checksum_type, String, :desc => N_("Checksum of the repository, currently 'sha1' & 'sha256' are supported") param :docker_upstream_name, String, :desc => N_("Name of the upstream docker repository") param :docker_tags_whitelist, Array, :desc => N_("Comma-separated list of tags to sync for Container Image repository") param :download_policy, ["immediate", "on_demand"], :desc => N_("download policy for yum repos (either 'immediate' or 'on_demand')") param :download_concurrency, :number, :desc => N_("Used to determine download concurrency of the repository in pulp3. Use value less than 20. Defaults to 10") - param :mirror_on_sync, :bool, :desc => N_("true if this repository when synced has to be mirrored from the source and stale rpms removed") + param :mirror_on_sync, :bool, :desc => N_("true if this repository when synced has to be mirrored from the source and stale rpms removed (Deprecated)") + param :mirroring_policy, Katello::RootRepository::MIRRORING_POLICIES, :desc => N_("Policy to set for mirroring content. Must be one of %s.") % RootRepository::MIRRORING_POLICIES param :verify_ssl_on_sync, :bool, :desc => N_("if true, Katello will verify the upstream url's SSL certifcates are signed by a trusted CA") param :upstream_username, String, :desc => N_("Username of the upstream repository user used for authentication") param :upstream_password, String, :desc => N_("Password of the upstream repository user used for authentication") param :upstream_authentication_token, String, :desc => N_("Password of the upstream authentication token.") param :deb_releases, String, :desc => N_("whitespace-separated list of releases to be synced from deb-archive") @@ -266,11 +267,11 @@ render :json => repo_types.values end api :PUT, "/repositories/:id/republish", N_("Forces a republish of the specified repository, regenerating metadata and symlinks on the filesystem.") param :id, :number, :desc => N_("Repository identifier"), :required => true - param :force, :bool, :desc => N_("Force metadata regeneration to proceed. Dangerous when repositories use mirror on sync."), :required => true + param :force, :bool, :desc => N_("Force metadata regeneration to proceed. Dangerous when repositories use the 'Complete Mirroring' mirroring policy."), :required => true def republish unless ::Foreman::Cast.to_bool(params[:force]) fail HttpErrors::BadRequest, _('Metadata republishing must be forced because it is a dangerous operation.') end task = async_task(::Actions::Katello::Repository::MetadataGenerate, @repository) @@ -499,11 +500,11 @@ end end # rubocop:disable Metrics/CyclomaticComplexity def repository_params - keys = [:download_policy, :mirror_on_sync, :arch, :verify_ssl_on_sync, :upstream_password, + keys = [:download_policy, :mirror_on_sync, :mirroring_policy, :sync_policy, :arch, :verify_ssl_on_sync, :upstream_password, :upstream_username, :download_concurrency, :upstream_authentication_token, {:os_versions => []}, :deb_releases, :deb_components, :deb_architectures, :description, :http_proxy_policy, :http_proxy_id, :retain_package_versions_count, {:ignorable_content => []} ] keys += [{:docker_tags_whitelist => []}, :docker_upstream_name] if params[:action] == 'create' || @repository&.docker? @@ -523,11 +524,12 @@ end 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 + to_return = params.require(:repository).permit(*keys).to_h.with_indifferent_access + handle_mirror_on_sync(to_return) end def get_content_credential(repo_params, content_type) credential_value = @product.send(content_type) @@ -543,12 +545,12 @@ 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, :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.verify_ssl_on_sync = ::Foreman::Cast.to_bool(repo_params[:verify_ssl_on_sync]) if repo_params.key?(:verify_ssl_on_sync) + root.mirroring_policy = repo_params[:mirroring_policy] || Katello::RootRepository::MIRRORING_POLICY_CONTENT 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.upstream_authentication_token = repo_params[:upstream_authentication_token] if repo_params.key?(:upstream_authentication_token) root.ignorable_content = repo_params[:ignorable_content] if root.yum? && repo_params.key?(:ignorable_content) root.http_proxy_policy = repo_params[:http_proxy_policy] if repo_params.key?(:http_proxy_policy) @@ -575,10 +577,23 @@ root end # rubocop:enable Metrics/CyclomaticComplexity + def handle_mirror_on_sync(repo_params) + if !repo_params.key?(:mirroring_policy) && repo_params.key?(:mirror_on_sync) + ::Foreman::Deprecation.api_deprecation_warning("mirror_on_sync is deprecated in favor of mirroring_policy. It will be removed in Katello 4.6.") + if ::Foreman::Cast.to_bool(repo_params[:mirror_on_sync]) + repo_params[:mirroring_policy] = Katello::RootRepository::MIRRORING_POLICY_CONTENT + else + repo_params[:mirroring_policy] = Katello::RootRepository::MIRRORING_POLICY_ADDITIVE + end + end + repo_params.delete(:mirror_on_sync) + repo_params + end + def error_on_rh_product fail HttpErrors::BadRequest, _("Red Hat products cannot be manipulated.") if @product.redhat? end def error_on_rh_repo @@ -650,10 +665,10 @@ end def check_import_parameters @repository.repository_type&.import_attributes&.each do |import_attribute| if import_attribute.required && params[import_attribute.api_param].blank? - fail HttpErrors::UnprocessableEntity, _("%s is required", import_attributes.api_param) + fail HttpErrors::UnprocessableEntity, _('%s is required') % import_attribute.api_param end end end end end