mongodb/mongo-ruby-driver

View on GitHub
lib/mongo/auth/aws/credentials_retriever.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method ec2_metadata_credentials has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def ec2_metadata_credentials
          http = Net::HTTP.new('169.254.169.254')
          req = Net::HTTP::Put.new('/latest/api/token',
            # The TTL is required in order to obtain the metadata token.
            {'x-aws-ec2-metadata-token-ttl-seconds' => '30'})
Severity: Minor
Found in lib/mongo/auth/aws/credentials_retriever.rb - About 1 hr to fix

    Method credentials has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def credentials
              if user
                credentials = Credentials.new(
                  user.name,
                  user.password,
    Severity: Minor
    Found in lib/mongo/auth/aws/credentials_retriever.rb - About 1 hr to fix

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

              def ec2_metadata_credentials
                http = Net::HTTP.new('169.254.169.254')
                req = Net::HTTP::Put.new('/latest/api/token',
                  # The TTL is required in order to obtain the metadata token.
                  {'x-aws-ec2-metadata-token-ttl-seconds' => '30'})
      Severity: Minor
      Found in lib/mongo/auth/aws/credentials_retriever.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 credentials_valid? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

              def credentials_valid?(credentials, source)
                unless credentials.access_key_id || credentials.secret_access_key ||
                  credentials.session_token
                then
                  return false
      Severity: Minor
      Found in lib/mongo/auth/aws/credentials_retriever.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 credentials has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

              def credentials
                if user
                  credentials = Credentials.new(
                    user.name,
                    user.password,
      Severity: Minor
      Found in lib/mongo/auth/aws/credentials_retriever.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

      Avoid too many return statements within this method.
      Open

                return nil
      Severity: Major
      Found in lib/mongo/auth/aws/credentials_retriever.rb - About 30 mins to fix

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

                def ecs_metadata_credentials
                  relative_uri = ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']
                  if relative_uri.nil? || relative_uri.empty?
                    return nil
                  end
        Severity: Minor
        Found in lib/mongo/auth/aws/credentials_retriever.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