saltstack/salt

View on GitHub
salt/modules/boto_secgroup.py

Summary

Maintainability
F
6 days
Test Coverage

File boto_secgroup.py has 572 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

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

    Function _get_group has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

    def _get_group(conn=None, name=None, vpc_id=None, vpc_name=None, group_id=None,
                   region=None, key=None, keyid=None, profile=None):  # pylint: disable=W0613
        '''
        Get a group object given a name, name and vpc_id/vpc_name or group_id. Return
        a boto.ec2.securitygroup.SecurityGroup object if the group is found, else
    Severity: Minor
    Found in salt/modules/boto_secgroup.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 _parse_rules has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def _parse_rules(sg, rules):
        _rules = []
        for rule in rules:
            log.debug('examining rule %s for group %s', rule, sg.id)
            attrs = ['ip_protocol', 'from_port', 'to_port', 'grants']
    Severity: Minor
    Found in salt/modules/boto_secgroup.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 authorize has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def authorize(name=None, source_group_name=None,
                  source_group_owner_id=None, ip_protocol=None,
                  from_port=None, to_port=None, cidr_ip=None, group_id=None,
                  source_group_group_id=None, region=None, key=None, keyid=None,
                  profile=None, vpc_id=None, vpc_name=None, egress=False):
    Severity: Minor
    Found in salt/modules/boto_secgroup.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_all_security_groups has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_all_security_groups(groupnames=None, group_ids=None, filters=None,
                                region=None, key=None, keyid=None, profile=None):
        '''
        Return a list of all Security Groups matching the given criteria and filters.
    
    
    Severity: Minor
    Found in salt/modules/boto_secgroup.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 _find_vpcs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def _find_vpcs(vpc_id=None, vpc_name=None, cidr=None, tags=None,
                   region=None, key=None, keyid=None, profile=None):
        '''
        Given VPC properties, find and return matching VPC ids.
        Borrowed from boto_vpc; these could be refactored into a common library
    Severity: Minor
    Found in salt/modules/boto_secgroup.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 revoke has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def revoke(name=None, source_group_name=None,
               source_group_owner_id=None, ip_protocol=None,
               from_port=None, to_port=None, cidr_ip=None, group_id=None,
               source_group_group_id=None, region=None, key=None, keyid=None,
               profile=None, vpc_id=None, vpc_name=None, egress=False):
    Severity: Minor
    Found in salt/modules/boto_secgroup.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

                        for g_attr, g_attr_map in six.iteritems(g_attrs):
                            g_val = getattr(grant, g_attr)
                            if not g_val:
                                continue
                            _grant[g_attr_map] = g_val
    Severity: Major
    Found in salt/modules/boto_secgroup.py - About 45 mins to fix

      Function convert_to_group_ids has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def convert_to_group_ids(groups, vpc_id=None, vpc_name=None, region=None, key=None,
                               keyid=None, profile=None):
          '''
          Given a list of security groups and a vpc_id, convert_to_group_ids will
          convert all list items in the given list to security group ids.
      Severity: Minor
      Found in salt/modules/boto_secgroup.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 delete_tags has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def delete_tags(tags,
                      name=None,
                      group_id=None,
                      vpc_name=None,
                      vpc_id=None,
      Severity: Minor
      Found in salt/modules/boto_secgroup.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

      Avoid too many return statements within this function.
      Open

                  return groups[0]
      Severity: Major
      Found in salt/modules/boto_secgroup.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

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

          Avoid too many return statements within this function.
          Open

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

            Avoid too many return statements within this function.
            Open

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

              Avoid too many return statements within this function.
              Open

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

                Avoid too many return statements within this function.
                Open

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

                  Avoid too many return statements within this function.
                  Open

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

                    Avoid too many return statements within this function.
                    Open

                                    return filtered_groups[0]
                    Severity: Major
                    Found in salt/modules/boto_secgroup.py - About 30 mins to fix

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

                      def _split_rules(rules):
                          '''
                          Split rules with combined grants into individual rules.
                      
                          Amazon returns a set of rules with the same protocol, from and to ports
                      Severity: Minor
                      Found in salt/modules/boto_secgroup.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

                              try:
                                  revoked = None
                                  if not egress:
                                      revoked = conn.revoke_security_group(
                                          src_security_group_name=source_group_name,
                      Severity: Major
                      Found in salt/modules/boto_secgroup.py and 1 other location - About 1 day to fix
                      salt/modules/boto_secgroup.py on lines 459..481

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

                      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:
                                  added = None
                                  if not egress:
                                      added = conn.authorize_security_group(
                                          src_security_group_name=source_group_name,
                      Severity: Major
                      Found in salt/modules/boto_secgroup.py and 1 other location - About 1 day to fix
                      salt/modules/boto_secgroup.py on lines 514..537

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

                      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 __virtual__():
                          '''
                          Only load if boto libraries exist and if boto libraries are greater than
                          a given version.
                          '''
                      Severity: Major
                      Found in salt/modules/boto_secgroup.py and 1 other location - About 2 hrs to fix
                      salt/modules/boto_ec2.py on lines 76..90

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

                      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 vpc_id and vpc_name:
                              try:
                                  vpc_id = _vpc_name_to_id(vpc_id=vpc_id, vpc_name=vpc_name, region=region,
                                                      key=key, keyid=keyid, profile=profile)
                              except boto.exception.BotoServerError as e:
                      Severity: Major
                      Found in salt/modules/boto_secgroup.py and 1 other location - About 1 hr to fix
                      salt/modules/boto_secgroup.py on lines 153..159

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

                      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 vpc_name:
                              try:
                                  vpc_id = _vpc_name_to_id(vpc_id=vpc_id, vpc_name=vpc_name, region=region,
                                                      key=key, keyid=keyid, profile=profile)
                              except boto.exception.BotoServerError as e:
                      Severity: Major
                      Found in salt/modules/boto_secgroup.py and 1 other location - About 1 hr to fix
                      salt/modules/boto_secgroup.py on lines 395..401

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

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

                          if tags:
                              for tag_name, tag_value in six.iteritems(tags):
                                  filter_parameters['filters']['tag:{0}'.format(tag_name)] = tag_value
                      Severity: Major
                      Found in salt/modules/boto_secgroup.py and 9 other locations - About 1 hr to fix
                      salt/modules/boto_ec2.py on lines 583..585
                      salt/modules/boto_ec2.py on lines 673..675
                      salt/modules/boto_vpc.py on lines 399..401
                      salt/modules/boto_vpc.py on lines 507..509
                      salt/modules/boto_vpc.py on lines 788..790
                      salt/modules/boto_vpc.py on lines 828..830
                      salt/modules/boto_vpc.py on lines 947..949
                      salt/modules/boto_vpc.py on lines 2149..2151
                      salt/modules/boto_vpc.py on lines 2505..2507

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

                      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 created:
                              log.info('Created security group %s.', name)
                              return True
                          else:
                              msg = 'Failed to create security group {0}.'.format(name)
                      Severity: Minor
                      Found in salt/modules/boto_secgroup.py and 2 other locations - About 35 mins to fix
                      salt/modules/boto_elasticache.py on lines 627..633
                      salt/modules/boto_elasticache.py on lines 648..654

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

                      try:
                          # pylint: disable=unused-import
                          import boto
                          import boto.ec2
                          # pylint: enable=unused-import
                      Severity: Major
                      Found in salt/modules/boto_secgroup.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_kinesis.py on lines 61..67
                      salt/modules/boto_s3.py on lines 63..71
                      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