Class: Katello::Pulp3::AnsibleCollection

Inherits:
PulpContentUnit show all
Includes:
LazyAccessor
Defined in:
app/services/katello/pulp3/ansible_collection.rb

Instance Attribute Summary

Attributes inherited from PulpContentUnit

#backend_data, #uuid

Class Method Summary collapse

Methods included from LazyAccessor

included

Methods inherited from PulpContentUnit

add_timestamps, backend_unit_identifier, content_api_create, content_type, content_unit_list, create_content, #fetch_backend_data, fetch_content_list, find_duplicate_unit, #initialize, model_class, page_options, pulp_units_batch_all, pulp_units_batch_for_repo, pulp_units_for_ids, supports_id_fetch?, unit_identifier

Constructor Details

This class inherits a constructor from Katello::Pulp3::PulpContentUnit

Class Method Details

.content_apiObject



6
7
8
# File 'app/services/katello/pulp3/ansible_collection.rb', line 6

def self.content_api
  PulpAnsibleClient::ContentCollectionVersionsApi.new(Katello::Pulp3::Api::AnsibleCollection.new(SmartProxy.pulp_primary!).api_client)
end

.generate_model_row(unit) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'app/services/katello/pulp3/ansible_collection.rb', line 21

def self.generate_model_row(unit)
  {
    pulp_id: unit['pulp_href'],
    checksum: unit['sha256'],
    namespace: unit['namespace'],
    version: unit['version'],
    name: unit['name'],
    description: unit['description']
  }
end

.ids_for_repository(repo_id) ⇒ Object



10
11
12
13
14
# File 'app/services/katello/pulp3/ansible_collection.rb', line 10

def self.ids_for_repository(repo_id)
  repo = Katello::Pulp3::Repository::AnsibleCollection.new(Katello::Repository.find(repo_id), SmartProxy.pulp_primary)
  repo_content_list = repo.content_list
  repo_content_list.map { |content| content.try(:pulp_href) }
end

.insert_child_associations(units, pulp_id_to_id) ⇒ Object



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

def self.insert_child_associations(units, pulp_id_to_id)
  insert_tags units
  collection_tag_rows = []
  units.each do |unit|
    katello_id = pulp_id_to_id[unit['pulp_href']]
    #delete old tags
    unit_tags = unit['tags']&.map { |tag| tag[:name] }
    Katello::AnsibleCollectionTag.where(:ansible_collection_id => katello_id).where.not(:ansible_tag_id => Katello::AnsibleTag.where(:name => unit_tags)).delete_all
    collection_tag_rows += Katello::AnsibleTag.where(:name => unit_tags)&.pluck(:id)&.map { |tag_id| {ansible_collection_id: katello_id, ansible_tag_id: tag_id} }
  end

  collection_tag_rows.flatten!
  Katello::AnsibleCollectionTag.insert_all(collection_tag_rows, unique_by: [:ansible_collection_id, :ansible_tag_id]) unless collection_tag_rows.empty?
end

.insert_tags(units) ⇒ Object



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

def self.insert_tags(units)
  tag_names = units.map { |unit| unit['tags']&.map { |tag| tag[:name] } }&.flatten
  tag_rows = tag_names&.compact&.map { |name| {name: name } }
  Katello::AnsibleTag.insert_all(tag_rows, unique_by: [:name]) if tag_rows.any?
end

.pulp_data(_pulp_href) ⇒ Object



16
17
18
19
# File 'app/services/katello/pulp3/ansible_collection.rb', line 16

def self.pulp_data(_pulp_href)
  #No content read method
  fail NotImplementedError
end