mongodb/mongo-ruby-driver

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

Summary

Maintainability
B
5 hrs
Test Coverage

Method ec2_metadata_credentials has 36 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 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

    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

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

              def prepare_web_identity_inputs
                token_file = ENV['AWS_WEB_IDENTITY_TOKEN_FILE']
                role_arn = ENV['AWS_ROLE_ARN']
                if token_file.nil? || role_arn.nil?
                  return nil
      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

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

              def credentials
                credentials = credentials_from_user(user)
                return credentials unless credentials.nil?
      
                credentials = credentials_from_environment
      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