ManageIQ/kubeclient

View on GitHub

Showing 24 of 26 total issues

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 fetch_context has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def fetch_context(context_name)
            context = @kcfg['contexts'].detect do |x|
              break x['context'] if x['name'] == context_name
            end
      
      
      Severity: Minor
      Found in lib/kubeclient/config.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 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 token has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def token(credentials, eks_cluster, region: 'us-east-1')
                  begin
                    require 'aws-sigv4'
                    require 'base64'
                    require 'cgi'
          Severity: Minor
          Found in lib/kubeclient/aws_eks_credentials.rb - About 1 hr to fix

            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 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 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 each has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def each
                    @finished = false
            
                    @http_client = build_client
                    response = @http_client.request(:get, @uri, build_client_options)
            Severity: Minor
            Found in lib/kubeclient/watch_stream.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 context has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def context(context_name = nil)
                  cluster, user, namespace = fetch_context(context_name || @kcfg['current-context'])
            
                  if user.key?('exec')
                    exec_opts = expand_command_option(user['exec'], 'command')
            Severity: Minor
            Found in lib/kubeclient/config.rb - About 1 hr to fix

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

                  def context(context_name = nil)
                    cluster, user, namespace = fetch_context(context_name || @kcfg['current-context'])
              
                    if user.key?('exec')
                      exec_opts = expand_command_option(user['exec'], 'command')
              Severity: Minor
              Found in lib/kubeclient/config.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 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 watcher_with_timeout has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def watcher_with_timeout
                    watch_options = @options.merge(watch: true, resource_version: @started)
                    @watcher = @client.watch_entities(@resource_name, watch_options)
                    timeout_deadline = Time.now + @reconcile_timeout
                    watcher_finished = false
              Severity: Minor
              Found in lib/kubeclient/informer.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 fetch_user_auth_options has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def fetch_user_auth_options(user)
                    options = {}
                    if user.key?('token')
                      options[:bearer_token] = user['token']
                    elsif user.key?('exec_result') && user['exec_result'].key?('token')
              Severity: Minor
              Found in lib/kubeclient/config.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 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 build_client has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def build_client
                      client = HTTP::Client.new(follow: follow_option)
              
                      if @http_options[:basic_auth_user] && @http_options[:basic_auth_password]
                        client = client.basic_auth(
              Severity: Minor
              Found in lib/kubeclient/watch_stream.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                      def initialize(api_endpoint, api_version, ssl_options, auth_options, namespace)
                Severity: Minor
                Found in lib/kubeclient/config.rb - About 35 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language