cloudamatic/mu

View on GitHub
modules/mu/providers/azure/server.rb

Summary

Maintainability
D
1 day
Test Coverage

Assignment Branch Condition size for create_update is too high. [224.1/75]
Open

        def create_update
          ipcfg = MU::Cloud::Azure.network(:NetworkInterfaceIPConfiguration).new
          ipcfg.name = @mu_name
          ipcfg.private_ipallocation_method = MU::Cloud::Azure.network(:IPAllocationMethod)::Dynamic

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 validateConfig is too high. [89.11/75]
Open

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

          server['region'] ||= MU::Cloud::Azure.myRegion(server['credentials'])
          server['ssh_user'] ||= "muadmin"

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

Class Server has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

      class Server < MU::Cloud::Server

        # Initialize this cloud resource object. Calling +super+ will invoke the initializer defined under {MU::Cloud}, which should set the attribtues listed in {MU::Cloud::PUBLIC_ATTRS} as well as applicable dependency shortcuts, like <tt>@vpc</tt>, for us.
        # @param args [Hash]: Hash of named arguments passed via Ruby's double-splat
        def initialize(**args)
Severity: Minor
Found in modules/mu/providers/azure/server.rb - About 3 hrs to fix

    Method create_update has 151 lines of code (exceeds 150 allowed). Consider refactoring.
    Open

            def create_update
              ipcfg = MU::Cloud::Azure.network(:NetworkInterfaceIPConfiguration).new
              ipcfg.name = @mu_name
              ipcfg.private_ipallocation_method = MU::Cloud::Azure.network(:IPAllocationMethod)::Dynamic
    
    
    Severity: Major
    Found in modules/mu/providers/azure/server.rb - About 1 hr to fix

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

                        next if type.match(/_Promo$/i)

      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 image_id.match(/\/Subscriptions\/[^\/]+\/Providers\/Microsoft.Compute\/Locations\/([^\/]+)\/Publishers\/([^\/]+)\/ArtifactTypes\/VMImage\/Offers\/([^\/]+)\/Skus\/([^\/]+)\/Versions\/([^\/]+)$/)

      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 v.match(/^#{Regexp.quote(version)}/)

      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

                      disk['device'].match(/([a-z])[^a-z]*$/i)

      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

                @config['image_id'].match(/\/Subscriptions\/[^\/]+\/Providers\/Microsoft.Compute\/Locations\/[^\/]+\/Publishers\/([^\/]+)\/ArtifactTypes\/VMImage\/Offers\/([^\/]+)\/Skus\/([^\/]+)\/Versions\/([^\/]+)$/)

      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 e.message.match(/InvalidParameter: /)

      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'

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

                if args[:cloud_id]
                  id_str = args[:cloud_id].is_a?(MU::Cloud::Azure::Id) ? args[:cloud_id].name : args[:cloud_id]
                  resource_groups.each { |rg|
                    begin
                      resp = MU::Cloud::Azure.compute(credentials: args[:credentials]).virtual_machines.get(rg, id_str)
      Severity: Major
      Found in modules/mu/providers/azure/server.rb and 1 other location - About 3 hrs to fix
      modules/mu/providers/azure/firewall_rule.rb on lines 291..309

      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 108.

      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

                cloud_desc.network_profile.network_interfaces.each { |iface|
                  iface_id = Id.new(iface.is_a?(Hash) ? iface['id'] : iface.id)
                  iface_desc = MU::Cloud::Azure.network(credentials: @credentials).network_interfaces.get(@resource_group, iface_id.to_s)
                  iface_desc.ip_configurations.each { |ipcfg|
                    ips << ipcfg.private_ipaddress
      Severity: Major
      Found in modules/mu/providers/azure/server.rb and 1 other location - About 1 hr to fix
      modules/mu/providers/azure/server.rb on lines 370..381

      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 75.

      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

                cloud_desc.network_profile.network_interfaces.each { |iface|
                  iface_id = Id.new(iface.is_a?(Hash) ? iface['id'] : iface.id)
                  iface_desc = MU::Cloud::Azure.network(credentials: @credentials).network_interfaces.get(@resource_group, iface_id.to_s)
                  iface_desc.ip_configurations.each { |ipcfg|
                    private_ips << ipcfg.private_ipaddress
      Severity: Major
      Found in modules/mu/providers/azure/server.rb and 1 other location - About 1 hr to fix
      modules/mu/providers/azure/server.rb on lines 402..413

      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 75.

      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 MU::Cloud.resourceClass("Azure", "VPC").haveRouteToInstance?(cloud_desc, credentials: @config['credentials']) or public_ips.size == 0
                  @config['canonical_ip'] = private_ips.first
                  return private_ips.first
                else
                  @config['canonical_ip'] = public_ips.first
      Severity: Minor
      Found in modules/mu/providers/azure/server.rb and 1 other location - About 35 mins to fix
      modules/mu/providers/google/server.rb on lines 995..1001

      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 36.

      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

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

                    if nat_ssh_user.nil? and !nat_ssh_host.nil?
                      MU.log "#{@config["name"]} (#{MU.deploy_id}) is configured to use #{@config['vpc']} NAT #{nat_ssh_host}, but username isn't specified. Guessing root.", MU::ERR, details: caller
                      nat_ssh_user = "root"
                    end
      Severity: Minor
      Found in modules/mu/providers/azure/server.rb and 2 other locations - About 35 mins to fix
      modules/mu/providers/aws/server.rb on lines 440..443
      modules/mu/providers/google/server.rb on lines 503..506

      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 35.

      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 img_cfg['image_then_destroy']
                    MU.log "Image #{image_id} ready, removing source node #{node}"
                    MU::Cloud::Azure.compute(credentials: @config['credentials']).delete_instance(
                      @project_id,
                      @config['availability_zone'],
      Severity: Minor
      Found in modules/mu/providers/azure/server.rb and 1 other location - About 25 mins to fix
      modules/mu/providers/google/server.rb on lines 856..865

      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 30.

      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

                      {
                        "key_is" => "platform",
                        "value_is" => "windows",
                        "set" => "muadmin"
                      },
      Severity: Minor
      Found in modules/mu/providers/azure/server.rb and 1 other location - About 25 mins to fix
      modules/mu/config/server.rb on lines 433..451

      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 29.

      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

      Unused method argument - image_id. If it's necessary, use _ or _image_id as an argument name to indicate that it won't be used. You can also write as imageTimeStamp(*) if you want the method to accept any arguments but don't care about them.
      Open

              def self.imageTimeStamp(image_id, credentials: nil)

      This cop checks for unused method arguments.

      Example:

      # bad
      
      def some_method(used, unused, _unused_but_allowed)
        puts used
      end

      Example:

      # good
      
      def some_method(used, _unused, _unused_but_allowed)
        puts used
      end

      Unused method argument - credentials. You can also write as imageTimeStamp(*) if you want the method to accept any arguments but don't care about them.
      Open

              def self.imageTimeStamp(image_id, credentials: nil)

      This cop checks for unused method arguments.

      Example:

      # bad
      
      def some_method(used, unused, _unused_but_allowed)
        puts used
      end

      Example:

      # good
      
      def some_method(used, _unused, _unused_but_allowed)
        puts used
      end

      Redundant use of Object#to_s in interpolation.
      Open

                    raise MuError, "Failed to locate subnet #{@config['vpc']['subnet_id']} in VPC #{@vpc.to_s}"

      This cop checks for string conversion in string interpolation, which is redundant.

      Example:

      # bad
      
      "result is #{something.to_s}"

      Example:

      # good
      
      "result is #{something}"

      Redundant use of Object#to_s in interpolation.
      Open

                    raise MuError, "Server #{@mu_name} wanted a private subnet, but there are none in #{@vpc.to_s}"

      This cop checks for string conversion in string interpolation, which is redundant.

      Example:

      # bad
      
      "result is #{something.to_s}"

      Example:

      # good
      
      "result is #{something}"

      Redundant use of Object#to_s in interpolation.
      Open

                    raise MuError, "Server #{@mu_name} wanted a public subnet, but there are none in #{@vpc.to_s}"

      This cop checks for string conversion in string interpolation, which is redundant.

      Example:

      # bad
      
      "result is #{something.to_s}"

      Example:

      # good
      
      "result is #{something}"

      end at 231, 10 is not aligned with if at 225, 28.
      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 736, 10 is not aligned with if at 712, 20.
      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 59, 10 is not aligned with if at 35, 22.
      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 MU::Cloud::Azure::APIError

      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 method argument - hard. If it's necessary, use _ or _hard as an argument name to indicate that it won't be used. You can also write as reboot(*) if you want the method to accept any arguments but don't care about them.
      Open

              def reboot(hard = false)

      This cop checks for unused method arguments.

      Example:

      # bad
      
      def some_method(used, unused, _unused_but_allowed)
        puts used
      end

      Example:

      # good
      
      def some_method(used, _unused, _unused_but_allowed)
        puts used
      end

      Useless assignment to variable - ssh_keydir.
      Open

                ssh_keydir = Etc.getpwuid(Process.uid).dir+"/.ssh"

      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 856, 14 is not aligned with if at 848, 20.
      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)

      There are no issues that match your filters.

      Category
      Status