ManageIQ/manageiq-api

View on GitHub

Showing 90 of 90 total issues

Cyclomatic complexity for run is too high. [52/11]
Open

def run
data = ""
params = {}
 
opts = Optimist.options do
Severity: Minor
Found in exe/manageiq-api by rubocop

Similar blocks of code found in 2 locations. Consider refactoring.
Open

module Subcollections
module SecurityPolicies
def security_policies_query_resource(object)
object.try(:security_policies) || []
end
Severity: Major
Found in app/controllers/api/subcollections/security_policies.rb and 1 other location - About 2 hrs to fix
app/controllers/api/subcollections/security_policy_rules.rb on lines 2..29

Similar blocks of code found in 2 locations. Consider refactoring.
Open

module Subcollections
module SecurityPolicyRules
def security_policy_rules_query_resource(object)
object.try(:security_policy_rules) || []
end
Severity: Major
Found in app/controllers/api/subcollections/security_policy_rules.rb and 1 other location - About 2 hrs to fix
app/controllers/api/subcollections/security_policies.rb on lines 2..29

Method parse_filter has a Cognitive Complexity of 23 (exceeds 11 allowed). Consider refactoring.
Open

def parse_filter(filter)
logical_or = filter.gsub!(/^or /i, '').present?
filter_field, operator, filter_value = split_filter_string(filter)
methods = OPERATORS[operator]
 
 
Severity: Minor
Found in lib/api/filter.rb - About 2 hrs to fix

Method determine_include_for_find has a Cognitive Complexity of 22 (exceeds 11 allowed). Consider refactoring.
Open

def determine_include_for_find(klass)
attrs = virtual_attributes_for(klass) do |type, attr_name, attr_base|
if klass.virtual_includes(attr_name) && !klass.attribute_supported_by_sql?(attr_name) && attr_base.blank?
attr_name
else
Severity: Minor
Found in app/controllers/api/base_controller/renderer.rb - About 2 hrs to fix

Cyclomatic complexity for parse_filter is too high. [14/11]
Open

def parse_filter(filter)
logical_or = filter.gsub!(/^or /i, '').present?
filter_field, operator, filter_value = split_filter_string(filter)
methods = OPERATORS[operator]
 
 
Severity: Minor
Found in lib/api/filter.rb by rubocop

Method normalize_hash has a Cognitive Complexity of 21 (exceeds 11 allowed). Consider refactoring.
Open

def normalize_hash(type, obj, opts = {})
Environment.fetch_encrypted_attribute_names(obj.class)
attrs = normalize_select_attributes(obj, opts)
result = {}
 
 
Severity: Minor
Found in app/controllers/api/base_controller/normalizer.rb - About 1 hr to fix

Cyclomatic complexity for normalize_attr is too high. [13/11]
Open

def normalize_attr(attr, value)
return if value.nil?
if value.kind_of?(Array) || value.kind_of?(ActiveRecord::Relation)
normalize_array(value)
elsif value.respond_to?(:attributes) || value.respond_to?(:keys)

Cyclomatic complexity for edit_resource is too high. [13/11]
Open

def edit_resource(type, id, data)
resource = resource_search(id, type)
 
allowed_params = %w[description credentials]
allowed_params += %w[name payload payload_type] if resource.configuration_script_source.nil?

Cyclomatic complexity for determine_include_for_find is too high. [12/11]
Open

def determine_include_for_find(klass)
attrs = virtual_attributes_for(klass) do |type, attr_name, attr_base|
if klass.virtual_includes(attr_name) && !klass.attribute_supported_by_sql?(attr_name) && attr_base.blank?
attr_name
else

Similar blocks of code found in 2 locations. Consider refactoring.
Open

def assign_resource(type, id, data)
profile = resource_search(id, type)
data['resources'].each do |resource|
raise 'Must specify resource href' unless resource.key?('href')
href = Href.new(resource['href'])
Severity: Major
Found in app/controllers/api/alert_definition_profiles_controller.rb and 1 other location - About 1 hr to fix
app/controllers/api/alert_definition_profiles_controller.rb on lines 43..58

Similar blocks of code found in 2 locations. Consider refactoring.
Open

