abonas/kubeclient

View on GitHub
lib/kubeclient.rb

Summary

Maintainability
F
3 days
Test Coverage

File kubeclient.rb has 615 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'faraday'
require 'faraday/follow_redirects'
require 'json'
require 'net/http'

Severity: Major
Found in lib/kubeclient.rb - About 1 day to fix

    Class Client has 44 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Client
        ENTITY_METHODS = %w[get watch delete create update patch json_patch merge_patch apply].freeze
    
        DEFAULT_SSL_OPTIONS = {
          client_cert: nil,
    Severity: Minor
    Found in lib/kubeclient.rb - About 6 hrs to fix

      Method define_entity_methods has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def define_entity_methods
            @entities.each_value do |entity|
              # get all entities of a type e.g. get_nodes, get_pods, etc.
              define_singleton_method("get_#{entity.method_names[1]}") do |options = {}|
                get_entities(entity.entity_type, entity.resource_name, options)
      Severity: Minor
      Found in lib/kubeclient.rb - About 1 hr to fix

        Method create_faraday_client has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def create_faraday_client
              url = "#{@api_endpoint}/#{@api_version}"
              options = {
                proxy: @http_proxy_uri,
                request: {
        Severity: Minor
        Found in lib/kubeclient.rb - About 1 hr to fix

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

              def handle_exception
                yield
              rescue Faraday::Error => e
                err_message = build_http_error_message(e)
                response_code = e.response ? (e.response[:status] || e.response&.env&.status) : nil
          Severity: Minor
          Found in lib/kubeclient.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 load_entities has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def load_entities
                @entities = {}
                fetch_entities['resources'].each do |resource|
                  next if resource['name'].include?('/')
                  # Not a regular entity, special functionality covered by `process_template`.
          Severity: Minor
          Found in lib/kubeclient.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 create_faraday_client has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def create_faraday_client
                url = "#{@api_endpoint}/#{@api_version}"
                options = {
                  proxy: @http_proxy_uri,
                  request: {
          Severity: Minor
          Found in lib/kubeclient.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 parse_definition has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.parse_definition(kind, name)
                # Kubernetes gives us 3 inputs:
                #   kind: "ComponentStatus", "NetworkPolicy", "Endpoints"
                #   name: "componentstatuses", "networkpolicies", "endpoints"
                #   singularName: "componentstatus" etc (usually omitted, defaults to kind.downcase)
          Severity: Minor
          Found in lib/kubeclient.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

          Method handle_uri has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle_uri(uri, path)
                raise ArgumentError, 'Missing uri' unless uri
                @api_endpoint = (uri.is_a?(URI) ? uri : URI.parse(uri))
          
                # This regex will anchor at the last `/api`, `/oapi` or`/apis/:group`) part of the URL
          Severity: Minor
          Found in lib/kubeclient.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

          Method configure_impersonation_headers has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def configure_impersonation_headers
                return unless (auth_as = @auth_options[:as])
                @headers[:'Impersonate-User'] = auth_as
                if (as_groups = @auth_options[:as_groups])
                  # Faraday joins multi-value headers with commas, which is not same as having
          Severity: Minor
          Found in lib/kubeclient.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

          Method patch_entity has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def patch_entity(resource_name, name, patch, strategy, namespace)
          Severity: Minor
          Found in lib/kubeclient.rb - About 35 mins to fix

            Method get_pod_log has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_pod_log(
                  pod_name, namespace,
                  container: nil, previous: false,
                  timestamps: false, since_time: nil, tail_lines: nil, limit_bytes: nil
                )
            Severity: Minor
            Found in lib/kubeclient.rb - About 25 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

            Method validate_bearer_token_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def validate_bearer_token_file
                  return unless (file = @auth_options[:bearer_token_file])
                  raise ArgumentError, "Token file #{file} does not exist" unless File.file?(file)
                  raise ArgumentError, "Token file #{file} cannot be read" unless File.readable?(file)
                end
            Severity: Minor
            Found in lib/kubeclient.rb - About 25 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

            There are no issues that match your filters.

            Category
            Status