Skip to content

Commit

Permalink
_Add auto-fixed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Prazak committed Oct 30, 2017
1 parent f8fb1b1 commit 21b55c8
Show file tree
Hide file tree
Showing 63 changed files with 315 additions and 303 deletions.
48 changes: 45 additions & 3 deletions .rubocop_todo.yml
@@ -1,28 +1,31 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-10-27 09:51:11 +0000 using RuboCop version 0.51.0.
# on 2017-10-30 11:48:15 +0000 using RuboCop version 0.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 13
# Offense count: 16
# Cop supports --auto-correct.
Layout/AlignArray:
Exclude:
- 'lib/foreman_openscap/engine.rb'
- 'lib/tasks/foreman_openscap_tasks.rake'

# Offense count: 33
# Offense count: 62
# Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, SupportedHashRocketStyles, EnforcedColonStyle, SupportedColonStyles, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/AlignHash:
Exclude:
- 'app/helpers/policies_helper.rb'
- 'app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb'
- 'app/models/concerns/foreman_openscap/host_extensions.rb'
- 'app/models/foreman_openscap/policy.rb'
- 'app/services/foreman_openscap/policy_dashboard/data.rb'
- 'config/routes.rb'
- 'lib/foreman_openscap/engine.rb'
- 'test/unit/policy_test.rb'
Expand Down Expand Up @@ -90,6 +93,13 @@ Layout/EmptyLinesAroundClassBody:
- 'test/unit/arf_report_status_calculator_test.rb'
- 'test/unit/concerns/openscap_proxy_extenstions_test.rb'

# Offense count: 12
# Cop supports --auto-correct.
Layout/EmptyLinesAroundMethodBody:
Exclude:
- 'app/controllers/arf_reports_controller.rb'
- 'app/lib/proxy_api/openscap.rb'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand All @@ -100,6 +110,14 @@ Layout/EmptyLinesAroundModuleBody:
- 'app/helpers/compliance_dashboard_helper.rb'
- 'app/helpers/compliance_hosts_helper.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Layout/IndentationWidth:
Exclude:
- 'app/controllers/arf_reports_controller.rb'
- 'app/lib/proxy_api/openscap.rb'

# Offense count: 5
# Cop supports --auto-correct.
Layout/LeadingCommentSpace:
Expand All @@ -120,6 +138,13 @@ Layout/MultilineOperationIndentation:
- 'app/helpers/policy_dashboard_helper.rb'
- 'app/models/foreman_openscap/policy.rb'

# Offense count: 6
# Cop supports --auto-correct.
Layout/RescueEnsureAlignment:
Exclude:
- 'app/controllers/arf_reports_controller.rb'
- 'app/lib/proxy_api/openscap.rb'

# Offense count: 4
# Cop supports --auto-correct.
Layout/SpaceAfterComma:
Expand Down Expand Up @@ -155,6 +180,13 @@ Layout/SpaceInsideBrackets:
Layout/SpaceInsideHashLiteralBraces:
Enabled: false

# Offense count: 12
# Cop supports --auto-correct.
Layout/TrailingWhitespace:
Exclude:
- 'app/controllers/arf_reports_controller.rb'
- 'app/lib/proxy_api/openscap.rb'

# Offense count: 1
Lint/AmbiguousOperator:
Exclude:
Expand Down Expand Up @@ -378,6 +410,16 @@ Style/RedundantBegin:
- 'app/controllers/arf_reports_controller.rb'
- 'app/lib/proxy_api/openscap.rb'

# Offense count: 5
# Cop supports --auto-correct.
Style/RedundantParentheses:
Exclude:
- 'app/controllers/api/v2/compliance/arf_reports_controller.rb'
- 'app/controllers/api/v2/compliance/policies_controller.rb'
- 'app/controllers/api/v2/compliance/scap_contents_controller.rb'
- 'app/controllers/api/v2/compliance/tailoring_files_controller.rb'
- 'app/controllers/policies_controller.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Expand Down
1 change: 0 additions & 1 deletion Rakefile 100644 → 100755
Expand Up @@ -33,5 +33,4 @@ Rake::TestTask.new(:test) do |t|
t.verbose = false
end


task :default => :test
7 changes: 3 additions & 4 deletions app/controllers/api/v2/compliance/arf_reports_controller.rb
Expand Up @@ -3,7 +3,6 @@
module Api
module V2
module Compliance

class ArfReportsController < V2::BaseController
include Api::Version2
include Foreman::Controller::SmartProxyAuth
Expand All @@ -19,7 +18,7 @@ def resource_name
end

