Class: Katello::RepositoryTypeManager

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/repository_type_manager.rb

Constant Summary collapse

PULP3_FEATURE =
"Pulpcore".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.defined_repository_typesObject (readonly)

Returns the value of attribute defined_repository_types.



10
11
12
# File 'app/services/katello/repository_type_manager.rb', line 10

def defined_repository_types
  @defined_repository_types
end

Class Method Details

.check_content_matches_repo_type!(repository, content_type) ⇒ Object



170
171
172
173
174
175
176
# File 'app/services/katello/repository_type_manager.rb', line 170

def check_content_matches_repo_type!(repository, content_type)
  repo_content_types = repository.repository_type.content_types.collect { |type| type.label }
  unless repo_content_types.include?(content_type)
    fail HttpErrors::BadRequest, _("Content type %{content_type} is incompatible with repositories of type %{repo_type}") %
           { content_type: content_type, repo_type: repository.content_type }
  end
end

.creatable_by_user?(repository_type, enabled_only = true) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
105
# File 'app/services/katello/repository_type_manager.rb', line 101

def creatable_by_user?(repository_type, enabled_only = true)
  type = enabled_only ? find(repository_type) : find_defined(repository_type)
  return false unless type
  type.allow_creation_by_user
end

.creatable_repository_types(enabled_only = true) ⇒ Object



47
48
49
50
51
52
# File 'app/services/katello/repository_type_manager.rb', line 47

def creatable_repository_types(enabled_only = true)
  repo_types = enabled_only ? enabled_repository_types : defined_repository_types
  repo_types.select do |repo_type, _|
    creatable_by_user?(repo_type, enabled_only)
  end
end

.enabled?(repository_type) ⇒ Boolean

Returns:

  • (Boolean)


166
167
168
# File 'app/services/katello/repository_type_manager.rb', line 166

def enabled?(repository_type)
  find(repository_type).present?
end

.enabled_content_types(enabled_only = true) ⇒ Object



65
66
67
68
69
70
71
# File 'app/services/katello/repository_type_manager.rb', line 65

def enabled_content_types(enabled_only = true)
  repo_types = enabled_only ? enabled_repository_types : defined_repository_types
  list = repo_types.values.map do |type|
    type.content_types.map(&:label).flatten
  end
  list.flatten
end

.enabled_repository_types(update = true) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/katello/repository_type_manager.rb', line 33

def enabled_repository_types(update = true)
  return @enabled_repository_types unless update

  disabled_types = @defined_repository_types.keys - @enabled_repository_types.keys
  return @enabled_repository_types if disabled_types.empty?

  if pulp_primary&.has_feature?(PULP3_FEATURE) && pulp_primary&.capabilities(PULP3_FEATURE)&.empty?
    fix_pulp3_capabilities
  end

  disabled_types.each { |repo_type| update_enabled_repository_type(repo_type.to_s) }
  @enabled_repository_types
end

.find(repository_type) ⇒ Object



127
128
129
130
131
132
133
134
# File 'app/services/katello/repository_type_manager.rb', line 127

def find(repository_type)
  # Skip updating disabled repo types because find() updates the input type if necessary
  found_repo_type = enabled_repository_types(false)[repository_type.to_s]
  if found_repo_type.blank?
    found_repo_type = update_enabled_repository_type(repository_type.to_s)
  end
  found_repo_type
end

.find_by(attribute, value) ⇒ Object



136
137
138
# File 'app/services/katello/repository_type_manager.rb', line 136

def find_by(attribute, value)
  enabled_repository_types.values.find { |type| type.try(attribute) == value }
end

.find_content_type(katello_label, indexable = false) ⇒ Object



144
145
146
147
148
149
150
151
152
# File 'app/services/katello/repository_type_manager.rb', line 144

def find_content_type(katello_label, indexable = false)
  enabled_repository_types.values.each do |repo_type|
    content_types = indexable ? repo_type.content_types_to_index : repo_type.content_types
    content_types.each do |content_type|
      return content_type if content_type.label == katello_label.to_s
    end
  end
  nil
end

.find_content_type!(katello_label) ⇒ Object



162
163
164
# File 'app/services/katello/repository_type_manager.rb', line 162

def find_content_type!(katello_label)
  find_content_type(katello_label) || fail("Couldn't find content type #{katello_label}")
end

.find_defined(repository_type) ⇒ Object



123
124
125
# File 'app/services/katello/repository_type_manager.rb', line 123

def find_defined(repository_type)
  @defined_repository_types[repository_type.to_s]
end

.find_repository_type(katello_label) ⇒ Object



140
141
142
# File 'app/services/katello/repository_type_manager.rb', line 140

def find_repository_type(katello_label)
  enabled_repository_types[katello_label]
end

.fix_pulp3_capabilitiesObject



26
27
28
29
30
31
# File 'app/services/katello/repository_type_manager.rb', line 26

