Skip to content

Commit

Permalink
Merge pull request #159 from NebraLtd/shawaj/bandito
Browse files Browse the repository at this point in the history
fix: correct bandit path and activate flake8
  • Loading branch information
shawaj authored Dec 5, 2021
2 parents 793f615 + 2c8d3da commit c6caddf
Show file tree
Hide file tree
Showing 50 changed files with 138 additions and 89 deletions.
5 changes: 5 additions & 0 deletions .github/linters/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 120
exclude =
# Exclude generated code.
*_pb2.py
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter@v3
uses: github/super-linter/slim@v4
env:
VALIDATE_ALL_CODEBASE: true
# VALIDATE_PYTHON_FLAKE8: true
VALIDATE_PYTHON_FLAKE8: true
VALIDATE_BASH: true
VALIDATE_JSON: true
VALIDATE_DOCKERFILE_HADOLINT: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
pip install -r test-requirements.txt
pip install -r requirements.txt
export PYTHONPATH=`pwd`
pytest --cov=minerconfig --cov=lib --cov-fail-under=1
pytest --cov=gatewayconfig --cov=lib --cov-fail-under=70
2 changes: 1 addition & 1 deletion .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- name: Run bandit against code base
run: |
pip install bandit
bandit -r config-python
bandit -r .
5 changes: 4 additions & 1 deletion gatewayconfig/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
logger = get_logger(__name__)
VARIANT = os.getenv('VARIANT')
# SENTRY_CONFIG currently being used in production
SENTRY_DSN = os.getenv('SENTRY_CONFIG') # https://docs.sentry.io/product/sentry-basics/dsn-explainer/
SENTRY_DSN = os.getenv('SENTRY_CONFIG') # https://docs.sentry.io/product/sentry-basics/dsn-explainer/
BALENA_DEVICE_UUID = os.getenv('BALENA_DEVICE_UUID')
BALENA_APP_NAME = os.getenv('BALENA_APP_NAME')
FIRMWARE_VERSION = os.getenv('FIRMWARE_VERSION')
Expand All @@ -24,10 +24,12 @@
)
ETHERNET_IS_ONLINE_FILEPATH = os.getenv('ETHERNET_IS_ONLINE_FILEPATH', '/sys/class/net/eth0/carrier')


def main():
validate_env()
start()


def validate_env():
logger.debug("Starting with the following ENV:\n\
SENTRY_DSN=%s\n\
Expand All @@ -50,6 +52,7 @@ def validate_env():
FIRMWARE_VERSION
))


def start():
config_app = GatewayconfigApp(
SENTRY_DSN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def __init__(self, index, eth0_mac_address, advertisement_type, variant_details)

self.add_local_name(advertisement_name)
self.include_tx_power = True
self.service_uuids = [constants.HELIUM_SERVICE_UUID]
self.service_uuids = [constants.HELIUM_SERVICE_UUID]
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def WriteValue(self, value, options):
fee = assert_location_details.fee
payer = assert_location_details.payer

logger.debug("Going to assert location for h3 %s, owner %s, nonce %s, amount %s, fee %s, payer %s" %
(h3_string, owner, nonce, amount, fee, payer))
logger.debug("Going to assert location for h3 %s, owner %s, nonce %s, amount %s, fee %s, payer %s" %
(h3_string, owner, nonce, amount, fee, payer))

miner_assert_request = miner_interface.AssertLocation(h3_string, owner, nonce, amount, fee, payer)

logger.debug("Asserted location")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dbus
import os
from time import sleep

from lib.cputemp.service import Characteristic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def ReadValue(self, options):

is_ethernet_online = read_ethernet_is_online(self.ethernet_is_online_filepath)
logger.debug("Ethernet is online: %s" % is_ethernet_online)
return string_to_dbus_encoded_byte_array(is_ethernet_online)
return string_to_dbus_encoded_byte_array(is_ethernet_online)
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import logging
import dbus

from lib.cputemp.service import Characteristic

from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
Expand All @@ -24,4 +21,4 @@ def __init__(self, service):

def ReadValue(self, options):
logger.debug('Read Lights')
return string_to_dbus_encoded_byte_array(DEFAULT_LIGHTS_VALUE)
return string_to_dbus_encoded_byte_array(DEFAULT_LIGHTS_VALUE)
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import logging
import dbus

from lib.cputemp.service import Characteristic

from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
Expand All @@ -24,4 +21,4 @@ def __init__(self, service, eth0_mac_address):

def ReadValue(self, options):
logger.debug('Read Mac Address')
return string_to_dbus_encoded_byte_array(self.eth0_mac_address)
return string_to_dbus_encoded_byte_array(self.eth0_mac_address)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
logger = get_logger(__name__)
MANUFACTURER_NAME = "Nebra LTD."


class ManufacturerNameCharacteristic(Characteristic):
def __init__(self, service):
Characteristic.__init__(
Expand All @@ -15,4 +16,4 @@ def __init__(self, service):

def ReadValue(self, options):
logger.debug('Read Manufacturer')
return string_to_dbus_encoded_byte_array(MANUFACTURER_NAME)
return string_to_dbus_encoded_byte_array(MANUFACTURER_NAME)
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

import logging
import dbus

from lib.cputemp.service import Characteristic

from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
Expand All @@ -27,4 +23,4 @@ def ReadValue(self, options):
logger.debug("Read Public Key")
self.shared_state.load_public_key()
logger.debug("Read Public Key: %s", self.shared_state.public_key)
return string_to_dbus_encoded_byte_array(self.shared_state.public_key)
return string_to_dbus_encoded_byte_array(self.shared_state.public_key)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __init__(self, service, shared_state):
self.shared_state = shared_state
# logger.debug("Constructed WifiConfiguredServicesCharacteristic %s" % self.shared_state.to_s())


def ReadValue(self, options):
logger.debug("Read Wifi CONFIGURED Services")
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import dbus

from lib.cputemp.service import Characteristic

from gatewayconfig.logger import get_logger
Expand Down Expand Up @@ -74,7 +72,7 @@ def StartNotify(self):
try:
self.connect_to_wifi(self.wifi_service, self.wifi_password)
except Exception:
pass
logger.exception("Wifi connect failed for unknown reason")

# Notify wifi status
wifi_status = self.check_wifi_status()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def WriteValue(self, value, options):
wifi_remove_ssid.ParseFromString(bytes(value))
nmcli_custom.connection.delete(wifi_remove_ssid.service)
logger.debug('Connection %s should be deleted'
% wifi_remove_ssid.service)
% wifi_remove_ssid.service)

def ReadValue(self, options):
logger.debug('Read WiFi Remove')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def ReadValue(self, options):
if(is_valid_ssid(ssid_str)):
logger.debug("%s is a valid ssid" % ssid_str)
ssid_unknown = ssid_str not in known_wifi_services.services

if(ssid_unknown):
logger.debug("%s ssid is unknown" % ssid_str)
known_wifi_services.services.append(ssid_str)
Expand All @@ -54,4 +54,3 @@ def ReadValue(self, options):

except Exception:
logger.exception('WifiServicesCharacteristic failed for unknown reason')

Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ def ReadValue(self, options):
else:
logger.debug("Ignoring SSID: %s" % ssid_str)

return string_to_dbus_encoded_byte_array(active_connection)
return string_to_dbus_encoded_byte_array(active_connection)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class AddGatewayDescriptor(Descriptor):

def __init__(self, characteristic):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class AssertLocationDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -12,4 +13,3 @@ def __init__(self, characteristic):

def ReadValue(self, options):
return string_to_dbus_encoded_byte_array(constants.ASSERT_LOCATION_LABEL)

2 changes: 1 addition & 1 deletion gatewayconfig/bluetooth/descriptors/lights_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class LightsDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -12,4 +13,3 @@ def __init__(self, characteristic):

def ReadValue(self, options):
return string_to_dbus_encoded_byte_array(constants.LIGHTS_LABEL)

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class MacAddressDescriptor(Descriptor):

def __init__(self, characteristic):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class OnboardingKeyDescriptor(Descriptor):

def __init__(self, characteristic):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from lib.cputemp.service import Descriptor
import gatewayconfig.constants as constants


class OpaqueStructureDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -20,4 +21,4 @@ def ReadValue(self, options):
value.append(dbus.Byte(0x00))
value.append(dbus.Byte(0x00))

return value
return value
3 changes: 2 additions & 1 deletion gatewayconfig/bluetooth/descriptors/public_key_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class PublicKeyDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -11,4 +12,4 @@ def __init__(self, characteristic):
characteristic)