def get_resource(message = 'no resource loaded')
instance_variable_get :"@arf_report" or raise message
instance_variable_get(:"@arf_report") || raise(message)
end

api :GET, '/compliance/arf_reports', N_('List ARF reports')
Expand Down Expand Up @@ -48,7 +47,7 @@ def destroy
param :date, :identifier, :required => true

def create
asset = ForemanOpenscap::Helper::get_asset(params[:cname], params[:policy_id])
asset = ForemanOpenscap::Helper.get_asset(params[:cname], params[:policy_id])
arf_report = ForemanOpenscap::ArfReport.create_arf(asset, params)
asset.host.refresh_statuses if asset.host
render :json => { :result => :OK, :id => arf_report.id.to_s }
Expand Down Expand Up @@ -77,7 +76,7 @@ def download_html
private

def find_resource
not_found and return if params[:id].blank?
not_found && return if params[:id].blank?
instance_variable_set("@arf_report", resource_scope.find(params[:id]))
end

Expand Down
7 changes: 4 additions & 3 deletions app/controllers/api/v2/compliance/policies_controller.rb
Expand Up @@ -15,10 +15,10 @@ def resource_name
end

def get_resource(message = 'no resource loaded')
instance_variable_get :"@policy" or raise message
instance_variable_get(:"@policy") || raise(message)
end

def policy_url(policy = nil)
def policy_url(_policy = nil)
api_compliance_policy_url(@policy)
end

Expand Down Expand Up @@ -100,8 +100,9 @@ def tailoring
end

private

def find_resource
not_found and return if params[:id].blank?
not_found && return if params[:id].blank?
instance_variable_set("@policy", resource_scope.find(params[:id]))
end

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/api/v2/compliance/scap_contents_controller.rb
Expand Up @@ -9,7 +9,7 @@ def resource_name
end

def get_resource(message = 'no resource loaded')
instance_variable_get :"@scap_content" or raise message
instance_variable_get(:"@scap_content") || raise(message)
end

api :GET, '/compliance/scap_contents', N_('List SCAP contents')
Expand Down Expand Up @@ -66,8 +66,9 @@ def destroy
end

private

def find_resource
not_found and return if params[:id].blank?
not_found && return if params[:id].blank?
instance_variable_set("@scap_content", resource_scope.find(params[:id]))
end

Expand Down
Expand Up @@ -10,7 +10,7 @@ def resource_name
end

def get_resource(message = 'no resource loaded')
instance_variable_get :"@tailoring_file" or raise message
instance_variable_get(:"@tailoring_file") || raise(message)
end

api :GET, '/compliance/tailoring_files', N_('List Tailoring files')
Expand Down Expand Up @@ -67,8 +67,9 @@ def destroy
end

private

def find_resource
not_found and return if params[:id].blank?
not_found && return if params[:id].blank?
instance_variable_set("@tailoring_file", resource_scope.find(params[:id]))
end

Expand Down
42 changes: 18 additions & 24 deletions app/controllers/arf_reports_controller.rb
Expand Up @@ -22,39 +22,33 @@ def show_html
end

def parse_html
begin
self.response_body = @arf_report.to_html
rescue => e
render :text => _(e.message)
end
self.response_body = @arf_report.to_html
rescue => e
render :text => _(e.message)
end

def parse_bzip
begin
response = @arf_report.to_bzip
send_data response, :filename => "#{format_filename}.xml.bz2", :type => 'application/octet-stream', :disposition => 'attachement'
rescue => e
process_error(:error_msg => (_("Failed to downloaded ARF report as bzip: %s") % e.message),
:error_redirect => arf_report_path(@arf_report.id))
end
response = @arf_report.to_bzip
send_data response, :filename => "#{format_filename}.xml.bz2", :type => 'application/octet-stream', :disposition => 'attachement'
rescue => e
process_error(:error_msg => (_("Failed to downloaded ARF report as bzip: %s") % e.message),
:error_redirect => arf_report_path(@arf_report.id))
end

def download_html
begin
response = @arf_report.to_html
send_data response, :filename => "#{format_filename}.html",
:type => 'text/html', :disposition => 'attachement'
rescue => e
process_error(:error_msg => _("Failed to downloaded ARF report in HTML: %s") % e.message,
:error_redirect => arf_report_path(@arf_report.id))
end
response = @arf_report.to_html
send_data response, :filename => "#{format_filename}.html",
:type => 'text/html', :disposition => 'attachement'
rescue => e
process_error(:error_msg => _("Failed to downloaded ARF report in HTML: %s") % e.message,
:error_redirect => arf_report_path(@arf_report.id))
end

