secrethub/ansible-secrethub

View on GitHub

Showing 16 of 16 total issues

Function _run_command has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def _run_command(self, args, stdin=None):
        """Runs a CLI command.

        :param list(str) args: The arguments of the CLI command (e.g. read /path/to/read)
        :param str stdin: Input to supply on stdin.
Severity: Minor
Found in module_utils/client.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

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

class CLINotPermitted(CLIInaccessible):
    """Error that is raised when the user has no execute permissions on the CLI.

    The user that runs the python process is the user that should have the permission.
    """
Severity: Major
Found in module_utils/client.py and 1 other location - About 1 hr to fix
module_utils/client.py on lines 155..162

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

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

class CLINotFound(CLIInaccessible):
    """Error that is raised when the CLI is not found at the configured path.
    """
    def __init__(self, cli_path):
        self.cli_path = cli_path
Severity: Major
Found in module_utils/client.py and 1 other location - About 1 hr to fix
module_utils/client.py on lines 165..174

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

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

class WriteError(Error):
    """Error that is raised when writing a secret.

    For now, this error is not subclassed, as we are not parsing the CLI's error message.
    When refactoring the client to have its own implementation of write instead of depending
Severity: Minor
Found in module_utils/client.py and 2 other locations - About 30 mins to fix
module_utils/client.py on lines 177..191
module_utils/client.py on lines 210..223

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

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

class ReadError(Error):
    """Error that is raised when reading a secret.

    For now, this error is not subclassed, as we are not parsing the CLI's error message.
    When refactoring the client to have its own implementation of read instead of depending
Severity: Minor
Found in module_utils/client.py and 2 other locations - About 30 mins to fix
module_utils/client.py on lines 194..207
module_utils/client.py on lines 210..223

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

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

class GenerateError(Error):
    """Error that is raised when generating a secret.

    For now, this error is not subclassed, as we are not parsing the CLI's error message.
    When refactoring the client to have its own implementation of generate instead of depending
Severity: Minor
Found in module_utils/client.py and 2 other locations - About 30 mins to fix
module_utils/client.py on lines 177..191
module_utils/client.py on lines 194..207

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

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

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

    def run(self):
        """ Installs or upgrades the SecretHub CLI when needed.

        Installs the SecretHub CLI when the CLI is not yet installed in the configured path.
        When a different version of the CLI is installed, it is upgraded/downgraded.
Severity: Minor
Found in library/secrethub_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

Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
Open

            return urlopen('https://get.secrethub.io/releases/LATEST').read().decode()
Severity: Minor
Found in library/secrethub_cli.py by bandit

subprocess call - check for execution of untrusted input.
Open

                p = subprocess.Popen(
                    command,
                    env=env,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
Severity: Info
Found in module_utils/client.py by bandit

Consider possible security implications associated with subprocess module.
Open

import subprocess


Severity: Info
Found in module_utils/client.py by bandit

subprocess call - check for execution of untrusted input.
Open

            p = subprocess.Popen(
                [self.bin_path(), '--version'],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
Severity: Info
Found in library/secrethub_cli.py by bandit

Consider possible security implications associated with subprocess module.
Open

import subprocess
Severity: Info
Found in library/secrethub_cli.py by bandit

Merge this if statement with the enclosing one.
Open

            if current_version is not None:
Severity: Major
Found in library/secrethub_cli.py by sonar-python

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...

Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
Open

            urlretrieve(fetch_url, tmp_file)
Severity: Minor
Found in library/secrethub_cli.py by bandit

Chmod setting a permissive mask 0o711 on file (NOT PARSED).
Open

        os.chmod(self.bin_path(), 0o711)
Severity: Minor
Found in library/secrethub_cli.py by bandit

subprocess call - check for execution of untrusted input.
Open

                p = subprocess.Popen(
                    command,
                    env=env,
                    stdin=subprocess.PIPE,
                    stdout=subprocess.PIPE,
Severity: Info
Found in module_utils/client.py by bandit
Severity
Category
Status
Source
Language