def unassign_resource(type, id, data)
profile = resource_search(id, type)
data['resources'].each do |resource|
raise 'Must specify resource href' unless resource.key?('href')
href = Href.new(resource['href'])
Severity: Major
Found in app/controllers/api/alert_definition_profiles_controller.rb and 1 other location - About 1 hr to fix
app/controllers/api/alert_definition_profiles_controller.rb on lines 26..41

Method collection_to_jbuilder has a Cognitive Complexity of 19 (exceeds 11 allowed). Consider refactoring.
Open

def collection_to_jbuilder(type, reftype, resources, opts = {})
link_builder = Api::LinksBuilder.new(params, @req.url, opts[:counts])
Jbuilder.new do |json|
json.set! 'name', opts[:name] if opts[:name]
 
 
Severity: Minor
Found in app/controllers/api/base_controller/renderer.rb - About 1 hr to fix

Method gen_action_spec_for_collections has a Cognitive Complexity of 17 (exceeds 11 allowed). Consider refactoring.
Open

def gen_action_spec_for_collections(collection, cspec, is_subcollection, href)
if is_subcollection
target = :subcollection_actions
cspec_target = collection_config.typed_subcollection_actions(@req.collection, collection) || cspec[target]
else
Severity: Minor
Found in app/controllers/api/base_controller/renderer.rb - About 1 hr to fix

Similar blocks of code found in 2 locations. Consider refactoring.
Open

def security_groups_remove_resource(parent, _type, _id, data)
security_group = data["name"]
raise "Cannot remove #{security_group} from #{parent.name}" unless parent.supports?(:remove_security_group)
 
message = "Removing security group #{security_group} from #{parent.name}"
Severity: Major
Found in app/controllers/api/subcollections/security_groups.rb and 1 other location - About 1 hr to fix
app/controllers/api/subcollections/security_groups.rb on lines 8..17

Similar blocks of code found in 2 locations. Consider refactoring.
Open

def security_groups_add_resource(parent, _type, _id, data)
security_group = data["name"]
raise "Cannot add #{security_group} to #{parent.name}" unless parent.supports?(:add_security_group)
 
message = "Adding security group #{security_group} to #{parent.name}"
Severity: Major
Found in app/controllers/api/subcollections/security_groups.rb and 1 other location - About 1 hr to fix
app/controllers/api/subcollections/security_groups.rb on lines 19..28

Method import_resource has a Cognitive Complexity of 15 (exceeds 11 allowed). Consider refactoring.
Open

def import_resource(_type, _id, data = {})
params = %w[dst_provider_id src_provider_id src_image_id]
raise BadRequestError, "Parameter 'data' has to contain non-empty values for the keys '#{params.join(", ")}', received: '#{data.to_json}'" if data.values_at(*params).any?(&:blank?)
raise BadRequestError, "Source and destination provider identifiers must differ" if data['dst_provider_id'] == data['src_provider_id']
 
 
Severity: Minor
Found in app/controllers/api/cloud_templates_controller.rb - About 55 mins to fix

Method gen_action_spec_for_resources has a Cognitive Complexity of 15 (exceeds 11 allowed). Consider refactoring.
Open

def gen_action_spec_for_resources(cspec, is_subcollection, href, resource)
if is_subcollection
target = :subresource_actions
cspec_target = cspec[target] || collection_config.typed_subcollection_actions(@req.collection, @req.subcollection, :subresource)
else
Severity: Minor
Found in app/controllers/api/base_controller/renderer.rb - About 55 mins to fix

Method virtual_attribute_search has a Cognitive Complexity of 15 (exceeds 11 allowed). Consider refactoring.
Open

def virtual_attribute_search(resource, attribute)
if resource.class < ApplicationRecord
rbac = Rbac::Filterer.new
# is relation in 'attribute' variable plural in the model class (from 'resource.class') ?
if [:has_many, :has_and_belongs_to_many].include?(resource.class.reflection_with_virtual(attribute).try(:macro))
Severity: Minor
Found in app/controllers/api/base_controller/renderer.rb - About 55 mins to fix

Method edit_resource has a Cognitive Complexity of 15 (exceeds 11 allowed). Consider refactoring.
Open

def edit_resource(type, id, data)
resource = resource_search(id, type)
 
allowed_params = %w[description credentials]
allowed_params += %w[name payload payload_type] if resource.configuration_script_source.nil?
Severity: Minor
Found in app/controllers/api/configuration_script_payloads_controller.rb - About 55 mins to fix
Severity
Category
Status
Source
Language