Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Style/CaseLikeIf cop #11047

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,16 @@ def create_manifest

def get_manifest_files(repository, manifest)
files = ['manifest.json']
if manifest['schemaVersion'] == 1
case manifest['schemaVersion']
when 1
if manifest['fsLayers']
files += manifest['fsLayers'].collect do |layer|
layerfile = "#{layer['blobSum'][7..-1]}.tar"
force_include_layer(repository, layer['blobSum'], layerfile)
layerfile
end
end
elsif manifest['schemaVersion'] == 2
when 2
if manifest['layers']
files += manifest['layers'].collect do |layer|
layerfile = "#{layer['digest'][7..-1]}.tar"
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/katello/api/v2/debs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def auto_complete(search)
page_size = Katello::Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
debs = Deb.in_repositories(@repositories)
col = ''
if search == 'name'
case search
when 'name'
col = "#{Deb.table_name}.name"
elsif search == 'arch'
when 'arch'
col = "#{Deb.table_name}.architecture"
end
debs = debs.where("#{col} ILIKE ?", "#{params[:term]}%").select(col).group(col).order(col).limit(page_size)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/katello/concerns/api/v2/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ def param_ids_missing(param_ids, filtered_ids)
def find_param_arrays(hash = params)
list_of_paths = []
hash.each do |key, value|
if value.is_a?(ActionController::Parameters) || value.is_a?(Hash)
case value
when ActionController::Parameters, Hash
list_of_paths += find_param_arrays(value).compact.map { |inner_keys| [key] + inner_keys }
elsif value.is_a?(Array)
when Array
list_of_paths << [key]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ def default_sort
end

def sort_options
if default_sort.is_a?(Array)
case default_sort
when Array
return [default_sort[0], default_sort[1], {}]
elsif default_sort.is_a?(Proc)
when Proc
return [nil, nil, { :custom_sort => default_sort }]
else
fail "Unsupported default_sort type"
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/katello/hosts_and_hostgroups_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ def content_options(host, selected_id, object_type, options = {})
all_options = []
orgs.each do |org|
content_object_options = ""
accessible_content_objects = if object_type == :lifecycle_environment
accessible_content_objects = case object_type
when :lifecycle_environment
accessible_lifecycle_environments(org, host)
elsif object_type == :content_source
when :content_source
accessible_content_proxies(host)
end
accessible_content_objects.each do |content_object|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ def pulp3_content_mapping(content)
::Katello::Rpm.with_identifiers(content[:package_ids])
unit_map = { :errata => [], :rpms => [] }
units.each do |unit|
if unit.class.name == "Katello::Erratum"
case unit.class.name
when "Katello::Erratum"
unit_map[:errata] << unit.id
elsif unit.class.name == "Katello::Rpm"
when "Katello::Rpm"
unit_map[:rpms] << unit.id
end
end
Expand Down
5 changes: 3 additions & 2 deletions app/lib/actions/middleware/backend_services_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def plan(*args)
def capsule_id(args)
capsule_id = nil
args.each do |arg|
if arg.is_a? SmartProxy
case arg
when SmartProxy
capsule_id = arg.id
elsif arg.is_a? Hash
when Hash
capsule_id = arg[:capsule_id] || arg[:smart_proxy_id]
end
break if capsule_id
Expand Down
5 changes: 3 additions & 2 deletions app/lib/katello/resources/cdn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ def http_downloader
# very old infrastructure for now, but that was considered better than having an insecure default.
net.min_version = OpenSSL::SSL::TLS1_2_VERSION

if (@options[:verify_ssl] == false) || (@options[:verify_ssl] == OpenSSL::SSL::VERIFY_NONE)
case @options[:verify_ssl]
when false, OpenSSL::SSL::VERIFY_NONE
net.verify_mode = OpenSSL::SSL::VERIFY_NONE
elsif @options[:verify_ssl].is_a? Integer
when Integer
net.verify_mode = @options[:verify_ssl]
net.verify_callback = lambda do |preverify_ok, ssl_context|
if !preverify_ok || ssl_context.error != 0
Expand Down
5 changes: 3 additions & 2 deletions app/lib/katello/util/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def self.ostructize(obj, options = {})
options[:prefix_keys] ||= []
options[:prefix] ||= '_'

