Class: Katello::Pulp3::ContentViewVersion::ImportValidator
- Inherits:
-
Object
- Object
- Katello::Pulp3::ContentViewVersion::ImportValidator
- Defined in:
- app/services/katello/pulp3/content_view_version/import_validator.rb
Instance Method Summary collapse
- #check! ⇒ Object
- #ensure_from_cvv_exists! ⇒ Object
- #ensure_importing_cvv_does_not_exist! ⇒ Object
- #ensure_manifest_imported! ⇒ Object
- #ensure_metadata_matches_repos_in_library! ⇒ Object
- #ensure_non_composite! ⇒ Object
- #ensure_non_syncable_path_valid! ⇒ Object
- #ensure_pulp_importable! ⇒ Object
- #ensure_redhat_products_metadata_are_in_the_library! ⇒ Object
-
#initialize(import:) ⇒ ImportValidator
constructor
A new instance of ImportValidator.
Constructor Details
#initialize(import:) ⇒ ImportValidator
Returns a new instance of ImportValidator.
5 6 7 8 9 10 11 12 13 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 5 def initialize(import:) @content_view = import.content_view @path = import.path @smart_proxy = import.smart_proxy @organization = import.organization @metadata_map = import. @interested_repos = import. @redhat_library_products = redhat_library_products end |
Instance Method Details
#check! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 15 def check! if @metadata_map.content_view.blank? && !.syncable_format? fail _("Content view not provided in the metadata") end ensure_non_syncable_path_valid! unless @metadata_map.syncable_format? ensure_pulp_importable! if @content_view && !@content_view.default? ensure_non_composite! ensure_importing_cvv_does_not_exist! ensure_from_cvv_exists! end ensure_manifest_imported! end |
#ensure_from_cvv_exists! ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 63 def ensure_from_cvv_exists! major = @metadata_map.content_view_version.major minor = @metadata_map.content_view_version.minor if @metadata_map.from_content_view_version from_major = @metadata_map.from_content_view_version.major from_minor = @metadata_map.from_content_view_version.minor unless ::Katello::ContentViewVersion.where(major: from_major, minor: from_minor, content_view: @content_view).exists? fail _("Prior Content View Version specified in the metadata - '%{name}' does not exist. "\ "Please import the metadata for '%{name}' before importing '%{current}' " % { name: "#{@content_view.name} #{from_major}.#{from_minor}", current: "#{@content_view.name} #{major}.#{minor}"}) end end end |
#ensure_importing_cvv_does_not_exist! ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 53 def ensure_importing_cvv_does_not_exist! major = @metadata_map.content_view_version.major minor = @metadata_map.content_view_version.minor if ::Katello::ContentViewVersion.where(major: major, minor: minor, content_view: @content_view).exists? fail _("Content View Version specified in the metadata - '%{name}' already exists. "\ "If you wish to replace the existing version, delete %{name} and try again. " % { name: "#{@content_view.name} #{major}.#{minor}" }) end end |
#ensure_manifest_imported! ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 79 def ensure_manifest_imported! any_rh_repos = @metadata_map.repositories.any?(&:redhat) if any_rh_repos && !@organization.manifest_imported? fail _("No manifest found. Import a manifest with the appropriate subscriptions "\ "before importing content.") end end |
#ensure_metadata_matches_repos_in_library! ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 87 def bad_repos = @interested_repos.select do |katello_repo| = (katello_repo) next unless !(katello_repo.content_type == .content_type && katello_repo.redhat? == .redhat) end if bad_repos.any? fail _("The following repositories provided in the import metadata have an incorrect content type or provider type. "\ "Make sure the export and import repositories are of the same type before importing\n "\ "%{repos}" % { repos: generate_product_repo_i18n_string(bad_repos).join("")} ) end end |
#ensure_non_composite! ⇒ Object
39 40 41 42 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 39 def ensure_non_composite! return if @content_view.blank? fail _("Content cannot be imported into a Composite Content View. ") if @content_view.composite? end |
#ensure_non_syncable_path_valid! ⇒ Object
32 33 34 35 36 37 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 32 def ensure_non_syncable_path_valid! uri = URI(@path) unless uri.scheme.blank? || uri.scheme == "file" fail _("Invalid path provided. Content can be only imported from file system. ") end end |
#ensure_pulp_importable! ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 44 def ensure_pulp_importable! return if @metadata_map.syncable_format? api = ::Katello::Pulp3::Api::Core.new(@smart_proxy).importer_check_api response = api.pulp_import_check_post(toc: "#{@path}/#{@metadata_map.toc}") unless response.toc.is_valid fail response.toc..join("\n") end end |
#ensure_redhat_products_metadata_are_in_the_library! ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/services/katello/pulp3/content_view_version/import_validator.rb', line 105 def missing = @metadata_map.repositories.select do |repo| repo.redhat && (repo).nil? end if missing.any? repos_in_import = generate_product_repo_i18n_string(missing) fail _("The organization's manifest does not contain the subscriptions required to enable the following repositories.\n "\ "%{repos}" % { repos: repos_in_import.join("")} ) end end |