cloudamatic/mu

View on GitHub
modules/mu/providers/aws/endpoint.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Assignment Branch Condition size for validateConfig is too high. [155.7/75]
Open

        def self.validateConfig(endpoint, configurator)
          ok = true

          if endpoint['log_requests'] and !endpoint['access_logs']
            logdesc = {

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for toKitten is too high. [150.6/75]
Open

        def toKitten(**_args)
          bok = {
            "cloud" => "AWS",
            "credentials" => @credentials,
            "cloud_id" => @cloud_id,

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for generate_methods is too high. [143.8/75]
Open

        def generate_methods(integrations = true)
          resp = MU::Cloud::AWS.apig(region: @region, credentials: @credentials).get_resources(
            rest_api_id: @cloud_id,
          )
          root_resource = resp.items.first.id

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for groom is too high. [107.2/75]
Open

        def groom
          generate_methods

          deployment = MU::Cloud::AWS.apig(region: @region, credentials: @credentials).get_deployments(
            rest_api_id: @cloud_id

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method schema has 215 lines of code (exceeds 150 allowed). Consider refactoring.
Open

        def self.schema(_config)
          toplevel_required = []
          schema = {
            "domain_names" => {
              "type" => "array",
Severity: Major
Found in modules/mu/providers/aws/endpoint.rb - About 3 hrs to fix

    Method has too many lines. [215/200]
    Open

            def self.schema(_config)
              toplevel_required = []
              schema = {
                "domain_names" => {
                  "type" => "array",

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method toKitten has a Cognitive Complexity of 88 (exceeds 75 allowed). Consider refactoring.
    Open

            def toKitten(**_args)
              bok = {
                "cloud" => "AWS",
                "credentials" => @credentials,
                "cloud_id" => @cloud_id,
    Severity: Minor
    Found in modules/mu/providers/aws/endpoint.rb - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Block has too many lines. [124/100]
    Open

              @config['methods'].each { |m|
                m["auth"] ||= m["iam_role"] ? "AWS_IAM" : "NONE"
    
                method_arn = "arn:#{MU::Cloud::AWS.isGovCloud?(@region) ? "aws-us-gov" : "aws"}:execute-api:#{@region}:#{MU::Cloud::AWS.credToAcct(@credentials)}:#{@cloud_id}/*/#{m['type']}/#{m['path']}"
                path_part = ["", "/"].include?(m['path']) ? nil : m['path']

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Cyclomatic complexity for validateConfig is too high. [33/30]
    Open

            def self.validateConfig(endpoint, configurator)
              ok = true
    
              if endpoint['log_requests'] and !endpoint['access_logs']
                logdesc = {

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Block has too many lines. [102/100]
    Open

              resources.each { |r|
                next if !r.respond_to?(:resource_methods) or r.resource_methods.nil?
                r.resource_methods.each_pair { |http_type, m|
                  bok['methods'] ||= []
                  method = {}

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                      if m_desc.method_integration.uri.match(/:lambda:path\/\d{4}-\d{2}-\d{2}\/functions\/arn:.*?:function:(.*?)\/invocations$/)

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                      elsif m_desc.method_integration.uri.match(/#{@region}:([^:]+):action\/(.*)/)

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                          if hdr.match(/^method\.response\.header\.(.*)/)

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use sort_by(&:created_date) instead of sort { |a, b| a.created_date <=> b.created_date }.
    Open

              ).items.sort { |a, b| a.created_date <=> b.created_date }.last

    This cop identifies places where sort { |a, b| a.foo <=> b.foo } can be replaced by sort_by(&:foo). This cop also checks max and min methods.

    Example:

    # bad
    array.sort { |a, b| a.foo <=> b.foo }
    array.max { |a, b| a.foo <=> b.foo }
    array.min { |a, b| a.foo <=> b.foo }
    array.sort { |a, b| a[:foo] <=> b[:foo] }
    
    # good
    array.sort_by(&:foo)
    array.sort_by { |v| v.foo }
    array.sort_by do |var|
      var.foo
    end
    array.max_by(&:foo)
    array.min_by(&:foo)
    array.sort_by { |a| a[:foo] }

    Use sort_by(&:created_date) instead of sort { |a, b| a.created_date <=> b.created_date }.
    Open

              ).items.sort { |a, b| a.created_date <=> b.created_date }.last

    This cop identifies places where sort { |a, b| a.foo <=> b.foo } can be replaced by sort_by(&:foo). This cop also checks max and min methods.

    Example:

    # bad
    array.sort { |a, b| a.foo <=> b.foo }
    array.max { |a, b| a.foo <=> b.foo }
    array.min { |a, b| a.foo <=> b.foo }
    array.sort { |a, b| a[:foo] <=> b[:foo] }
    
    # good
    array.sort_by(&:foo)
    array.sort_by { |v| v.foo }
    array.sort_by do |var|
      var.foo
    end
    array.max_by(&:foo)
    array.min_by(&:foo)
    array.sort_by { |a| a[:foo] }

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

                resp = MU::Cloud::AWS.apig(region: args[:region], credentials: args[:credentials]).get_rest_apis
                if resp and resp.items
                  resp.items.each { |api|
                    found[api.id] = api
                  }
    Severity: Minor
    Found in modules/mu/providers/aws/endpoint.rb and 2 other locations - About 25 mins to fix
    modules/mu/providers/aws/alarm.rb on lines 158..163
    modules/mu/providers/aws/storage_pool.rb on lines 140..145

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 31.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

                  if !dom['unmanaged_name'] and !dom['dns_record']
                    MU.log "API Gateway #{endpoint['name']}: Must specify either unmanaged_name or dns_record in domain_name block", MU::ERR, details: dom
                    ok = false
                  end
    Severity: Minor
    Found in modules/mu/providers/aws/endpoint.rb and 1 other location - About 15 mins to fix
    modules/mu/config/notifier.rb on lines 62..65

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 26.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    end at 145, 14 is not aligned with if at 134, 26.
    Open

                  end

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    end at 262, 14 is not aligned with if at 258, 36.
    Open

                  end

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Useless assignment to variable - stage.
    Open

                stage = MU::Cloud::AWS.apig(region: @region, credentials: @credentials).update_stage(

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Useless assignment to variable - cert_domains. Use _ or _cert_domains as a variable name to indicate that it won't be used.
    Open

                    cert_arn, cert_domains = MU::Cloud::AWS.resolveSSLCertificate(dom['certificate'], region: dom['region'], credentials: dom['credentials'])

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    end at 75, 12 is not aligned with if at 53, 19.
    Open

                end

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Unused block argument - log_desc. If it's necessary, use _ or _log_desc as an argument name to indicate that it won't be used.
    Open

                    logs.each_pair { |log_id, log_desc|

    This cop checks for unused block arguments.

    Example:

    # bad
    
    do_something do |used, unused|
      puts used
    end
    
    do_something do |bar|
      puts :foo
    end
    
    define_method(:foo) do |bar|
      puts :baz
    end

    Example:

    #good
    
    do_something do |used, _unused|
      puts used
    end
    
    do_something do
      puts :foo
    end
    
    define_method(:foo) do |_bar|
      puts :baz
    end

    end at 255, 14 is not aligned with if at 251, 24.
    Open

                  end

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Do not suppress exceptions.
    Open

                rescue Aws::APIGateway::Errors::ConflictException

    This cop checks for rescue blocks with no body.

    Example:

    # bad
    
    def some_method
      do_something
    rescue
      # do nothing
    end

    Example:

    # bad
    
    begin
      do_something
    rescue
      # do nothing
    end

    Example:

    # good
    
    def some_method
      do_something
    rescue
      handle_exception
    end

    Example:

    # good
    
    begin
      do_something
    rescue
      handle_exception
    end

    Unused block argument - m. If it's necessary, use _ or _m as an argument name to indicate that it won't be used.
    Open

                r.resource_methods.each_pair { |http_type, m|

    This cop checks for unused block arguments.

    Example:

    # bad
    
    do_something do |used, unused|
      puts used
    end
    
    do_something do |bar|
      puts :foo
    end
    
    define_method(:foo) do |bar|
      puts :baz
    end

    Example:

    #good
    
    do_something do |used, _unused|
      puts used
    end
    
    do_something do
      puts :foo
    end
    
    define_method(:foo) do |_bar|
      puts :baz
    end

    Useless assignment to variable - deployment.
    Open

                deployment = MU::Cloud::AWS.apig(region: @region, credentials: @credentials).create_deployment(

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    There are no issues that match your filters.

    Category
    Status