Class: Candlepin::Content::RepositoryMapper
- Inherits:
-
Object
- Object
- Candlepin::Content::RepositoryMapper
- Defined in:
- app/models/katello/candlepin/content.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
- #ca ⇒ 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
- #name ⇒ Object
- #path ⇒ Object
- #pulp_id ⇒ Object
- #relative_path ⇒ Object
- #substitutor ⇒ Object
- #unprotected? ⇒ Boolean
- #validate! ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(product, content, substitutions) ⇒ RepositoryMapper
Returns a new instance of RepositoryMapper.
41 42 43 44 45 |
# File 'app/models/katello/candlepin/content.rb', line 41 def initialize(product, content, substitutions) @product = product @content = content @substitutions = substitutions end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
39 40 41 |
# File 'app/models/katello/candlepin/content.rb', line 39 def content @content end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
39 40 41 |
# File 'app/models/katello/candlepin/content.rb', line 39 def product @product end |
#substitutions ⇒ Object (readonly)
Returns the value of attribute substitutions.
39 40 41 |
# File 'app/models/katello/candlepin/content.rb', line 39 def substitutions @substitutions end |
Instance Method Details
#arch ⇒ Object
116 117 118 |
# File 'app/models/katello/candlepin/content.rb', line 116 def arch substitutions[:basearch] || "noarch" end |
#build_repository ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/katello/candlepin/content.rb', line 53 def build_repository repository = Repository.new( :environment => product.organization.library, :product => product, :pulp_id => pulp_id, :cp_label => content.label, :content_id => content.id, :arch => arch, :major => major, :minor => minor, :relative_path => relative_path, :name => name, :label => label, :url => feed_url, :feed_ca => ca, :feed_cert => product.certificate, :feed_key => product.key, :content_type => katello_content_type, :preserve_metadata => true, #preserve repo metadata when importing from cp :unprotected => unprotected?, :download_policy => download_policy, :mirror_on_sync => true, :content_view_version => product.organization. library.default_content_view_version ) repository end |
#ca ⇒ Object
168 169 170 |
# File 'app/models/katello/candlepin/content.rb', line 168 def ca File.read(::Katello::Resources::CDN::CdnResource.ca_file) end |
#content_type ⇒ Object
136 137 138 |
# File 'app/models/katello/candlepin/content.rb', line 136 def content_type kickstart? ? 'yum' : content.type end |
#download_policy ⇒ Object
160 161 162 163 164 165 166 |
# File 'app/models/katello/candlepin/content.rb', line 160 def download_policy if katello_content_type == Repository::YUM_TYPE Setting[:default_download_policy] else "" end end |
#feed_url ⇒ Object
112 113 114 |
# File 'app/models/katello/candlepin/content.rb', line 112 def feed_url product.repo_url(path) end |
#file? ⇒ Boolean
152 153 154 |
# File 'app/models/katello/candlepin/content.rb', line 152 def file? content.type.downcase == 'file' end |
#find_repository ⇒ Object
47 48 49 50 51 |
# File 'app/models/katello/candlepin/content.rb', line 47 def find_repository ::Katello::Repository.where(product_id: product.id, environment_id: product.organization.library.id, pulp_id: pulp_id).first end |
#katello_content_type ⇒ Object
140 141 142 143 144 145 146 |
# File 'app/models/katello/candlepin/content.rb', line 140 def katello_content_type if content_type == ::Katello::Repository::CANDLEPIN_DOCKER_TYPE ::Katello::Repository::DOCKER_TYPE else content_type end end |
#kickstart? ⇒ Boolean
156 157 158 |
# File 'app/models/katello/candlepin/content.rb', line 156 def kickstart? content.type.downcase == 'kickstart' end |
#label ⇒ Object
120 121 122 |
# File 'app/models/katello/candlepin/content.rb', line 120 def label ::Katello::Util::Model.labelize(name) end |
#major ⇒ Object
128 129 130 |
# File 'app/models/katello/candlepin/content.rb', line 128 def major version[:major] end |
#minor ⇒ Object
132 133 134 |
# File 'app/models/katello/candlepin/content.rb', line 132 def minor version[:minor] end |
#name ⇒ Object
91 92 93 94 95 96 |
# File 'app/models/katello/candlepin/content.rb', line 91 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
102 103 104 105 106 |
# File 'app/models/katello/candlepin/content.rb', line 102 def path substitutions.inject(content.contentUrl) do |url, (key, value)| url.gsub("$#{key}", value) end end |
#pulp_id ⇒ Object
98 99 100 |
# File 'app/models/katello/candlepin/content.rb', line 98 def pulp_id product.repo_id(name) end |
#relative_path ⇒ Object
108 109 110 |
# File 'app/models/katello/candlepin/content.rb', line 108 def relative_path ::Katello::Glue::Pulp::Repos.repo_path_from_content_path(product.organization.library, path) end |
#substitutor ⇒ Object
87 88 89 |
# File 'app/models/katello/candlepin/content.rb', line 87 def substitutor product.cdn_resource.substitutor end |
#unprotected? ⇒ Boolean
148 149 150 |
# File 'app/models/katello/candlepin/content.rb', line 148 def unprotected? kickstart? || file? end |
#validate! ⇒ Object
82 83 84 85 |
# File 'app/models/katello/candlepin/content.rb', line 82 def validate! return if katello_content_type == Repository::OSTREE_TYPE substitutor.valid_substitutions(content, substitutions) end |
#version ⇒ Object
124 125 126 |
# File 'app/models/katello/candlepin/content.rb', line 124 def version ::Katello::Resources::CDN::Utils.parse_version(substitutions[:releasever]) end |