Consider possible security implications associated with run module. Open
from subprocess import run, call, Popen, PIPE, DEVNULL, STDOUT
- Exclude checks
subprocess call - check for execution of untrusted input. Open
add_boot = run(["rc-update", "add", "swap", "boot"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
unmounted = call(["umount", "-f", "/dev/" + device])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
swapon = run(
["swapon", "/media/volatile/volatile/swap", "-p 100"],
stdout=PIPE,
stderr=STDOUT,
- Exclude checks
Starting a process with a partial executable path Open
call(["apk", "add", "curl", "jq", "autossh", "axel"])
- Exclude checks
Starting a process with a partial executable path Open
call(["mkfs.ext4", "-F", "/dev/" + device])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
setup = run(["setup-apkcache", var_cache], stdout=PIPE, stderr=STDOUT)
- Exclude checks
Starting a process with a partial executable path Open
add_boot = run(["rc-update", "add", "swap", "boot"])
- Exclude checks
Starting a process with a partial executable path Open
add_default = run(["rc-update", "add", "swap", "default"])
- Exclude checks
Starting a process with a partial executable path Open
exitcode = call(
["mount", "-t ext4", "/dev/" + device, path],
stdout=DEVNULL,
stdin=DEVNULL,
- Exclude checks
Starting a process with a partial executable path Open
unmounted = call(["umount", "/dev/" + device])
- Exclude checks
Starting a process with a partial executable path Open
call(["mkfs.ext4", "-F", "/dev/" + device])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
exitcode = call(
["mount", "/dev/" + device, path], stdout=DEVNULL, stdin=DEVNULL
- Exclude checks
subprocess call - check for execution of untrusted input. Open
dd = run(
[
"dd",
"if=/dev/zero",
"of=/media/volatile/volatile/swap",
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["apk", "update"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["apk", "add", "raspberrypi"])
- Exclude checks
Starting a process with a partial executable path Open
call(["rc-update", "del", "lncm-post", "default"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["apk", "add", "curl", "jq", "autossh", "axel"])
- Exclude checks
Starting a process with a partial executable path Open
unmounted = call(["umount", "-f", "/dev/" + device])
- Exclude checks
Starting a process with a partial executable path Open
dd = run(
[
"dd",
"if=/dev/zero",
"of=/media/volatile/volatile/swap",
- Exclude checks
subprocess call - check for execution of untrusted input. Open
mkswap = run(
["mkswap", "/media/volatile/volatile/swap"],
stdout=PIPE,
stderr=STDOUT,
- Exclude checks
Starting a process with a partial executable path Open
call(["apk", "add", "raspberrypi"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
start_tor = run(["/sbin/service", "tor", "start"])
- Exclude checks
Starting a process with a partial executable path Open
call(["apk", "update"])
- Exclude checks
Starting a process with a partial executable path Open
call(["rc-update", "add", service, runlevel])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
exitcode = call(["/usr/bin/crontab", "/home/lncm/crontab"])
- Exclude checks
Starting a process with a partial executable path Open
mkswap = run(
["mkswap", "/media/volatile/volatile/swap"],
stdout=PIPE,
stderr=STDOUT,
- Exclude checks
subprocess call - check for execution of untrusted input. Open
exitcode = call(["rc-update", "add", "docker-compose"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["rc-update", "del", "lncm-post", "default"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
add_default = run(["rc-update", "add", "swap", "default"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
exitcode = call(
["mount", "-t ext4", "/dev/" + device, path],
stdout=DEVNULL,
stdin=DEVNULL,
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["mkfs.ext4", "-F", "/dev/" + device])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["pip3", "install", "docker-compose==1.23.2"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
unmounted = call(["umount", "/dev/" + device])
- Exclude checks
Starting a process with a partial executable path Open
swapon = run(
["swapon", "/media/volatile/volatile/swap", "-p 100"],
stdout=PIPE,
stderr=STDOUT,
- Exclude checks
Starting a process with a partial executable path Open
exitcode = call(["rc-update", "add", "docker-compose"])
- Exclude checks
Starting a process with a partial executable path Open
setup = run(["setup-apkcache", var_cache], stdout=PIPE, stderr=STDOUT)
- Exclude checks
Starting a process with a partial executable path Open
exitcode = call(
["mount", "/dev/" + device, path], stdout=DEVNULL, stdin=DEVNULL
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["rc-update", "add", service, runlevel])
- Exclude checks
Starting a process with a partial executable path Open
call(["pip3", "install", "docker-compose==1.23.2"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
add_tor = run(["apk", "add", "tor"])
- Exclude checks
subprocess call - check for execution of untrusted input. Open
call(["mkfs.ext4", "-F", "/dev/" + device])
- Exclude checks
Starting a process with a partial executable path Open
add_tor = run(["apk", "add", "tor"])
- Exclude checks
Function usb_setup
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
def usb_setup():
"""Perform setup on three usb devices"""
largest = usb.largest_partition()
medium = usb.medium_partition()
smallest = usb.smallest_partition()
- Read upRead up
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
File install.py
has 378 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""
Node installation related functionality
"""
from pathlib import Path
import shutil
Cyclomatic complexity is too high in function check_for_destruction. (10) Open
def check_for_destruction(device, path):
"""Check devices for destruction flag. If so, format with ext4"""
print("Check devices for destruction flag")
destroy = Path(path + "/DESTROY_ALL_DATA_ON_THIS_DEVICE/").is_dir()
if destroy:
- Read upRead up
- Exclude checks
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. |
Cyclomatic complexity is too high in function create_swap. (10) Open
def create_swap():
"""Create swap on volatile usb device"""
import psutil
# TODO: make sure dd runs in foreground and is blocking
- Read upRead up
- Exclude checks
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. |
Function create_swap
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def create_swap():
"""Create swap on volatile usb device"""
import psutil
# TODO: make sure dd runs in foreground and is blocking
- Read upRead up
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 check_for_destruction
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def check_for_destruction(device, path):
"""Check devices for destruction flag. If so, format with ext4"""
print("Check devices for destruction flag")
destroy = Path(path + "/DESTROY_ALL_DATA_ON_THIS_DEVICE/").is_dir()
if destroy:
- Read upRead up
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
Cyclomatic complexity is too high in function usb_setup. (7) Open
def usb_setup():
"""Perform setup on three usb devices"""
largest = usb.largest_partition()
medium = usb.medium_partition()
smallest = usb.smallest_partition()
- Read upRead up
- Exclude checks
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. |
Cyclomatic complexity is too high in function fallback_mount. (6) Open
def fallback_mount(partition, path):
"""Attempt to mount partition at path using ext4 first and falling back to any
:return bool: success
"""
- Read upRead up
- Exclude checks
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. |
Avoid deeply nested control flow statements. Open
if mount_path.mkdir(exist_ok=True) and mount_path.is_dir():
# We confirmed device is mountable, readable, writable
setup_fstab(device, mountpoints[num])
else:
Function check_to_fetch
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_to_fetch(file_path, url):
"""Check and fetch if necessary"""
filename = file_path.split("/")[-1]
path_list = file_path.split("/")[:-1]
dir_path = "/".join(path_list)
- Read upRead up
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
Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed. Open
def check_for_destruction(device, path):
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed. Open
def create_swap():
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Refactor this function to reduce its Cognitive Complexity from 37 to the 15 allowed. Open
def usb_setup():
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Merge this if statement with the enclosing one. Open
if swap_on() and enable_swap():
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Similar blocks of code found in 2 locations. Consider refactoring. Open
if mnt_any(partition, path) == 0 and usb.is_mounted(partition):
print(
"{d} mounted at {p} with any filesystem".format(
d=partition, p=path
)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if mnt_ext4(partition, path) == 0 and usb.is_mounted(partition):
print("{d} is mounted as ext4 at {p}".format(d=partition, p=path))
return True
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Line too long (82 > 79 characters) Open
"""Attempt to mount partition at path using ext4 first and falling back to any
- Read upRead up
- Exclude checks
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 (127 > 79 characters) Open
"https://raw.githubusercontent.com/lncm/pi-factory/b12c6f43d11be58dac03a2513cfd2abbb16f6526/etc/init.d/docker-compose",
- Read upRead up
- Exclude checks
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 (84 > 79 characters) Open
"https://raw.githubusercontent.com/lncm/invoicer-ui/master/dist/index.html",
- Read upRead up
- Exclude checks
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 (83 > 79 characters) Open
"{d} formatted with ext4 successfully and mounted.".format(
- Read upRead up
- Exclude checks
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.