saltstack/salt

View on GitHub
salt/states/boto_dynamodb.py

Summary

Maintainability
F
6 days
Test Coverage

File boto_dynamodb.py has 640 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Manage DynamoDB Tables
======================

Severity: Major
Found in salt/states/boto_dynamodb.py - About 1 day to fix

    Function present has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def present(name=None,
                table_name=None,
                region=None,
                key=None,
                keyid=None,
    Severity: Minor
    Found in salt/states/boto_dynamodb.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 _global_indexes_present has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def _global_indexes_present(provisioned_indexes, global_indexes, changes_old,
                                changes_new, comments, name, region, key, keyid,
                                profile):
        '''Handles global secondary index for the table present state.'''
        ret = {'result': True}
    Severity: Minor
    Found in salt/states/boto_dynamodb.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 _determine_gsi_updates has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def _determine_gsi_updates(existing_index_names, provisioned_gsi_config, gsi_config):
        # index name -> {'read': <read throughput>, 'write': <write throughput>}
        provisioned_throughputs = {}
        index_updates = {}
        for index_name in existing_index_names:
    Severity: Minor
    Found in salt/states/boto_dynamodb.py - About 2 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 _alarms_present has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def _alarms_present(name, alarms, alarms_from_pillar,
                        write_capacity_units, read_capacity_units,
                        region, key, keyid, profile):
        '''helper method for present.  ensure that cloudwatch_alarms are set'''
        # load data from alarms_from_pillar
    Severity: Minor
    Found in salt/states/boto_dynamodb.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 _update_global_secondary_indexes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def _update_global_secondary_indexes(ret, changes_old, changes_new, comments, existing_index_names,
                                         provisioned_gsi_config, gsi_config, name, region, key,
                                         keyid, profile):
        '''Updates ret iff there was a failure or in test mode.'''
        try:
    Severity: Minor
    Found in salt/states/boto_dynamodb.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 deeply nested control flow statements.
    Open

                        if new_value['ProjectionType'] != current_value['ProjectionType']:
                            raise GsiNotUpdatableError('GSI projection types do not match')
                        elif set(new_value.get('NonKeyAttributes', [])) != set(current_value.get('NonKeyAttributes', [])):
                            raise GsiNotUpdatableError('NonKeyAttributes do not match for GSI projection')
                    elif new_value != current_value:
    Severity: Major
    Found in salt/states/boto_dynamodb.py - About 45 mins to fix

      Avoid too many return statements within this function.
      Open

                  return ret
      Severity: Major
      Found in salt/states/boto_dynamodb.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return ret
        Severity: Major
        Found in salt/states/boto_dynamodb.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return ret
          Severity: Major
          Found in salt/states/boto_dynamodb.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return ret
            Severity: Major
            Found in salt/states/boto_dynamodb.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return ret
              Severity: Major
              Found in salt/states/boto_dynamodb.py - About 30 mins to fix

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

                        if info["attributes"]["metric"] == "ConsumedWriteCapacityUnits" \
                           and "threshold" not in info["attributes"]:
                            info["attributes"]["threshold"] = math.ceil(write_capacity_units * info["attributes"]["threshold_percent"])
                            del info["attributes"]["threshold_percent"]
                            # the write_capacity_units is given in unit / second. So we need
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 1 other location - About 7 hrs to fix
                salt/states/boto_dynamodb.py on lines 644..651

                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 126.

                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

                        if info["attributes"]["metric"] == "ConsumedReadCapacityUnits" \
                           and "threshold" not in info["attributes"]:
                            info["attributes"]["threshold"] = math.ceil(read_capacity_units * info["attributes"]["threshold_percent"])
                            del info["attributes"]["threshold_percent"]
                            # the read_capacity_units is given in unit / second. So we need
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 1 other location - About 7 hrs to fix
                salt/states/boto_dynamodb.py on lines 636..643

                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 126.

                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

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

                        if ret['result'] is False:
                            ret['comment'] = ',\n'.join(comments)
                            _add_changes(ret, changes_old, changes_new)
                            return ret
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 1 other location - About 1 hr to fix
                salt/states/boto_dynamodb.py on lines 393..396

                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 45.

                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

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

                        if ret['result'] is False:
                            ret['comment'] = ',\n'.join(comments)
                            _add_changes(ret, changes_old, changes_new)
                            return ret
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 1 other location - About 1 hr to fix
                salt/states/boto_dynamodb.py on lines 381..384

                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 45.

                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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                        info["attributes"]["description"] = name + " " + info["attributes"]["description"]
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 2 other locations - About 1 hr to fix
                salt/states/boto_asg.py on lines 784..784
                salt/states/boto_elb.py on lines 995..995

                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 41.

                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

                            if not is_created:
                                ret['result'] = False
                                ret['comment'] = 'Failed to create table {0}'.format(name)
                                _add_changes(ret, changes_old, changes_new)
                                return ret
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 1 other location - About 1 hr to fix
                salt/states/boto_dynamodb.py on lines 359..363

                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 48.

                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

                            if not is_updated:
                                ret['result'] = False
                                ret['comment'] = 'Failed to update table {0}'.format(name)
                                _add_changes(ret, changes_old, changes_new)
                                return ret
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 1 other location - About 1 hr to fix
                salt/states/boto_dynamodb.py on lines 311..315

                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 48.

                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

                            for index_name in index_updates:
                                changes_old['global_indexes'][index_name] = provisioned_throughputs[index_name]
                                changes_new['global_indexes'][index_name] = index_updates[index_name]
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 1 other location - About 1 hr to fix
                salt/modules/debian_ip.py on lines 1301..1303

                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 47.

                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 3 locations. Consider refactoring.
                Open

                        if results.get("changes", {}) != {}:
                            merged_return_value["changes"][info["name"]] = results["changes"]
                Severity: Major
                Found in salt/states/boto_dynamodb.py and 2 other locations - About 1 hr to fix
                salt/states/boto_asg.py on lines 815..816
                salt/states/boto_elb.py on lines 1009..1010

                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 46.

                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

                        datapipeline_ret = _ensure_backup_datapipeline_present(
                            name=name,
                            schedule_name=config['name'],
                            period=config['period'],
                            utc_hour=config['utc_hour'],
                Severity: Minor
                Found in salt/states/boto_dynamodb.py and 1 other location - About 30 mins to fix
                salt/states/x509.py on lines 491..494

                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 40.

                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