saltstack/salt

View on GitHub
salt/modules/boto_cloudtrail.py

Summary

Maintainability
F
1 wk
Test Coverage

File boto_cloudtrail.py has 360 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

.. versionadded:: 2016.3.0
Severity: Minor
Found in salt/modules/boto_cloudtrail.py - About 4 hrs to fix

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

    def describe(Name,
                 region=None, key=None, keyid=None, profile=None):
        '''
        Given a trail name describe its properties.
    
    
    Severity: Minor
    Found in salt/modules/boto_cloudtrail.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 update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def update(Name,
               S3BucketName, S3KeyPrefix=None,
               SnsTopicName=None,
               IncludeGlobalServiceEvents=None,
               IsMultiRegionTrail=None,
    Severity: Minor
    Found in salt/modules/boto_cloudtrail.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 create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def create(Name,
               S3BucketName, S3KeyPrefix=None,
               SnsTopicName=None,
               IncludeGlobalServiceEvents=None,
               IsMultiRegionTrail=None,
    Severity: Minor
    Found in salt/modules/boto_cloudtrail.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

    def update(Name,
               S3BucketName, S3KeyPrefix=None,
               SnsTopicName=None,
               IncludeGlobalServiceEvents=None,
               IsMultiRegionTrail=None,
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 1 other location - About 1 day to fix
    salt/modules/boto_cloudtrail.py on lines 125..169

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

    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

    def create(Name,
               S3BucketName, S3KeyPrefix=None,
               SnsTopicName=None,
               IncludeGlobalServiceEvents=None,
               IsMultiRegionTrail=None,
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 1 other location - About 1 day to fix
    salt/modules/boto_cloudtrail.py on lines 298..342

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

    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

    def remove_tags(Name,
               region=None, key=None, keyid=None, profile=None, **kwargs):
        '''
        Remove tags from a trail
    
    
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 1 other location - About 1 day to fix
    salt/modules/boto_cloudtrail.py on lines 407..435

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

    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

    def add_tags(Name,
               region=None, key=None, keyid=None, profile=None, **kwargs):
        '''
        Add tags to a trail
    
    
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 1 other location - About 1 day to fix
    salt/modules/boto_cloudtrail.py on lines 438..466

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

    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

    def exists(Name,
               region=None, key=None, keyid=None, profile=None):
        '''
        Given a trail name, check to see if the given trail exists.
    
    
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 1 other location - About 7 hrs to fix
    salt/modules/boto_iot.py on lines 272..296

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

    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

    def _get_trail_arn(name, region=None, key=None, keyid=None, profile=None):
        if name.startswith('arn:aws:cloudtrail:'):
            return name
    
        account_id = __salt__['boto_iam.get_account_id'](
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 1 other location - About 6 hrs to fix
    salt/states/boto_lambda.py on lines 742..753

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

    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

    def stop_logging(Name,
               region=None, key=None, keyid=None, profile=None):
        '''
        Stop logging for a trail
    
    
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 7 other locations - About 4 hrs to fix
    salt/modules/boto_apigateway.py on lines 504..520
    salt/modules/boto_cloudtrail.py on lines 172..193
    salt/modules/boto_cloudtrail.py on lines 345..366
    salt/modules/boto_cloudwatch_event.py on lines 156..177
    salt/modules/boto_elasticsearch_domain.py on lines 267..287
    salt/modules/boto_iot.py on lines 336..357
    salt/modules/boto_iot.py on lines 792..813

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

    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

    def start_logging(Name,
               region=None, key=None, keyid=None, profile=None):
        '''
        Start logging for a trail
    
    
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 7 other locations - About 4 hrs to fix
    salt/modules/boto_apigateway.py on lines 504..520
    salt/modules/boto_cloudtrail.py on lines 172..193
    salt/modules/boto_cloudtrail.py on lines 369..390
    salt/modules/boto_cloudwatch_event.py on lines 156..177
    salt/modules/boto_elasticsearch_domain.py on lines 267..287
    salt/modules/boto_iot.py on lines 336..357
    salt/modules/boto_iot.py on lines 792..813

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

    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

    def delete(Name,
                region=None, key=None, keyid=None, profile=None):
        '''
        Given a trail name, delete it.
    
    
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 7 other locations - About 4 hrs to fix
    salt/modules/boto_apigateway.py on lines 504..520
    salt/modules/boto_cloudtrail.py on lines 345..366
    salt/modules/boto_cloudtrail.py on lines 369..390
    salt/modules/boto_cloudwatch_event.py on lines 156..177
    salt/modules/boto_elasticsearch_domain.py on lines 267..287
    salt/modules/boto_iot.py on lines 336..357
    salt/modules/boto_iot.py on lines 792..813

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

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

        try:
            conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
            trail = conn.get_trail_status(Name=Name)
            if trail:
                keys = ('IsLogging', 'LatestDeliveryError', 'LatestNotificationError',
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 6 other locations - About 3 hrs to fix
    salt/modules/boto_cloudtrail.py on lines 211..229
    salt/modules/boto_iot.py on lines 375..388
    salt/modules/boto_iot.py on lines 407..416
    salt/modules/boto_iot.py on lines 494..508
    salt/modules/boto_iot.py on lines 710..723
    salt/modules/boto_s3_bucket.py on lines 267..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 70.

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

        try:
            conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
            trails = conn.describe_trails(trailNameList=[Name])
            if trails and trails.get('trailList'):
                keys = ('Name', 'S3BucketName', 'S3KeyPrefix',
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 6 other locations - About 3 hrs to fix
    salt/modules/boto_cloudtrail.py on lines 247..270
    salt/modules/boto_iot.py on lines 375..388
    salt/modules/boto_iot.py on lines 407..416
    salt/modules/boto_iot.py on lines 494..508
    salt/modules/boto_iot.py on lines 710..723
    salt/modules/boto_s3_bucket.py on lines 267..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 70.

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

    try:
        #pylint: disable=unused-import
        import boto
        import boto3
        #pylint: enable=unused-import
    Severity: Major
    Found in salt/modules/boto_cloudtrail.py and 3 other locations - About 45 mins to fix
    salt/modules/boto_cfn.py on lines 47..56
    salt/modules/boto_elbv2.py on lines 55..66
    salt/modules/boto_s3_bucket.py on lines 71..80

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

    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