Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from shlomizadok/add_migration
Create an Endpoint for migrating old ARF reports
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Proxy::OpenSCAP | ||
class ImportApi < ::Sinatra::Base | ||
include ::Proxy::Log | ||
helpers ::Proxy::Helpers | ||
authorize_with_trusted_hosts | ||
|
||
require 'smart_proxy_openscap/openscap_lib' | ||
|
||
post "/arf/:cname/:policy_id/:date" do | ||
cn = params[:cname] | ||
date = params[:date] | ||
policy = params[:policy_id] | ||
log_halt(500, "Insufficient data") if (cn.nil? || date.nil?) | ||
|
||
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string) | ||
begin | ||
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date) | ||
.store_archive(request.body.string) | ||
rescue Proxy::OpenSCAP::StoreReportError => e | ||
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, cn, post_to_foreman['id'], date) | ||
.store_failed(request.body.string) | ||
logger.error "Failed to save Report in reports directory (#{Proxy::OpenSCAP::Plugin.settings.reportsdir}). Failed with: #{e.message}. | ||
Saving file in #{Proxy::OpenSCAP::Plugin.settings.failed_dir}. Please copy manually to #{Proxy::OpenSCAP::Plugin.settings.reportsdir}" | ||
rescue *HTTP_ERRORS => e | ||
### If the upload to foreman fails then store it in the spooldir | ||
logger.error "Failed to upload to Foreman, saving in spool. Failed with: #{e.message}" | ||
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.spooldir, cn, policy, date) | ||
.store_spool(request.body.string) | ||
rescue Proxy::OpenSCAP::StoreSpoolError => e | ||
log_halt 500, e.message | ||
end | ||
{:success => true, :arf_id => post_to_foreman['id']}.to_json | ||
end | ||
end | ||
end |