def ReadValue(self, options):
return string_to_dbus_encoded_byte_array(constants.PUBLIC_KEY_LABEL)
return string_to_dbus_encoded_byte_array(constants.PUBLIC_KEY_LABEL)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from lib.cputemp.service import Descriptor
import gatewayconfig.constants as constants


class UTF8FormatDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -20,4 +21,4 @@ def ReadValue(self, options):
value.append(dbus.Byte(0x00))
value.append(dbus.Byte(0x00))

return value
return value
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class WifiConfiguredServicesDescriptor(Descriptor):

def __init__(self, characteristic):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class WifiConnectDescriptor(Descriptor):

def __init__(self, characteristic):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class WifiRemoveDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -11,4 +12,4 @@ def __init__(self, characteristic):
characteristic)

def ReadValue(self, options):
return string_to_dbus_encoded_byte_array(constants.WIFI_REMOVE_VALUE)
return string_to_dbus_encoded_byte_array(constants.WIFI_REMOVE_VALUE)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class WifiServicesDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -11,4 +12,4 @@ def __init__(self, characteristic):
characteristic)

def ReadValue(self, options):
return string_to_dbus_encoded_byte_array(constants.WIFI_SERVICES_LABEL)
return string_to_dbus_encoded_byte_array(constants.WIFI_SERVICES_LABEL)
3 changes: 2 additions & 1 deletion gatewayconfig/bluetooth/descriptors/wifi_ssid_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gatewayconfig.helpers import string_to_dbus_encoded_byte_array
import gatewayconfig.constants as constants


class WifiSSIDDescriptor(Descriptor):

def __init__(self, characteristic):
Expand All @@ -11,4 +12,4 @@ def __init__(self, characteristic):
characteristic)

def ReadValue(self, options):
return string_to_dbus_encoded_byte_array(constants.WIFI_SSID_LABEL)
return string_to_dbus_encoded_byte_array(constants.WIFI_SSID_LABEL)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from gatewayconfig.bluetooth.characteristics.serial_number_characteristic import SerialNumberCharacteristic
import gatewayconfig.constants as constants


class DeviceInformationService(Service):
# Service that provides basic information
def __init__(self, index, eth0_mac_address):
Service.__init__(self, index, constants.DEVINFO_SVC_UUID, True)
self.add_characteristic(ManufacturerNameCharacteristic(self))
self.add_characteristic(FirmwareRevisionCharacteristic(self))
self.add_characteristic(SerialNumberCharacteristic(self, eth0_mac_address))
self.add_characteristic(SerialNumberCharacteristic(self, eth0_mac_address))
Loading

0 comments on commit c6caddf

Please sign in to comment.