Class: Actions::Pulp3::Repository::SaveArtifact

Inherits:
AbstractAsyncTask show all
Defined in:
app/lib/actions/pulp3/repository/save_artifact.rb

Instance Method Summary collapse

Methods inherited from AbstractAsyncTask

#cancel, #cancel!, #combined_tasks, #done?, #external_task, #humanized_state, #new_or_existing_objects, #pulp_tasks, #rescue_external_task, #run, #task_groups

Methods inherited from Abstract

#smart_proxy

Instance Method Details

#fetch_artifact_hrefObject



48
49
50
51
# File 'app/lib/actions/pulp3/repository/save_artifact.rb', line 48

def fetch_artifact_href
  sha_artifact_list = ::Katello::Pulp3::Api::Core.new(smart_proxy).artifacts_api.list("sha256": input[:options][:sha256])
  sha_artifact_list&.results&.first&.pulp_href
end

#invoke_external_taskObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/lib/actions/pulp3/repository/save_artifact.rb', line 12

def invoke_external_task
  repository = ::Katello::Repository.find(input[:repository_id])
  artifact_href = input[:options][:artifact_href] || fetch_artifact_href
  fail _("Content not uploaded to pulp") unless artifact_href
  content_type = input[:unit_type_id]
  content_backend_service = SmartProxy.pulp_primary.content_service(content_type)

  if repository.deb?
    repo_url = repository.backend_service(smart_proxy).repository_reference.repository_href
    output[:pulp_tasks] = [content_backend_service.content_api_create(relative_path: input[:options][:file_name],
                                                                      repository: repo_url,
                                                                      repository_id: repository.id,
                                                                      distribution: "katello",
                                                                      component: "upload",
                                                                      artifact: artifact_href,
                                                                      content_type: content_type)]
  else
    existing_content = ::Katello::Pulp3::PulpContentUnit.find_duplicate_unit(repository, input[:unit_type_id], {filename: input[:options][:file_name]}, input[:options][:sha256])
    existing_content_href = existing_content&.results&.first&.pulp_href

    if ::Katello::RepositoryTypeManager.find_content_type(input[:unit_type_id]).repository_import_on_upload
      output[:pulp_tasks] = [repository.backend_service(smart_proxy).repository_import_content(artifact_href, input[:options])]
    else
      if existing_content_href
        output[:content_unit_href] = existing_content_href
        []
      else
        output[:pulp_tasks] = [content_backend_service.content_api_create(relative_path: input[:options][:file_name],
                                                                          repository_id: repository.id,
                                                                          artifact: artifact_href,
                                                                          content_type: content_type)]
      end
    end
  end
end

#plan(file, repository, smart_proxy, tasks, unit_type_id, options = {}) ⇒ Object

This task creates a content unit and may or may not create a new repository version in the process



6
7
8
9
10
# File 'app/lib/actions/pulp3/repository/save_artifact.rb', line 6

def plan(file, repository, smart_proxy, tasks, unit_type_id, options = {})
  options[:file_name] = file[:filename]
  options[:sha256] = file[:sha256] || (Digest::SHA256.hexdigest(File.read(file[:path])) if file[:path].present?)
  plan_self(:repository_id => repository.id, :smart_proxy_id => smart_proxy.id, :tasks => tasks, :unit_type_id => unit_type_id, :options => options)
end