boroivanov/ecs-tools

View on GitHub

Showing 24 of 32 total issues

Service has 24 functions (exceeds 20 allowed). Consider refactoring.
Open

class Service(object):
    def __init__(self, ecs, ecr, cluster, service):
        self.ecs = ecs
        self.ecr = ecr
        self._cluster = cluster
Severity: Minor
Found in ecstools/resources/service.py - About 2 hrs to fix

    Cyclomatic complexity is too high in function exec. (9)
    Open

    @click.command(short_help='Run ECS Exec')
    @click.argument('cluster')
    @click.argument('service')
    @click.argument('command', default='/bin/bash')
    @click.option('-c', '--container', type=str, default=None, help='Container name')
    Severity: Minor
    Found in ecstools/commands/service/exec.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method get_command. (6)
    Open

        def get_command(self, ctx, cmd_name):
            """
            Check if alias is defined in the config.
            Otherwise, check if any of the subcommands start with the passed
            command.
    Severity: Minor
    Found in ecstools/lib/cli.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

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

    def exec(ctx, cluster, service, command, container, task):
        """Run ECS Exec"""
        ecs = ctx.obj['ecs']
        ecr = ctx.obj['ecr']
        region = ctx.obj['region']
    Severity: Minor
    Found in ecstools/commands/service/exec.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 list_services has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_services(ecs, cluster):
        try:
            response = ecs.list_services(cluster=cluster, maxResults=100)
        except ClientError as e:
            if e.response['Error']['Code'] == 'ClusterNotFoundException':
    Severity: Minor
    Found in ecstools/commands/service/ls.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

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

        def _remove_options_parameters(args):
            """
            Removes options parameters.
            Returns a list of argument parameters only.
            """
    Severity: Minor
    Found in ecstools/lib/cli.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 ls has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def ls(ctx, cluster, all_stats, arn):
        """List services"""
        ecs = ctx.obj['ecs']
        ecr = ctx.obj['ecr']
    
    
    Severity: Minor
    Found in ecstools/commands/service/ls.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 delete_environment_variables has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def delete_environment_variables(pairs, envs):
        for pair in pairs:
            key = pair.split('=', 1)[0]
            for e in envs:
                if key == e['name']:
    Severity: Minor
    Found in ecstools/commands/service/env.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

    Line too long (99 > 79 characters)
    Open

        cmd = f'aws ecs execute-command --cluster {cluster} --task {task_id} --container {container}' \
    Severity: Minor
    Found in ecstools/commands/service/exec.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (97 > 79 characters)
    Open

                tasks = ecs.list_tasks(cluster=cluster, serviceName=service, desiredStatus='RUNNING')
    Severity: Minor
    Found in ecstools/commands/service/exec.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (81 > 79 characters)
    Open

    @click.option('-c', '--container', type=str, default=None, help='Container name')
    Severity: Minor
    Found in ecstools/commands/service/exec.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (81 > 79 characters)
    Open

            task_desc = ecs.describe_tasks(cluster=cluster, tasks=[task])['tasks'][0]
    Severity: Minor
    Found in ecstools/commands/service/exec.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (80 > 79 characters)
    Open

            container_desc = container_selection(srv.task_definition().containers())
    Severity: Minor
    Found in ecstools/commands/service/exec.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Either remove or fill this block of code.
    Open

                pass
    Severity: Major
    Found in ecstools/resources/service.py by sonar-python

    Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

    Noncompliant Code Example

    for i in range(3):
        pass
    

    Exceptions

    When a block contains a comment, this block is not considered to be empty.

    Rename function "ls" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
    Open

    def ls(ctx, cluster, all_stats, arn):

    Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

    Noncompliant Code Example

    With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

    def MyFunction(a,b):
        ...
    

    Compliant Solution

    def my_function(a,b):
        ...
    

    Either merge this branch with the identical one on line "171" or change one of the implementations.
    Open

                    click.echo(e, err=True)
    Severity: Major
    Found in ecstools/resources/service.py by sonar-python

    Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

    Noncompliant Code Example

    if 0 <= a < 10:
        do_the_thing()
    elif 10 <= a < 20:
        do_the_other_thing()
    elif 20 <= a < 50:
        do_the_thing()  # Noncompliant; duplicates first condition
    else:
        do_the_rest()
    
    b = 4 if a > 12 else 4
    

    Compliant Solution

    if (0 <= a < 10) or (20 <= a < 50):
        do_the_thing()
    elif 10 <= a < 20:
        do_the_other_thing()
    else:
        do_the_rest()
    
    b = 4
    

    or

    if 0 <= a < 10:
        do_the_thing()
    elif 10 <= a < 20:
        do_the_other_thing()
    elif 20 <= a < 50:
        do_the_third_thing()
    else:
        do_the_rest()
    
    b = 8 if a > 12 else 4
    

    Consider possible security implications associated with subprocess module.
    Open

    import subprocess
    Severity: Info
    Found in ecstools/commands/service/exec.py by bandit

    Rename field "ecr"
    Open

            self.ecr = ecr
    Severity: Major
    Found in ecstools/resources/ecr.py by sonar-python

    It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.

    Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.

    Noncompliant Code Example

    class Foo:
      foo = ''
    
      def getFoo(self):
        ...
    
    foo = Foo()
    foo.getFoo() # what does this return?
    

    Compliant Solution

    class Foo:
      name = ''
    
      def getName(self):
        ...
    
    foo = Foo()
    foo.getName()
    

    Rename function "ls" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
    Open

    def ls(ctx, arn):

    Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

    Noncompliant Code Example

    With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

    def MyFunction(a,b):
        ...
    

    Compliant Solution

    def my_function(a,b):
        ...
    

    subprocess call - check for execution of untrusted input.
    Open

            subprocess.check_call(shlex.split(cmd))
    Severity: Info
    Found in ecstools/commands/service/exec.py by bandit
    Severity
    Category
    Status
    Source
    Language