Sha256: 87fa953c5baf52f2d12d6f4d8ab54b151876f20ca1fdefce50c1b18141c687ab

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

module Actions
  module Pulp3
    module Repository
      class CommitUpload < Pulp3::AbstractAsyncTask
        def plan(repository, smart_proxy, upload_href, sha256)
          plan_self(:repository_id => repository.id, :smart_proxy_id => smart_proxy.id, :upload_href => upload_href, :sha256 => sha256)
        end

        def invoke_external_task
          repo = ::Katello::Repository.find(input[:repository_id])
          repo_backend_service = repo.backend_service(smart_proxy)
          uploads_api = repo_backend_service.core_api.uploads_api
          duplicate_sha_artifact_list = ::Katello::Pulp3::Api::Core.new(smart_proxy).artifacts_api.list("sha256": input[:sha256])
          duplicate_sha_artifact_href = duplicate_sha_artifact_list&.results&.first&.pulp_href
          if duplicate_sha_artifact_href
            uploads_api.delete(input[:upload_href])
            output[:artifact_href] = duplicate_sha_artifact_href
            output[:pulp_tasks] = nil
          else
            output[:artifact_href] = nil
            upload_commit = repo_backend_service.core_api.upload_commit_class.new(sha256: input[:sha256])
            output[:pulp_tasks] = [uploads_api.commit(input[:upload_href], upload_commit)]
          end
        end

        def check_for_errors
          combined_tasks.each do |task|
            if unique_error task.error
              warn _("Duplicate artifact detected")
            else
              super
            end
          end
        end

        def unique_error(message)
          message&.include?("code='unique'")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katello-4.3.0.rc2.1 app/lib/actions/pulp3/repository/commit_upload.rb
katello-4.3.0.rc2 app/lib/actions/pulp3/repository/commit_upload.rb
katello-4.3.0.rc1 app/lib/actions/pulp3/repository/commit_upload.rb