if obj.is_a? Hash
case obj
when Hash

ostructized_hash = {}
obj.each do |key, value|
Expand All @@ -31,7 +32,7 @@ def self.ostructize(obj, options = {})
end
return OpenStruct.new ostructized_hash

elsif obj.is_a? Array
when Array

return obj.map { |r| ostructize(r, options) }

Expand Down
7 changes: 4 additions & 3 deletions app/lib/katello/util/errata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ def filter_by_type(errata_list, filter_type)

def get_pulp_filter_type(type)
filter_type = type.downcase
if filter_type == "bugfix"
case filter_type
when "bugfix"
return ::Katello::Erratum::BUGZILLA
elsif filter_type == "enhancement"
when "enhancement"
return ::Katello::Erratum::ENHANCEMENT
elsif filter_type == "security"
when "security"
return ::Katello::Erratum::SECURITY
end
end
Expand Down
5 changes: 3 additions & 2 deletions app/lib/katello/util/report_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def rename_column(original, new)
end

def as(type)
if type == :csv
case type
when :csv
as_csv(transform_data)
elsif type == :text
when :text
as_text(transform_data)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module Validators
class AlternateContentSourcePathValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value
if attribute == :base_url
case attribute
when :base_url
unless AlternateContentSourcePathValidator.validate_base_url(value)
record.errors[attribute] << N_("%s is not a valid path") % value
end
elsif attribute == :subpaths
when :subpaths
unless AlternateContentSourcePathValidator.validate_subpaths(value)
record.errors[attribute] << N_('All subpaths must have a slash at the end and none at the front')
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ def pulp3_configuration(config_class)
end

def pulp3_ssl_configuration(config, connection_adapter = Faraday.default_adapter)
if connection_adapter == :excon
case connection_adapter
when :excon
config.ssl_client_cert = ::Cert::Certs.ssl_client_cert_filename
config.ssl_client_key = ::Cert::Certs.ssl_client_key_filename
elsif connection_adapter == :net_http
when :net_http
config.ssl_client_cert = ::Cert::Certs.ssl_client_cert
config.ssl_client_key = ::Cert::Certs.ssl_client_key
else
Expand Down
5 changes: 3 additions & 2 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,10 @@ def product_type
def content_counts
content_counts = {}
RepositoryTypeManager.defined_repository_types[content_type].content_types_to_index.each do |content_type|
if content_type&.model_class::CONTENT_TYPE == DockerTag::CONTENT_TYPE
case content_type&.model_class::CONTENT_TYPE
when DockerTag::CONTENT_TYPE
content_counts[DockerTag::CONTENT_TYPE] = docker_tags.count
elsif content_type&.model_class::CONTENT_TYPE == GenericContentUnit::CONTENT_TYPE
when GenericContentUnit::CONTENT_TYPE
content_counts[content_type.content_type] = content_type&.model_class&.in_repositories(self)&.where(:content_type => content_type.content_type)&.count
else
content_counts[content_type.label] = content_type&.model_class&.in_repositories(self)&.count
Expand Down
9 changes: 5 additions & 4 deletions app/models/katello/sync_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,14 @@ def add_recurring_logic_to_sync_plan(sync_date, interval, cron_expression)
if interval.nil?
fail _("Interval cannot be nil")
end
if (interval.downcase.eql? "hourly")
case interval.downcase
when "hourly"
cron = min.to_s + " * * * *"
elsif (interval.downcase.eql? "daily")
when "daily"
cron = min.to_s + " " + hour.to_s + " * * *"
elsif (interval.downcase.eql? "weekly")
when "weekly"
cron = min.to_s + " " + hour.to_s + " * * " + day.to_s
elsif (interval.downcase.eql? CUSTOM_CRON)
when CUSTOM_CRON
cron = cron_expression
else
fail _("Interval not set correctly")
Expand Down
14 changes: 8 additions & 6 deletions app/models/katello/task_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ def generate_description
ret = []
task_type = self.task_type.to_s

