Skip to content

Commit

Permalink
Don't set default values for SIGAN_MODULE, SIGAN_CLASS, or DEVICE_MOD…
Browse files Browse the repository at this point in the history
…EL. Add check and raise exception if SIGAN_MODULE or SIGAN_CLASS are not set. Don't set sensor_sha512 if unable to generate hash. Add DEVICE_MODEL to readme and env.template.
  • Loading branch information
dboulware committed Jan 31, 2024
1 parent b25601a commit 4dcfd4f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ settings in the environment file:
- CALLBACK_TIMEOUT: The timeout for the posts sent to the callback URL when a scheduled
action is completed.
- DEBUG: Django debug mode. Set to False in production.
- DEVICE_MODEL: Optional setting indicating the model of the signal analyzer. The
TekRSASigan class will use this value to determine which action configs to load.
See [scos-tekrsa](https://github.com/ntia/scos-tekrsa) for additional details.
- DOCKER_TAG: Always set to “latest” to install newest version of docker containers.
- DOMAINS: A space separated list of domain names. Used to generate [ALLOWED_HOSTS](
<https://docs.djangoproject.com/en/3.0/ref/settings/#allowed-hosts>).
Expand Down
2 changes: 2 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ CALLBACK_TIMEOUT=2
# Use either true or false
DEBUG=true

DEVICE_MODEL=RSA507A

# Use latest as default for local development
DOCKER_TAG=latest

Expand Down
2 changes: 0 additions & 2 deletions src/initialization/capabilities_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def load_capabilities(sensor_definition_file: str) -> dict:
).hexdigest()
capabilities["sensor"]["sensor_sha512"] = sensor_definition_hash
except:
capabilities["sensor"]["sensor_sha512"] = "ERROR GENERATING HASH"
# sensor_sha512 is None, do not raise Exception, but log it
logger.exception(f"Unable to generate sensor definition hash")

return capabilities
14 changes: 14 additions & 0 deletions src/initialization/sensor_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def load_sensor(sensor_capabilities: dict) -> Sensor:
sigan = None
try:
if not settings.RUNNING_MIGRATIONS:
check_for_required_sigan_settings()
sigan_module_setting = settings.SIGAN_MODULE
sigan_module = importlib.import_module(sigan_module_setting)
logger.info(
Expand All @@ -97,6 +98,19 @@ def load_sensor(sensor_capabilities: dict) -> Sensor:
return sensor


def check_for_required_sigan_settings():
error = ""
raise_exception = False
if settings.SIGAN_MODULE is None:
raise_exception = True
error = "SIGAN_MODULE environment variable must be set. "
if settings.SIGAN_CLASS is None:
raise_exception = True
error += "SIGAN_CLASS environment variable. "
if raise_exception:
raise Exception(error)


def load_switches(switch_dir: Path) -> dict:
logger.debug(f"Loading switches in {switch_dir}")
switch_dict = {}
Expand Down
6 changes: 3 additions & 3 deletions src/sensor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@
"PORT": "5432",
}
}
DEVICE_MODEL = env("DEVICE_MODEL", default="RSA507A")
SIGAN_MODULE = env.str("SIGAN_MDOULE", default="scos_tekrsa.hardware.tekrsa_sigan")
SIGAN_CLASS = env.str("SIGAN_CLASS", default="TekRSASigan")
DEVICE_MODEL = env("DEVICE_MODEL", default=None)
SIGAN_MODULE = env.str("SIGAN_MDOULE", default=None)
SIGAN_CLASS = env.str("SIGAN_CLASS", default=None)

if not IN_DOCKER:
DATABASES["default"]["HOST"] = "localhost"
Expand Down

0 comments on commit 4dcfd4f

Please sign in to comment.