Class: ForemanInventoryUpload::Async::UploadReportJob

Inherits:
ShellProcess
  • Object
show all
Defined in:
lib/foreman_inventory_upload/async/upload_report_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShellProcess

#logger, #progress_output, #rescue_strategy_for_self

Methods included from ForemanRhCloud::Async::ExponentialBackoff

#attempts_before_next_interval, #done!, #done?, #invoke_external_task, #poll_external_task, #poll_intervals

Methods included from AsyncHelpers

#hash_to_s

Class Method Details

.output_label(label) ⇒ Object



6
7
8
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 6

def self.output_label(label)
  "upload_for_#{label}"
end

Instance Method Details

#commandObject



44
45
46
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 44

def command
  ['/bin/bash', File.join(File.dirname(filename), ForemanInventoryUpload.upload_script_file)]
end

#content_disconnected?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 80

def content_disconnected?
  Setting[:content_disconnected]
end

#envObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 48

def env
  env_vars = super.merge(
    'FILES' => filename,
    'CER_PATH' => @cer_path
  )

  http_proxy_string = ForemanRhCloud.http_proxy_string(logger: logger)
  if http_proxy_string
    env_vars['http_proxy'] = http_proxy_string
    env_vars['https_proxy'] = http_proxy_string
  end
  env_vars
end

#filenameObject



72
73
74
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 72

def filename
  input[:filename]
end

#organizationObject



76
77
78
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 76

def organization
  @organization ||= Organization.find(input[:organization_id])
end

#plan(filename, organization_id) ⇒ Object



10
11
12
13
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 10

def plan(filename, organization_id)
  label = UploadReportJob.output_label(organization_id)
  super(label, filename: filename, organization_id: organization_id)
end

#rh_credentialsObject



62
63
64
65
66
67
68
69
70
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 62

def rh_credentials
  @rh_credentials ||= begin
    candlepin_id_certificate = organization.owner_details['upstreamConsumer']['idCert']
    {
      cert: candlepin_id_certificate['cert'],
      key: candlepin_id_certificate['key'],
    }
  end
end

#try_executeObject



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
# File 'lib/foreman_inventory_upload/async/upload_report_job.rb', line 15

def try_execute
  if content_disconnected?
    progress_output do |progress_output|
      progress_output.write_line('Upload was stopped since disconnected mode setting is enabled for content on this instance.')
      progress_output.status = "Task aborted, exit 1"
      done!
    end
    return
  end

  unless organization.owner_details&.fetch('upstreamConsumer')&.fetch('idCert')
    logger.info("Skipping organization '#{organization}', no candlepin certificate defined.")
    progress_output do |progress_output|
      progress_output.write_line("Skipping organization #{organization}, no candlepin certificate defined.")
      progress_output.status = "Task aborted, exit 1"
      done!
    end
    return
  end

  Tempfile.create([organization.name, '.pem']) do |cer_file|
    cer_file.write(rh_credentials[:cert])
    cer_file.write(rh_credentials[:key])
    cer_file.flush
    @cer_path = cer_file.path
    super
  end
end