atlassian/localstack

View on GitHub
localstack/utils/cloudformation/template_deployer.py

Summary

Maintainability
F
3 days
Test Coverage

Function retrieve_resource_details has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

def retrieve_resource_details(resource_id, resource_status, resources, stack_name):
    resource = resources[resource_id]
    resource_id = resource_status.get('PhysicalResourceId') or resource_id
    resource_type = resource_status['ResourceType']
    if not resource:
Severity: Minor
Found in localstack/utils/cloudformation/template_deployer.py - About 7 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

File template_deployer.py has 426 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import yaml
import logging
import traceback
from threading import local
Severity: Minor
Found in localstack/utils/cloudformation/template_deployer.py - About 6 hrs to fix

    Function deploy_resource has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def deploy_resource(resource_id, resources, stack_name):
        resource = resources[resource_id]
        client = get_client(resource)
        if not client:
            return False
    Severity: Minor
    Found in localstack/utils/cloudformation/template_deployer.py - 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

    Function extract_resource_attribute has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def extract_resource_attribute(resource_type, resource, attribute):
        LOGGER.debug('Extract resource attribute: %s %s' % (resource_type, attribute))
        # extract resource specific attributes
        if resource_type == 'Lambda::Function':
            actual_attribute = 'FunctionArn' if attribute == 'Arn' else attribute
    Severity: Minor
    Found in localstack/utils/cloudformation/template_deployer.py - 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

    Function resolve_refs_recursively has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def resolve_refs_recursively(stack_name, value, resources):
        if isinstance(value, dict):
            if len(value) == 1 and 'Ref' in value:
                return resolve_ref(stack_name, value['Ref'],
                    resources, attribute='PhysicalResourceId')
    Severity: Minor
    Found in localstack/utils/cloudformation/template_deployer.py - 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

    Function get_resource_dependencies has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_resource_dependencies(resource_id, resource, resources):
        result = {}
        dumped = json.dumps(common.json_safe(resource))
        for other_id, other in iteritems(resources):
            if resource != other:
    Severity: Minor
    Found in localstack/utils/cloudformation/template_deployer.py - 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

    Function deploy_template has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def deploy_template(template, stack_name):
        if isinstance(template, string_types):
            template = parse_template(template)
    
        if MARKER_DONT_REDEPLOY_STACK in template:
    Severity: Minor
    Found in localstack/utils/cloudformation/template_deployer.py - 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 function.
    Open

                return resource['id']
    Severity: Major
    Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return aws_stack.connect_to_service('apigateway').get_method(restApiId=api_id,
      Severity: Major
      Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return None
        Severity: Major
        Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return result[0] if result else None
          Severity: Major
          Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return None
            Severity: Major
            Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return aws_stack.connect_to_service('s3').get_bucket_location(Bucket=resource_id)
              Severity: Major
              Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return result[0] if result else None
                Severity: Major
                Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return None
                  Severity: Major
                  Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return None
                    Severity: Major
                    Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return None
                      Severity: Major
                      Found in localstack/utils/cloudformation/template_deployer.py - About 30 mins to fix

                        Function resources_to_deploy_next has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        def resources_to_deploy_next(resources, stack_name):
                            result = {}
                            for resource_id, resource in iteritems(resources):
                                if is_deployable_resource(resource) and not is_deployed(resource_id, resources, stack_name):
                                    res_deps = get_resource_dependencies(resource_id, resource, resources)
                        Severity: Minor
                        Found in localstack/utils/cloudformation/template_deployer.py - 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

                        Function all_dependencies_satisfied has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        def all_dependencies_satisfied(resources, stack_name, all_resources, depending_resource=None):
                            for resource_id, resource in iteritems(resources):
                                if is_deployable_resource(resource):
                                    if not is_deployed(resource_id, all_resources, stack_name):
                                        return False
                        Severity: Minor
                        Found in localstack/utils/cloudformation/template_deployer.py - 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

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                    result = list(filter(lambda res: res['path'] == path, api_resources))
                        Severity: Minor
                        Found in localstack/utils/cloudformation/template_deployer.py and 1 other location - About 30 mins to fix
                        localstack/utils/cloudformation/template_deployer.py on lines 231..231

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 32.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                                    result = list(filter(lambda api: api['name'] == resource_id, apis))
                        Severity: Minor
                        Found in localstack/utils/cloudformation/template_deployer.py and 1 other location - About 30 mins to fix
                        localstack/utils/cloudformation/template_deployer.py on lines 246..246

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 32.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status