def fix_pulp3_capabilities
  pulp_primary&.refresh
  if pulp_primary&.capabilities(PULP3_FEATURE)&.empty?
    fail Katello::Errors::PulpcoreMissingCapabilities
  end
end

.generic_content_type?(content_type, enabled_only = true) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
99
# File 'app/services/katello/repository_type_manager.rb', line 96

def generic_content_type?(content_type, enabled_only = true)
  types = generic_content_types(enabled_only)
  types.include?(content_type)
end

.generic_content_types(enabled_only = true) ⇒ Object



80
81
82
83
84
85
86
# File 'app/services/katello/repository_type_manager.rb', line 80

def generic_content_types(enabled_only = true)
  repo_types = enabled_only ? enabled_repository_types : defined_repository_types
  list = repo_types.values.map do |type|
    type.content_types.select { |ct| ct.model_class::CONTENT_TYPE == Katello::GenericContentUnit::CONTENT_TYPE }
  end
  list.flatten.map(&:content_type)
end

.generic_remote_options(opts = {}) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'app/services/katello/repository_type_manager.rb', line 178

def generic_remote_options(opts = {})
  options = []
  sorted_options = {}
  repo_types = opts[:defined_only] ? defined_repository_types : enabled_repository_types
  repo_types.each do |_, type|
    if opts[:content_type]
      (options << type.generic_remote_options).flatten! if type.pulp3_service_class == Katello::Pulp3::Repository::Generic && type.id.to_s == opts[:content_type]
    elsif opts[:sort_by_repo_type]
      sorted_options[type.id] = type.generic_remote_options if type.pulp3_service_class == Katello::Pulp3::Repository::Generic
    else
      (options << type.generic_remote_options).flatten! if type.pulp3_service_class == Katello::Pulp3::Repository::Generic
    end
  end
  opts[:sort_by_repo_type] ? sorted_options : options
end

.generic_repository_types(enabled_only = true) ⇒ Object



54
55
56
57
58
59
# File 'app/services/katello/repository_type_manager.rb', line 54

def generic_repository_types(enabled_only = true)
  repo_types = enabled_only ? enabled_repository_types : defined_repository_types
  repo_types.select do |_, values|
    values.pulp3_service_class == Katello::Pulp3::Repository::Generic
  end
end

.generic_ui_content_types(enabled_only = true) ⇒ Object



88
89
90
91
92
93
94
# File 'app/services/katello/repository_type_manager.rb', line 88

def generic_ui_content_types(enabled_only = true)
  repo_types = enabled_only ? enabled_repository_types : defined_repository_types
  list = repo_types.values.map do |type|
    type.content_types.select { |ct| ct.generic_browser }
  end
  list.flatten.map(&:content_type)
end

.indexable_content_typesObject



73
74
75
76
77
78
# File 'app/services/katello/repository_type_manager.rb', line 73

def indexable_content_types
  enabled_repository_types.
            values.
            map(&:content_types_to_index).
            flatten
end

.model_class(pulp_service_class) ⇒ Object



154
155
156
157
158
159
160
# File 'app/services/katello/repository_type_manager.rb', line 154

def model_class(pulp_service_class)
  enabled_repository_types.values.each do |repo_type|
    repo_type.content_types.each do |content_type|
      return content_type.model_class if (content_type.pulp3_service_class == pulp_service_class)
    end
  end
end

.pulp3_plugin_installed?(repository_type) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/services/katello/repository_type_manager.rb', line 61

def pulp3_plugin_installed?(repository_type)
  pulp_primary&.capabilities(PULP3_FEATURE)&.include?(@defined_repository_types[repository_type].pulp3_plugin)
end

.pulp_primaryObject



12
13
14
# File 'app/services/katello/repository_type_manager.rb', line 12

def pulp_primary
  ::SmartProxy.pulp_primary
end

.register(id, &block) ⇒ Object

Plugin constructor



17
18
19
20
21
22
23
24
# File 'app/services/katello/repository_type_manager.rb', line 17

def register(id, &block)
  defined_repo_type = find_defined(id)
  if defined_repo_type.blank?
    defined_repo_type = ::Katello::RepositoryType.new(id)
    defined_repo_type.instance_eval(&block) if block_given?
    @defined_repository_types[id.to_s] = defined_repo_type
  end
end

.removable_content_types(enabled_only = true) ⇒ Object



107
108
109
110
111
112
113
# File 'app/services/katello/repository_type_manager.rb', line 107

def removable_content_types(enabled_only = true)
  repo_types = enabled_only ? enabled_repository_types : defined_repository_types
  list = repo_types.values.map do |type|
    type.content_types.select(&:removable)
  end
  list.flatten
end

.uploadable_content_types(enabled_only = true) ⇒ Object



115
116
117
118
119
120
121
# File 'app/services/katello/repository_type_manager.rb', line 115

def uploadable_content_types(enabled_only = true)
  repo_types = enabled_only ? enabled_repository_types : defined_repository_types
  list = repo_types.values.map do |type|
    type.content_types.select(&:uploadable)
  end
  list.flatten
end