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



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

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)


99
100
101
102
103
# File 'app/services/katello/repository_type_manager.rb', line 99

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



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

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)


164
165
166
# File 'app/services/katello/repository_type_manager.rb', line 164

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

.enabled_content_types(enabled_only = true) ⇒ Object



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

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
# File 'app/services/katello/repository_type_manager.rb', line 33

def enabled_repository_types(update = true)
  if update && pulp_primary&.has_feature?(PULP3_FEATURE) && pulp_primary&.capabilities(PULP3_FEATURE)&.empty?
    fix_pulp3_capabilities
  end

  disabled_types = @defined_repository_types.keys - @enabled_repository_types.keys
  if update && disabled_types.present?
    disabled_types.each { |repo_type| update_enabled_repository_type(repo_type.to_s) }
  end
  @enabled_repository_types
end

.find(repository_type) ⇒ Object



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

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



134
135
136
# File 'app/services/katello/repository_type_manager.rb', line 134

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

.find_content_type(katello_label, indexable = false) ⇒ Object



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

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



160
161
162
# File 'app/services/katello/repository_type_manager.rb', line 160

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



121
122
123
# File 'app/services/katello/repository_type_manager.rb', line 121

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

.find_repository_type(katello_label) ⇒ Object



138
139
140
# File 'app/services/katello/repository_type_manager.rb', line 138

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)


94
95
96
97
# File 'app/services/katello/repository_type_manager.rb', line 94

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



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

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



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

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



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

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



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

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



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

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

.model_class(pulp_service_class) ⇒ Object



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

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)


59
60
61
# File 'app/services/katello/repository_type_manager.rb', line 59

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



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

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



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

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