Class: Candlepin::Content::DockerRepositoryMapper

Inherits:
Object
  • Object
show all
Defined in:
app/models/katello/candlepin/content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, content, container_registry_name = nil) ⇒ DockerRepositoryMapper

Returns a new instance of DockerRepositoryMapper.



176
177
178
179
180
# File 'app/models/katello/candlepin/content.rb', line 176

def initialize(product, content, container_registry_name = nil)
  @product = product
  @content = content
  @container_registry_name = container_registry_name
end

Instance Attribute Details

#container_registry_nameObject

Returns the value of attribute container_registry_name.



175
176
177
# File 'app/models/katello/candlepin/content.rb', line 175

def container_registry_name
  @container_registry_name
end

#contentObject (readonly)

Returns the value of attribute content.



174
175
176
# File 'app/models/katello/candlepin/content.rb', line 174

def content
  @content
end

#productObject (readonly)

Returns the value of attribute product.



174
175
176
# File 'app/models/katello/candlepin/content.rb', line 174

def product
  @product
end

#registriesObject

Returns the value of attribute registries.



175
176
177
# File 'app/models/katello/candlepin/content.rb', line 175

def registries
  @registries
end

#registry_repoObject

Returns the value of attribute registry_repo.



175
176
177
# File 'app/models/katello/candlepin/content.rb', line 175

def registry_repo
  @registry_repo
end

Instance Method Details

#build_repositoryObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'app/models/katello/candlepin/content.rb', line 196

def build_repository
  unless registry
    Rails.logger.error("Docker registry with pulp_id #{container_registry_name} was not found at #{content.contentUrl}")
    fail _("Docker repository not found")
  end
  ::Katello::Repository.new(:environment => product.organization.library,
                           :product => product,
                           :pulp_id => pulp_id,
                           :cp_label => content.label,
                           :content_id => content.id,
                           :relative_path => relative_path,
                           :name => name,
                           :docker_upstream_name => registry["name"],
                           :label => label,
                           :url => feed_url,
                           :feed_ca => ca,
                           :feed_cert => product.certificate,
                           :feed_key => product.key,
                           :content_type => ::Katello::Repository::DOCKER_TYPE,
                           :preserve_metadata => true, #preserve repo metadata when importing from cp
                           :unprotected => true,
                           :content_view_version => product.organization.library.default_content_view_version)
end

#caObject



251
252
253
# File 'app/models/katello/candlepin/content.rb', line 251

def ca
  File.read(::Katello::Resources::CDN::CdnResource.ca_file)
end

#feed_urlObject



232
233
234
235
236
237
# File 'app/models/katello/candlepin/content.rb', line 232

def feed_url
  cdn_uri = URI.parse(product.provider.repository_url)
  docker_repo_uri =  URI.parse(registry["url"])
  docker_repo_uri =  URI.parse("#{cdn_uri.scheme}://#{registry['url']}") unless docker_repo_uri.host
  "#{docker_repo_uri.scheme}://#{docker_repo_uri.host}:#{docker_repo_uri.port}"
end

#find_repositoryObject



190
191
192
193
194
# File 'app/models/katello/candlepin/content.rb', line 190

def find_repository
  ::Katello::Repository.where(product_id: product.id,
                              environment_id: product.organization.library.id,
                              docker_upstream_name: container_registry_name).first
end

#katello_content_typeObject



243
244
245
# File 'app/models/katello/candlepin/content.rb', line 243

def katello_content_type
  ::Katello::Repository::DOCKER_TYPE
end

#labelObject



239
240
241
# File 'app/models/katello/candlepin/content.rb', line 239

def label
  ::Katello::Util::Model.labelize(name)
end

#nameObject



224
225
226
# File 'app/models/katello/candlepin/content.rb', line 224

def name
  "#{content.name} - (#{registry['name']})"
end

#pulp_idObject



228
229
230
# File 'app/models/katello/candlepin/content.rb', line 228

def pulp_id
  product.repo_id(content.name, nil, registry['name'])
end

#registryObject



182
183
184
185
186
187
188
# File 'app/models/katello/candlepin/content.rb', line 182

def registry
  validate!
  @registries ||= product.cdn_resource.get_docker_registries(content.contentUrl)
  @registry_repo ||= registries.detect do |reg|
    reg['name'] == @container_registry_name
  end
end

#relative_pathObject



247
248
249
# File 'app/models/katello/candlepin/content.rb', line 247

def relative_path
  ::Katello::Glue::Pulp::Repos.repo_path_from_content_path(product.organization.library, content.contentUrl)
end

#validate!Object



220
221
222
# File 'app/models/katello/candlepin/content.rb', line 220

def validate!
  fail _("Registry name cannot be blank") if @container_registry_name.blank?
end