cloudamatic/mu

View on GitHub

Showing 255 of 2,705 total issues

Method getStockImage has a Cognitive Complexity of 80 (exceeds 75 allowed). Consider refactoring.
Open

    def self.getStockImage(cloud = MU::Config.defaultCloud, platform: nil, region: nil, fail_hard: false, quiet: false)

      if !MU::Cloud.supportedClouds.include?(cloud)
        MU.log "'#{cloud}' is not a supported cloud provider! Available providers:", MU::ERR, details: MU::Cloud.supportedClouds
        raise MuError, "'#{cloud}' is not a supported cloud provider!"
Severity: Minor
Found in modules/mu/cloud/machine_images.rb - About 1 hr 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

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

        def self.schema(_config)
          toplevel_required = []

          schema = {
            "disabled" => {
Severity: Major
Found in modules/mu/providers/aws/cdn.rb - About 1 hr 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

      Avoid deeply nested control flow statements.
      Open

                          if e.message.match(/Cannot delete an inactive project/)
                            # this is fine
                          else
                            MU.log "Got #{e.message} trying to delete project #{p.project_id} (#{p.name})", MU::ERR
                            next
      Severity: Major
      Found in modules/mu/providers/google/habitat.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            MU.log "Filesystem #{pool.name}: #{pool.file_system_id} already deleted", MU::NOTICE if e.to_s.start_with?("invalid file system ID")
        Severity: Major
        Found in modules/mu/providers/aws/storage_pool.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              raise MuError, "Failed to delete filesystem #{pool.name}: #{pool.file_system_id}, still in use." if attempts >= 6
          Severity: Major
          Found in modules/mu/providers/aws/storage_pool.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                          elsif entitytype == "role"
                            resp = MU::Cloud::AWS.iam(credentials: @credentials).list_attached_role_policies(
                              role_name: entityname
                            )
            
            
            Severity: Major
            Found in modules/mu/providers/aws/role.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      semanage_pkg = if node['platform_version'].to_i < 6
                        "policycoreutils"
                      elsif node['platform_version'].to_i < 8
                        "policycoreutils-python"
                      else
              Severity: Major
              Found in cookbooks/mu-tools/recipes/rsyslog.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                      MU.log "Disabling CloudFront distribution #{my_name ? my_name : ids[my_arn].id})", MU::NOTICE
                Severity: Major
                Found in modules/mu/providers/aws/cdn.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                        if id.match(/:log-group:/)
                                          stream_id = id.sub(/:([^:]+)$/, ":log-stream:*")
                  #                        "arn:aws:logs:us-east-2:accountID:log-group:log_group_name:log-stream:CloudTrail_log_stream_name_prefix*"
                                          statement["Resource"] << stream_id
                                        elsif id.match(/:s3:/)
                  Severity: Major
                  Found in modules/mu/providers/aws/role.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                  if report_data and !report_data.empty?
                                    report ||= {}
                                    report[elt_namestr] = report_data
                                  end
                    Severity: Major
                    Found in modules/mu.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                        return name_only ? "#default" : @@my_hosted_cfg
                      Severity: Major
                      Found in modules/mu/providers/aws.rb - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                            elsif new_args.is_a?(Hash)
                                              new_args[page_markers[paginator]] = new_page
                        Severity: Major
                        Found in modules/mu/providers/aws.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                      MU.log e.message+" - Google admin bucket #{adminBucketName(credentials)}/#{name} with #{credentials ? credentials : "default"} credentials", MU::DEBUG, details: aclobj
                          Severity: Major
                          Found in modules/mu/providers/google.rb - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                              MU.log "External Google user specified with no role binding, will grant 'viewer' in #{my_org ? "organization #{my_org.display_name}" : "project #{user['project']}"}", MU::WARN
                            Severity: Major
                            Found in modules/mu/providers/google/user.rb - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                elsif dnsrec["type"] == "A"
                                                  if public
                                                    # Make sure we have a public IP address to register. Use the private one if we don't
                                                    deploydata['public_ip_address'] ? deploydata['public_ip_address'] : deploydata['private_ip_address']
                                                  else
                              Severity: Major
                              Found in modules/mu/providers/aws/dnszone.rb - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                            raise MuError, "No valid credentials available! Either grant admin privileges to machine service account, or manually add a different one with mu-configure" if found.nil?
                                Severity: Major
                                Found in modules/mu/providers/google.rb - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                  rescue
                                                    MU.log function['code']['zip_file']+" does not contain function.js or index.js, at least one must be present for runtime #{function['runtime']}", MU::ERR
                                                    ok = false
                                  Severity: Major
                                  Found in modules/mu/providers/google/function.rb - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                          if e.message.match(/failedPrecondition/) and retries < max_retries
                                                            sleep 30
                                                            retries += 1
                                                            retry
                                                          else
                                    Severity: Major
                                    Found in modules/mu/providers/google/folder.rb - About 45 mins to fix

                                      Method find has a Cognitive Complexity of 78 (exceeds 75 allowed). Consider refactoring.
                                      Open

                                              def self.find(**args)
                                                credcfg = MU::Cloud::Google.credConfig(args[:credentials])
                                                customer = MU::Cloud::Google.customerID(args[:credentials])
                                                my_org = MU::Cloud::Google.getOrg(args[:credentials])
                                      
                                      
                                      Severity: Minor
                                      Found in modules/mu/providers/google/role.rb - About 45 mins 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

                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language