saltstack/salt

View on GitHub
salt/modules/boto_iot.py

Summary

Maintainability
F
1 wk
Test Coverage

File boto_iot.py has 628 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

.. versionadded:: 2016.3.0
Severity: Major
Found in salt/modules/boto_iot.py - About 1 day to fix

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

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

    def list_topic_rules(topic=None, ruleDisabled=None,
                region=None, key=None, keyid=None, profile=None):
        '''
        List all rules (for a given topic, if specified)
    
    
    Severity: Minor
    Found in salt/modules/boto_iot.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 policy_exists(policyName,
               region=None, key=None, keyid=None, profile=None):
        '''
        Given a policy name, check to see if the given policy exists.
    
    
    Severity: Major
    Found in salt/modules/boto_iot.py and 1 other location - About 7 hrs to fix
    salt/modules/boto_cloudtrail.py on lines 98..122

    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 replace_topic_rule(ruleName, sql, actions, description,
                ruleDisabled=False,
                region=None, key=None, keyid=None, profile=None):
        '''
        Given a valid config, replace a topic rule with the new values.
    Severity: Major
    Found in salt/modules/boto_iot.py and 1 other location - About 5 hrs to fix
    salt/modules/boto_iot.py on lines 726..756

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

    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_topic_rule(ruleName, sql, actions, description,
                ruleDisabled=False,
                region=None, key=None, keyid=None, profile=None):
        '''
        Given a valid config, create a topic rule.
    Severity: Major
    Found in salt/modules/boto_iot.py and 1 other location - About 5 hrs to fix
    salt/modules/boto_iot.py on lines 759..789

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

    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 detach_principal_policy(policyName, principal,
                region=None, key=None, keyid=None, profile=None):
        '''
        Detach the specified policy from the specified principal (certificate or other
        credential.)
    Severity: Major
    Found in salt/modules/boto_iot.py and 7 other locations - About 4 hrs to fix
    salt/modules/boto_apigateway.py on lines 753..769
    salt/modules/boto_apigateway.py on lines 882..898
    salt/modules/boto_apigateway.py on lines 901..917
    salt/modules/boto_apigateway.py on lines 1160..1176
    salt/modules/boto_iot.py on lines 454..476
    salt/modules/boto_iot.py on lines 643..666
    salt/modules/boto_lambda.py on lines 694..714

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

    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 attach_principal_policy(policyName, principal,
                region=None, key=None, keyid=None, profile=None):
        '''
        Attach the specified policy to the specified principal (certificate or other
        credential.)
    Severity: Major
    Found in salt/modules/boto_iot.py and 7 other locations - About 4 hrs to fix
    salt/modules/boto_apigateway.py on lines 753..769
    salt/modules/boto_apigateway.py on lines 882..898
    salt/modules/boto_apigateway.py on lines 901..917
    salt/modules/boto_apigateway.py on lines 1160..1176
    salt/modules/boto_iot.py on lines 454..476
    salt/modules/boto_iot.py on lines 669..691
    salt/modules/boto_lambda.py on lines 694..714

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

    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_policy_version(policyName, policyVersionId,
                region=None, key=None, keyid=None, profile=None):
        '''
        Given a policy name and version, delete it.
    
    
    Severity: Major
    Found in salt/modules/boto_iot.py and 7 other locations - About 4 hrs to fix
    salt/modules/boto_apigateway.py on lines 753..769
    salt/modules/boto_apigateway.py on lines 882..898
    salt/modules/boto_apigateway.py on lines 901..917
    salt/modules/boto_apigateway.py on lines 1160..1176
    salt/modules/boto_iot.py on lines 643..666
    salt/modules/boto_iot.py on lines 669..691
    salt/modules/boto_lambda.py on lines 694..714

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

    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_topic_rule(ruleName,
                region=None, key=None, keyid=None, profile=None):
        '''
        Given a rule name, delete it.
    
    
    Severity: Major
    Found in salt/modules/boto_iot.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_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

    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_policy(policyName,
                region=None, key=None, keyid=None, profile=None):
        '''
        Given a policy name, delete it.
    
    
    Severity: Major
    Found in salt/modules/boto_iot.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_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 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)
            policy = conn.get_policy(policyName=policyName)
            if policy:
                keys = ('policyName', 'policyArn', 'policyDocument',
    Severity: Major
    Found in salt/modules/boto_iot.py and 6 other locations - About 3 hrs to fix
    salt/modules/boto_cloudtrail.py on lines 211..229
    salt/modules/boto_cloudtrail.py on lines 247..270
    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)
            rule = conn.get_topic_rule(ruleName=ruleName)
            return {'exists': True}
        except ClientError as e:
    Severity: Major
    Found in salt/modules/boto_iot.py and 6 other locations - About 3 hrs to fix
    salt/modules/boto_cloudtrail.py on lines 211..229
    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_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)
            policy = conn.get_policy_version(policyName=policyName,
                                             policyversionId=policyVersionId)
            return {'exists': bool(policy)}
    Severity: Major
    Found in salt/modules/boto_iot.py and 6 other locations - About 3 hrs to fix
    salt/modules/boto_cloudtrail.py on lines 211..229
    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 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)
            policy = conn.get_policy_version(policyName=policyName,
                                             policyVersionId=policyVersionId)
            if policy:
    Severity: Major
    Found in salt/modules/boto_iot.py and 6 other locations - About 3 hrs to fix
    salt/modules/boto_cloudtrail.py on lines 211..229
    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 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 2 locations. Consider refactoring.
    Open

        try:
            conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
            conn.delete_thing_type(thingTypeName=thingTypeName)
            return {'deleted': True}
        except ClientError as e:
    Severity: Major
    Found in salt/modules/boto_iot.py and 1 other location - About 2 hrs to fix
    salt/modules/boto_lambda.py on lines 575..613

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

    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 policy:
                keys = ('policyName', 'policyArn', 'policyDocument',
                        'defaultVersionId')
                return {'policy': dict([(k, policy.get(k)) for k in keys])}
            else:
    Severity: Major
    Found in salt/modules/boto_iot.py and 1 other location - About 1 hr to fix
    salt/modules/boto_lambda.py on lines 779..783

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

    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