if task_type =~ /^package_group/
case task_type
when /^package_group/
action = task_type.include?("remove") ? :removed : :installed
ret = packages_change_description(result[:details][:package_group], action)
elsif task_type == "package_install" || task_type == "errata_install"
when "package_install", "errata_install"
ret = packages_change_description(result[:details][:rpm], :installed)
elsif task_type == "package_update"
when "package_update"
ret = packages_change_description(result[:details][:rpm], :updated)
elsif task_type == "package_remove"
when "package_remove"
ret = packages_change_description(result[:details][:rpm], :removed)
end
ret
Expand All @@ -246,13 +247,14 @@ def rmi_error_description
errors, stacktrace = self.result[:errors]
return "" unless errors
# Handle not very friendly Pulp message
if errors =~ /^\(.*\)$/
case errors
when /^\(.*\)$/
if stacktrace.class == Array
stacktrace.last.split(":").first
else
stacktrace.split("(").first
end
elsif errors =~ /^\[.*,.*\]$/m
when /^\[.*,.*\]$/m
result = errors.split(",").map do |error|
error.gsub(/^\W+|\W+$/, "")
end
Expand Down
22 changes: 11 additions & 11 deletions app/services/katello/candlepin/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,26 @@ def self.friendly_compliance_reasons(candlepin_reasons)
def self.distribution_to_puppet_os(name)
return ::Operatingsystem::REDHAT_ATOMIC_HOST_OS if name == ::Operatingsystem::REDHAT_ATOMIC_HOST_DISTRO_NAME

name = name.downcase
if name =~ /red\s*hat/
case name.downcase
when /red\s*hat/
'RedHat'
elsif name =~ /centos/
when /centos/
'CentOS'
elsif name =~ /fedora/
when /fedora/
'Fedora'
elsif name =~ /sles/ || name =~ /suse.*enterprise.*/
when /sles/, /suse.*enterprise.*/
'SLES'
elsif name =~ /debian/
when /debian/
'Debian'
elsif name =~ /ubuntu/
when /ubuntu/
'Ubuntu'
elsif name =~ /oracle/
when /oracle/
'OracleLinux'
elsif name =~ /almalinux/
when /almalinux/
'AlmaLinux'
elsif name =~ /rocky/
when /rocky/
'Rocky'
elsif name =~ /amazon/
when /amazon/
'Amazon'
else
'Unknown'
Expand Down
5 changes: 3 additions & 2 deletions app/services/katello/candlepin/message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def consumer_uuid
end

def pool_id
if subject == 'pool.created' || subject == 'pool.deleted'
case subject
when 'pool.created', 'pool.deleted'
content['entityId']
elsif subject == 'entitlement.created' || subject == 'entitlement.deleted'
when 'entitlement.created', 'entitlement.deleted'
content['referenceId']
end
end
Expand Down
10 changes: 6 additions & 4 deletions app/services/katello/pulp3/content_view_version/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ def repository_mapping(content_view_version)
end

def import_cv_name_from_export(name:, generated_for:)
if generated_for == :library_import
case generated_for
when :library_import
::Katello::ContentView::IMPORT_LIBRARY
elsif generated_for == :repository_import
when :repository_import
name.gsub(/^Export/, 'Import')
else
name
Expand Down Expand Up @@ -138,9 +139,10 @@ def import_content_view_params
}
end

if generated_for == :library_export
case generated_for
when :library_export
generated_for = :library_import
elsif generated_for == :repository_export
when :repository_export
generated_for = :repository_import
end

Expand Down
5 changes: 3 additions & 2 deletions app/services/katello/pulp3/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def started?
end

def error
if task_data[:state] == CANCELED
case task_data[:state]
when CANCELED
_("Task canceled")
elsif task_data[:state] == FAILED
when FAILED
if task_data[:error][:description].blank?
_("Pulp task error")
else
Expand Down
5 changes: 3 additions & 2 deletions test/support/auth_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ def setup_user_with_permissions(permissions, user, organizations: [], locations:
user.update!(organizations: organizations) unless organizations.blank?
user.update!(locations: locations) unless locations.blank?

actual_permissions = if permissions.is_a?(Hash)
actual_permissions = case permissions
when Hash
[permissions]
elsif permissions.is_a?(Array)
when Array
permissions.collect do |perm|
if perm.is_a?(Hash)
perm
Expand Down
Loading