Class: Candlepin::Content::RepositoryMapper

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, 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

#contentObject (readonly)

Returns the value of attribute content.



39
40
41
# File 'app/models/katello/candlepin/content.rb', line 39

def content
  @content
end

#productObject (readonly)

Returns the value of attribute product.



39
40
41
# File 'app/models/katello/candlepin/content.rb', line 39

def product
  @product
end

#substitutionsObject (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

#archObject



116
117
118
# File 'app/models/katello/candlepin/content.rb', line 116

def arch
  substitutions[:basearch] || "noarch"
end

#build_repositoryObject



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

#caObject



168
169
170
# File 'app/models/katello/candlepin/content.rb', line 168

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

#content_typeObject



136
137
138
# File 'app/models/katello/candlepin/content.rb', line 136

def content_type
  kickstart? ? 'yum' : content.type
end

#download_policyObject



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_urlObject



112
113
114
# File 'app/models/katello/candlepin/content.rb', line 112

def feed_url
  product.repo_url(path)
end

#file?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'app/models/katello/candlepin/content.rb', line 152

def file?
  content.type.downcase == 'file'
end

#find_repositoryObject



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_typeObject



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

Returns:

  • (Boolean)


156
157
158
# File 'app/models/katello/candlepin/content.rb', line 156

def kickstart?
  content.type.downcase == 'kickstart'
end

#labelObject



120
121
122
# File 'app/models/katello/candlepin/content.rb', line 120

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

#majorObject



128
129
130
# File 'app/models/katello/candlepin/content.rb', line 128

def major
  version[:major]
end

#minorObject



132
133
134
# File 'app/models/katello/candlepin/content.rb', line 132

def minor
  version[:minor]
end

#nameObject



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

#pathObject



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_idObject



98
99
100
# File 'app/models/katello/candlepin/content.rb', line 98

def pulp_id
  product.repo_id(name)
end

#relative_pathObject



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

#substitutorObject



87
88
89
# File 'app/models/katello/candlepin/content.rb', line 87

def substitutor
  product.cdn_resource.substitutor
end

#unprotected?Boolean

Returns:

  • (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

#versionObject



124
125
126
# File 'app/models/katello/candlepin/content.rb', line 124

def version
  ::Katello::Resources::CDN::Utils.parse_version(substitutions[:releasever])
end