From b08c85d96ff736354ed535b3b92bce6226bf4826 Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Wed, 25 Oct 2023 19:09:31 +0000 Subject: [PATCH] Fixes #36844 - Fail early when syncing non-library repos --- app/controllers/katello/api/v2/repositories_controller.rb | 1 + app/lib/actions/katello/repository/sync.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/katello/api/v2/repositories_controller.rb b/app/controllers/katello/api/v2/repositories_controller.rb index d5929312bca..e10c0453ffa 100644 --- a/app/controllers/katello/api/v2/repositories_controller.rb +++ b/app/controllers/katello/api/v2/repositories_controller.rb @@ -348,6 +348,7 @@ def show param :skip_metadata_check, :bool, :desc => N_("Force sync even if no upstream changes are detected. Only used with yum or deb repositories."), :required => false param :validate_contents, :bool, :desc => N_("Force a sync and validate the checksums of all content. Only used with yum repositories."), :required => false def sync + fail HttpErrors::BadRequest, _("attempted to sync a non-library repository.") unless @repository.library_instance? sync_options = { :skip_metadata_check => ::Foreman::Cast.to_bool(params[:skip_metadata_check]), :validate_contents => ::Foreman::Cast.to_bool(params[:validate_contents]), diff --git a/app/lib/actions/katello/repository/sync.rb b/app/lib/actions/katello/repository/sync.rb index 5645e7b4191..557412bd830 100644 --- a/app/lib/actions/katello/repository/sync.rb +++ b/app/lib/actions/katello/repository/sync.rb @@ -85,6 +85,7 @@ def humanized_name def validate_repo!(repo:, source_url:, skip_metadata_check:, skip_candlepin_check:) fail ::Katello::Errors::InvalidActionOptionError, _("Unable to sync repo. This repository does not have a feed url.") if repo.url.blank? && source_url.blank? fail ::Katello::Errors::InvalidActionOptionError, _("Cannot skip metadata check on non-yum/deb repositories.") if skip_metadata_check && !repo.yum? && !repo.deb? + fail ::Katello::Errors::InvalidActionOptionError, _("Unable to sync repo. This repository is not a library instance repository.") unless repo.library_instance? ::Katello::Util::CandlepinRepositoryChecker.check_repository_for_sync!(repo) if repo.yum? && !skip_candlepin_check end