def destroy
if @arf_report.destroy
process_success(:success_msg => _("Successfully deleted ARF report."), :success_redirect => arf_reports_path)
else
process_error(:error_msg => _("Failed to delete ARF Report for host %{host_name} reported at %{reported_at}") % {:host_name => @arf_report.host.name, :reported_at => @arf_report.reported_at})
process_error(:error_msg => _("Failed to delete ARF Report for host %{host_name} reported at %{reported_at}") % { :host_name => @arf_report.host.name, :reported_at => @arf_report.reported_at })
end
end

Expand Down Expand Up @@ -83,18 +77,18 @@ def find_multiple
@arf_reports = ::ForemanOpenscap::ArfReport.where(:id => params[:arf_report_ids])
if @arf_reports.empty?
error _('No compliance reports were found.')
redirect_to(arf_reports_path) and return false
redirect_to(arf_reports_path) && (return false)
end
else
error _('No compliance reports selected')
redirect_to(arf_reports_path) and return false
redirect_to(arf_reports_path) && (return false)
end
return @arf_reports
rescue => e
error _("Something went wrong while selecting compliance reports - %s") % e
logger.debug e.message
logger.debug e.backtrace.join("\n")
redirect_to arf_reports_path and return false
redirect_to(arf_reports_path) && (return false)
end

def action_permission
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/openscap_proxies_controller.rb
@@ -1,5 +1,5 @@
class OpenscapProxiesController < ApplicationController
before_action :find_proxy, :only => [:openscap_spool]
before_filter :find_proxy, :only => [:openscap_spool]

def openscap_spool
last_error = @smart_proxy ? find_spool_error : nil
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/policies_controller.rb
Expand Up @@ -35,7 +35,7 @@ def create
if @policy.wizard_completed? && @policy.save
process_success :success_redirect => policies_path
elsif @policy.valid?
render 'new' and return
render('new') && return
else
@policy.rewind_step
process_error :object => @policy
Expand Down Expand Up @@ -64,7 +64,7 @@ def destroy
def scap_content_selected
if params[:scap_content_id] && (@scap_content = ::ForemanOpenscap::ScapContent.find(params[:scap_content_id]))
@policy ||= ::ForemanOpenscap::Policy.new
render :partial => 'scap_content_results', :locals => {:policy => @policy}
render :partial => 'scap_content_results', :locals => { :policy => @policy }
end
end

Expand Down Expand Up @@ -104,6 +104,7 @@ def remove_policy_from_multiple_hosts
end

private

def find_by_id
@policy = resource_base.find(params[:id])
end
Expand All @@ -118,18 +119,18 @@ def find_multiple
@hosts = Host.where("id IN (?)", params[:host_ids])
if @hosts.empty?
error _('No hosts were found.')
redirect_to(hosts_path) and return false
redirect_to(hosts_path) && (return false)
end
else
error _('No hosts selected')
redirect_to(hosts_path) and return false
redirect_to(hosts_path) && (return false)
end
return @hosts
rescue => e
error _("Something went wrong while selecting hosts - %s") % e
logger.debug e.message
logger.debug e.backtrace.join("\n")
redirect_to hosts_path and return false
redirect_to(hosts_path) && (return false)
end

def action_permission
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/scap_contents_controller.rb
Expand Up @@ -15,8 +15,8 @@ def index

def show
send_data @scap_content.scap_file,
:type => 'application/xml',
:filename => @scap_content.original_filename
:type => 'application/xml',
:filename => @scap_content.original_filename
end

def new
Expand Down Expand Up @@ -49,6 +49,7 @@ def destroy
end

private

def find_by_id
@scap_content = resource_base.find(params[:id])
end
Expand All @@ -58,5 +59,4 @@ def handle_file_upload
params[:scap_content][:original_filename] = scap_raw_file.original_filename
params[:scap_content][:scap_file] = scap_raw_file.tempfile.read if scap_raw_file.tempfile.respond_to?(:read)
end

end
2 changes: 1 addition & 1 deletion app/helpers/arf_report_dashboard_helper.rb
Expand Up @@ -10,7 +10,7 @@ def reports_breakdown_chart(report, options = {})
[[:failed, _('Failed')],
[:passed, _('Passed')],
[:othered, _('Othered')],].each do |i|
data << {:label => i[1], :data => report[i[0]], :color => COLORS[i[0]]}
data << { :label => i[1], :data => report[i[0]], :color => COLORS[i[0]] }
end
flot_pie_chart 'overview', _('Compliance reports breakdown'), data, options
end
Expand Down

0 comments on commit 21b55c8

Please sign in to comment.