NexusSW/lxd-common

View on GitHub

Showing 36 of 36 total issues

Method update_container has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

          def update_container(container_name, container_options)
            raise NexusSW::LXD::RestAPI::Error::NotFound, "Container (#{container_name}) does not exist" unless container_exists? container_name
            configs = container_options[:config]
            devices = container_options[:devices]
            profiles = container_options[:profiles]
Severity: Minor
Found in lib/nexussw/lxd/driver/mixins/cli.rb - About 1 day 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 execute_chunked has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

          def execute_chunked(command, options, &block)
            NIO::WebSocket::Reactor.start
            LXD.with_timeout_and_retries options do
              if options[:capture] == :interactive
                if options[:tty] == false
Severity: Minor
Found in lib/nexussw/lxd/transport/mixins/local.rb - About 4 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

Method stop_container has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

          def stop_container(container_id, options = {})
            return if container_status(container_id) == "stopped"
            if options[:force]
              api.stop_container(container_id, force: true)
            else
Severity: Minor
Found in lib/nexussw/lxd/driver/mixins/rest.rb - About 3 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

Method execute_chunked has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

          def execute_chunked(command, options = {}, &block)
            opid = nil
            backchannel = nil
            getlogs = false
            command = runas_command(command, options)
Severity: Minor
Found in lib/nexussw/lxd/transport/mixins/rest.rb - About 3 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

Class RestAPI has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

    class RestAPI
      def initialize(api_options)
        @api_options = api_options
      end

Severity: Minor
Found in lib/nexussw/lxd/rest_api.rb - About 2 hrs to fix

    Method initialize has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

                def initialize(ws_options, baseurl, endpoints, &block)
                  @waitlist = {}
                  @callback = block if block_given?
                  waitlist[:control] = NIO::WebSocket.connect(baseurl + endpoints[:control], ws_options) do |driver|
                    driver.on :io_error do # usually I get an EOF
    Severity: Minor
    Found in lib/nexussw/lxd/transport/mixins/rest.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

    Method symbolize_keys has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.symbolize_keys(hash)
          {}.tap do |retval|
            hash.each do |k, v|
              if %w{config expanded_config}.include? k
                retval[k.to_sym] = v
    Severity: Minor
    Found in lib/nexussw/lxd.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

    Method stop_container has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

              def stop_container(container_id, options = {})
                options ||= {} # default behavior: no timeout or retries.  These functions are up to the consumer's context and not really 'sane' defaults
                return if container_status(container_id) == "stopped"
                return inner_transport.execute("lxc stop #{container_id} --force", capture: false).error! if options[:force]
                LXD.with_timeout_and_retries(options) do
    Severity: Minor
    Found in lib/nexussw/lxd/driver/mixins/cli.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

    Method with_timeout_and_retries has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.with_timeout_and_retries(options = {})
          Timeout.timeout(options[:timeout] || 0) do
            tries = 0
            loop do
              begin
    Severity: Minor
    Found in lib/nexussw/lxd.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

    Method convert_bools has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

          def self.convert_bools(hash)
            {}.tap do |retval|
              hash.each do |k, v|
                if [:ephemeral, :stateful].include? k
                  retval[k] = v
    Severity: Minor
    Found in lib/nexussw/lxd/rest_api.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

    Method execute_chunked has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

              def execute_chunked(command, options = {}, &block)
                opid = nil
                backchannel = nil
                getlogs = false
                command = runas_command(command, options)
    Severity: Minor
    Found in lib/nexussw/lxd/transport/mixins/rest.rb - About 2 hrs to fix

      Method update_container has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                def update_container(container_name, container_options)
                  raise NexusSW::LXD::RestAPI::Error::NotFound, "Container (#{container_name}) does not exist" unless container_exists? container_name
                  configs = container_options[:config]
                  devices = container_options[:devices]
                  profiles = container_options[:profiles]
      Severity: Minor
      Found in lib/nexussw/lxd/driver/mixins/cli.rb - About 1 hr to fix

        Method send_request has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

                def send_request(verb, relative_url, content = nil)
                  fileop = false
                  response = connection.send(verb) do |req|
                    req.url relative_url
                    if content.is_a? Hash
        Severity: Minor
        Found in lib/nexussw/lxd/rest_api/connection.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 remote_for! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                  def remote_for!(url, protocol = "lxd")
                    raise "Protocol is required" unless protocol # protect me from accidentally slipping in a nil
                    # normalize the url and 'require' protocol to protect against a scenario:
                    #   1) user only specifies https://someimageserver.org without specifying the protocol
                    #   2) the rest of this function would blindly add that without saying the protocol
        Severity: Minor
        Found in lib/nexussw/lxd/driver/mixins/cli.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 initialize has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                    def initialize(ws_options, baseurl, endpoints, &block)
                      @waitlist = {}
                      @callback = block if block_given?
                      waitlist[:control] = NIO::WebSocket.connect(baseurl + endpoints[:control], ws_options) do |driver|
                        driver.on :io_error do # usually I get an EOF
        Severity: Minor
        Found in lib/nexussw/lxd/transport/mixins/rest.rb - About 1 hr to fix

          Method execute_chunked has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                    def execute_chunked(command, options, &block)
                      NIO::WebSocket::Reactor.start
                      LXD.with_timeout_and_retries options do
                        if options[:capture] == :interactive
                          if options[:tty] == false
          Severity: Minor
          Found in lib/nexussw/lxd/transport/mixins/local.rb - About 1 hr to fix

            Method chunk_callback has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                      def chunk_callback(stdout, stderr = nil)
                        if stdout
                          NIO::WebSocket::Reactor.queue_task do
                            @mon_out = NIO::WebSocket::Reactor.selector.register(stdout, :r)
                            @mon_out.value = proc do
            Severity: Minor
            Found in lib/nexussw/lxd/transport/mixins/local.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 user has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                        def user(user_nameorid, options = {})
                          return unless user_nameorid
                          passwd = read_file options[:passwd_file] || "/etc/passwd"
            
                          # rework into .split(':') if this gets more complicated
            Severity: Minor
            Found in lib/nexussw/lxd/transport/mixins/helpers/users.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 upload_files_individually has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                        def upload_files_individually(local_path, path)
                          dest = File.join(path, File.basename(local_path))
                          execute("mkdir -p " + dest).error! # for parity with tarball extract
                          Dir.entries(local_path).map { |f| (f == "." || f == "..") ? nil : File.join(local_path, f) }.compact.each do |f|
                            upload_files_individually f, dest if File.directory? f
            Severity: Minor
            Found in lib/nexussw/lxd/transport/mixins/helpers/folder_txfr.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 convert_bools has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                  def self.convert_bools(oldhash)
                    {}.tap do |retval|
                      oldhash.each do |k, v|
                        retval[k] = case v
                                    when "true" then true
            Severity: Minor
            Found in lib/nexussw/lxd/driver.rb - About 55 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