saltstack/salt

View on GitHub
salt/modules/boto_kinesis.py

Summary

Maintainability
F
4 days
Test Coverage

File boto_kinesis.py has 408 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Connection module for Amazon Kinesis

.. versionadded:: 2017.7.0
Severity: Minor
Found in salt/modules/boto_kinesis.py - About 5 hrs to fix

    Function reshard has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    def reshard(stream_name, desired_size, force=False,
                region=None, key=None, keyid=None, profile=None):
        """
        Reshard a kinesis stream.  Each call to this function will wait until the stream is ACTIVE,
        then make a single split or merge operation. This function decides where to split or merge
    Severity: Minor
    Found in salt/modules/boto_kinesis.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 list_streams has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_streams(region=None, key=None, keyid=None, profile=None):
        '''
        Return a list of all streams visible to the current account
    
        CLI example:
    Severity: Minor
    Found in salt/modules/boto_kinesis.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 _execute_with_retries has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def _execute_with_retries(conn, function, **kwargs):
        '''
        Retry if we're rate limited by AWS or blocked by another call.
        Give up and return error message if resource not found or argument is invalid.
    
    
    Severity: Minor
    Found in salt/modules/boto_kinesis.py - 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

    Function get_info_for_reshard has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_info_for_reshard(stream_details):
        """
        Collect some data: number of open shards, key range, etc.
        Modifies stream_details to add a sorted list of OpenShards.
        Returns (min_hash_key, max_hash_key, stream_details)
    Severity: Minor
    Found in salt/modules/boto_kinesis.py - About 35 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 function.
    Open

        return r
    Severity: Major
    Found in salt/modules/boto_kinesis.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return r
      Severity: Major
      Found in salt/modules/boto_kinesis.py - About 30 mins to fix

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

        def increase_stream_retention_period(stream_name, retention_hours,
                                             region=None, key=None, keyid=None, profile=None):
            '''
            Increase stream retention period to retention_hours
        
        
        Severity: Major
        Found in salt/modules/boto_kinesis.py and 4 other locations - About 3 hrs to fix
        salt/modules/boto_kinesis.py on lines 177..192
        salt/modules/boto_kinesis.py on lines 231..247
        salt/modules/boto_kinesis.py on lines 250..267
        salt/modules/boto_kinesis.py on lines 270..287

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

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

        def decrease_stream_retention_period(stream_name, retention_hours,
                                             region=None, key=None, keyid=None, profile=None):
            '''
            Decrease stream retention period to retention_hours
        
        
        Severity: Major
        Found in salt/modules/boto_kinesis.py and 4 other locations - About 3 hrs to fix
        salt/modules/boto_kinesis.py on lines 177..192
        salt/modules/boto_kinesis.py on lines 212..228
        salt/modules/boto_kinesis.py on lines 250..267
        salt/modules/boto_kinesis.py on lines 270..287

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

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

        def disable_enhanced_monitoring(stream_name, metrics,
                                        region=None, key=None, keyid=None, profile=None):
            '''
            Disable enhanced monitoring for the specified shard-level metrics on stream stream_name
        
        
        Severity: Major
        Found in salt/modules/boto_kinesis.py and 4 other locations - About 3 hrs to fix
        salt/modules/boto_kinesis.py on lines 177..192
        salt/modules/boto_kinesis.py on lines 212..228
        salt/modules/boto_kinesis.py on lines 231..247
        salt/modules/boto_kinesis.py on lines 250..267

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

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

        def enable_enhanced_monitoring(stream_name, metrics,
                                       region=None, key=None, keyid=None, profile=None):
            '''
            Enable enhanced monitoring for the specified shard-level metrics on stream stream_name
        
        
        Severity: Major
        Found in salt/modules/boto_kinesis.py and 4 other locations - About 3 hrs to fix
        salt/modules/boto_kinesis.py on lines 177..192
        salt/modules/boto_kinesis.py on lines 212..228
        salt/modules/boto_kinesis.py on lines 231..247
        salt/modules/boto_kinesis.py on lines 270..287

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

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

        def create_stream(stream_name, num_shards, region=None, key=None, keyid=None, profile=None):
            '''
            Create a stream with name stream_name and initial number of shards num_shards.
        
            CLI example::
        Severity: Major
        Found in salt/modules/boto_kinesis.py and 4 other locations - About 3 hrs to fix
        salt/modules/boto_kinesis.py on lines 212..228
        salt/modules/boto_kinesis.py on lines 231..247
        salt/modules/boto_kinesis.py on lines 250..267
        salt/modules/boto_kinesis.py on lines 270..287

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

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

        try:
            import boto3
            import botocore
            logging.getLogger('boto3').setLevel(logging.CRITICAL)
            HAS_BOTO = True
        Severity: Major
        Found in salt/modules/boto_kinesis.py and 7 other locations - About 30 mins to fix
        salt/modules/boto3_elasticache.py on lines 65..73
        salt/modules/boto_cloudfront.py on lines 64..72
        salt/modules/boto_s3.py on lines 63..71
        salt/modules/boto_secgroup.py on lines 61..69
        salt/modules/boto_sns.py on lines 55..63
        salt/modules/boto_sqs.py on lines 67..75
        salt/utils/botomod.py on lines 52..60

        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