Class: ForemanInventoryUpload::Async::UploadReportDirectJob
Defined Under Namespace
Classes: FileUpload
Class Method Summary
collapse
Instance Method Summary
collapse
#execute_cloud_request
#attempts_before_next_interval, #done!, #done?, #invoke_external_task, #poll_external_task, #poll_intervals
#hash_to_s
Class Method Details
.output_label(label) ⇒ Object
41
42
43
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 41
def self.output_label(label)
"upload_for_#{label}"
end
|
Instance Method Details
#certificate ⇒ Object
121
122
123
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 121
def certificate
ForemanRhCloud.with_iop_smart_proxy? ? foreman_certificate : manifest_certificate
end
|
#content_disconnected? ⇒ Boolean
159
160
161
162
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 159
def content_disconnected?
return false if ForemanRhCloud.with_iop_smart_proxy?
!Setting[:subscription_connection_enabled]
end
|
#filename ⇒ Object
151
152
153
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 151
def filename
input[:filename]
end
|
#foreman_certificate ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 133
def foreman_certificate
cert_path = Setting[:ssl_certificate]
key_path = Setting[:ssl_priv_key]
unless cert_path && File.readable?(cert_path)
raise "SSL certificate file not found or not readable: #{cert_path}"
end
unless key_path && File.readable?(key_path)
raise "SSL private key file not found or not readable: #{key_path}"
end
{
cert: File.read(cert_path),
key: File.read(key_path),
}
end
|
#logger ⇒ Object
164
165
166
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 164
def logger
Foreman::Logging.logger('background')
end
|
#manifest_certificate ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 125
def manifest_certificate
candlepin_id_certificate = organization.owner_details['upstreamConsumer']['idCert']
{
cert: candlepin_id_certificate['cert'],
key: candlepin_id_certificate['key'],
}
end
|
#move_to_done_folder ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 111
def move_to_done_folder
FileUtils.mkdir_p(ForemanInventoryUpload.done_folder)
done_file = ForemanInventoryUpload.done_file_path(File.basename(filename))
if File.exist?(done_file)
logger.warn("Destination file #{done_file} already exists. Overwriting with new report.")
end
FileUtils.mv(filename, done_file, force: true)
logger.debug("Moved #{filename} to #{done_file}")
end
|
#organization ⇒ Object
155
156
157
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 155
def organization
Organization.find(input[:organization_id])
end
|
#plan(filename, organization_id) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 49
def plan(filename, organization_id)
organization = Organization.find(organization_id)
action_subject(organization)
plan_self(
filename: filename,
organization_id: organization_id
)
end
|
#rescue_strategy_for_self ⇒ Object
168
169
170
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 168
def rescue_strategy_for_self
Dynflow::Action::Rescue::Fail
end
|
#resource_locks ⇒ Object
45
46
47
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 45
def resource_locks
:link
end
|
#try_execute ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 59
def try_execute
if content_disconnected?
logger.info("Upload canceled: connection to Insights is not enabled. Report location: #{filename}")
done!
return
end
unless organization.owner_details&.dig('upstreamConsumer', 'idCert')
logger.info("Skipping organization '#{organization}', no candlepin certificate defined.")
done!
return
end
Tempfile.create([organization.name, '.pem']) do |cer_file|
cer_file.write(certificate[:cert])
cer_file.write(certificate[:key])
cer_file.flush
upload_file(cer_file.path)
end
move_to_done_folder
done!
end
|
#upload_file(cer_path) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/foreman_inventory_upload/async/upload_report_direct_job.rb', line 83
def upload_file(cer_path)
cert_content = File.read(cer_path)
File.open(filename, 'rb') do |file|
wrapped_file = FileUpload.new(file, content_type: 'application/vnd.redhat.qpc.tar+tgz')
response = execute_cloud_request(
method: :post,
url: ForemanInventoryUpload.upload_url,
payload: {
multipart: true,
file: wrapped_file,
},
headers: {
'X-Org-Id' => organization.label,
},
ssl_client_cert: OpenSSL::X509::Certificate.new(cert_content),
ssl_client_key: OpenSSL::PKey::RSA.new(cert_content),
timeout: 600,
open_timeout: 60
)
logger.debug("Upload response code: #{response.code}")
end
end
|