Class: Katello::Candlepin::RepositoryMapper
- Inherits:
-
Object
- Object
- Katello::Candlepin::RepositoryMapper
- Defined in:
- app/models/katello/candlepin/repository_mapper.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#substitutions ⇒ Object
readonly
Returns the value of attribute substitutions.
Instance Method Summary collapse
- #arch ⇒ Object
- #build_repository ⇒ Object
- #content_type ⇒ Object
- #download_policy ⇒ Object
- #feed_url ⇒ Object
- #file? ⇒ Boolean
- #find_repository ⇒ Object
-
#initialize(product, content, substitutions) ⇒ RepositoryMapper
constructor
A new instance of RepositoryMapper.
- #katello_content_type ⇒ Object
- #kickstart? ⇒ Boolean
- #label ⇒ Object
- #major ⇒ Object
- #minor ⇒ Object
- #mirroring_policy ⇒ Object
- #name ⇒ Object
- #path ⇒ Object
- #prune_substitutions(subs, url) ⇒ Object
- #relative_path ⇒ Object
- #substitutor ⇒ Object
- #suse? ⇒ Boolean
- #unprotected? ⇒ Boolean
- #validate! ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(product, content, substitutions) ⇒ RepositoryMapper
Returns a new instance of RepositoryMapper.
6 7 8 9 10 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 6 def initialize(product, content, substitutions) @product = product @content = content @substitutions = prune_substitutions(substitutions.try(:with_indifferent_access), content.content_url) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 4 def content @content end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
4 5 6 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 4 def product @product end |
#substitutions ⇒ Object (readonly)
Returns the value of attribute substitutions.
4 5 6 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 4 def substitutions @substitutions end |
Instance Method Details
#arch ⇒ Object
93 94 95 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 93 def arch substitutions[:basearch] || "noarch" end |
#build_repository ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 31 def build_repository root = RootRepository.new( :product => product, :content_id => content.cp_content_id, :arch => arch, :major => major, :minor => minor, :name => name, :label => label, :url => feed_url, :content_type => katello_content_type, :unprotected => unprotected?, :download_policy => download_policy, :mirroring_policy => mirroring_policy ) Repository.new(:root => root, :relative_path => relative_path, :environment => product.organization.library, :content_view_version => product.organization.library.default_content_view_version) end |
#content_type ⇒ Object
113 114 115 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 113 def content_type kickstart? ? 'yum' : content.content_type end |
#download_policy ⇒ Object
141 142 143 144 145 146 147 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 141 def download_policy if ::Katello::RootRepository::CONTENT_ATTRIBUTE_RESTRICTIONS[:download_policy].include?(katello_content_type) Setting[:default_redhat_download_policy] else "" end end |
#feed_url ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 84 def feed_url return if product.organization.cdn_configuration.export_sync? @feed_url ||= if product.cdn_resource.respond_to?(:repository_url) product.cdn_resource.repository_url(content_label: content.label, arch: arch, major: version[:major], minor: version[:minor]) else product.repo_url(path) end end |
#file? ⇒ Boolean
133 134 135 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 133 def file? content.content_type.downcase == 'file' end |
#find_repository ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 12 def find_repository if substitutions[:basearch] root = ::Katello::RootRepository.where(product_id: product.id, content_id: content.cp_content_id, minor: minor, arch: arch).first else root = ::Katello::RootRepository.where(product_id: product.id, content_id: content.cp_content_id, minor: minor).first end if root Katello::Repository.where(root: root, environment_id: product.organization.library.id).first end end |
#katello_content_type ⇒ Object
117 118 119 120 121 122 123 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 117 def katello_content_type if content_type == ::Katello::Repository::CANDLEPIN_DOCKER_TYPE ::Katello::Repository::DOCKER_TYPE else content_type end end |
#kickstart? ⇒ Boolean
137 138 139 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 137 def kickstart? content.content_type.downcase == 'kickstart' end |
#label ⇒ Object
97 98 99 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 97 def label ::Katello::Util::Model.labelize(name) end |
#major ⇒ Object
105 106 107 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 105 def major version[:major] end |
#minor ⇒ Object
109 110 111 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 109 def minor version[:minor] end |
#mirroring_policy ⇒ Object
149 150 151 152 153 154 155 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 149 def mirroring_policy if katello_content_type == Repository::YUM_TYPE Katello::RootRepository::MIRRORING_POLICY_COMPLETE else Katello::RootRepository::MIRRORING_POLICY_CONTENT end end |
#name ⇒ Object
63 64 65 66 67 68 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 63 def name sorted_substitutions = substitutions.sort_by { |k, _| k.to_s }.map(&:last) repo_name_parts = [content.name, sorted_substitutions].flatten.compact repo_name_parts.join(" ").gsub(/[^a-z0-9\-._ ]/i, "") end |
#path ⇒ Object
70 71 72 73 74 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 70 def path substitutions.inject(content.content_url) do |url, (key, value)| url.gsub("$#{key}", value) end end |
#prune_substitutions(subs, url) ⇒ Object
80 81 82 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 80 def prune_substitutions(subs, url) subs.select { |key, _| url.include?("$#{key}") } end |
#relative_path ⇒ Object
76 77 78 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 76 def relative_path ::Katello::Repository.repo_path_from_content_path(product.organization.library, path) end |
#substitutor ⇒ Object
58 59 60 61 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 58 def substitutor fail _("Manifest does not have a valid subscription") if product.cdn_resource.nil? product.cdn_resource.substitutor end |
#suse? ⇒ Boolean
129 130 131 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 129 def suse? content.content_type == Repository::YUM_TYPE && !!path.downcase.match(/suse/) end |
#unprotected? ⇒ Boolean
125 126 127 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 125 def unprotected? kickstart? || file? || suse? end |
#validate! ⇒ Object
53 54 55 56 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 53 def validate! return if katello_content_type == Repository::OSTREE_TYPE || product.organization.cdn_configuration.export_sync? substitutor.validate_substitutions(content, substitutions) end |
#version ⇒ Object
101 102 103 |
# File 'app/models/katello/candlepin/repository_mapper.rb', line 101 def version ::Katello::Resources::CDN::Utils.parse_version(substitutions[:releasever]) end |