Skip to content
Snippets Groups Projects
Commit c64866ea authored by David Hammer's avatar David Hammer
Browse files

Merge branch 'calcat-secrets-configurable-path' into 'master'

Get secrets file path from configuration

See merge request !98
parents 71b6c6d0 7cebca03
No related branches found
No related tags found
1 merge request!98Get secrets file path from configuration
......@@ -271,6 +271,17 @@ class BaseCalcatFriend:
# Parameters which any detector would probably have (extend this in subclass)
# TODO: probably switch to floating point for everything, including mem cells
(
STRING_ELEMENT(schema)
.key("constantParameters.secretsFile")
.displayedName("CalCat secrets file")
.description(
"Path to JSON file specifying secret token and some parameters used to "
"access CalCat."
)
.assignmentOptional()
.defaultValue("~/.calcat-secrets.json")
.commit(),
STRING_ELEMENT(schema)
.key("constantParameters.deviceMappingSnapshotAt")
.tags("managed")
......@@ -375,23 +386,20 @@ class BaseCalcatFriend:
.commit(),
)
def __init__(
self,
device,
secrets_fn: pathlib.Path,
):
def __init__(self, device):
self.device = device
self.cached_constants = {}
self.cached_constants_lock = threading.RLock()
# api lock used to force queries to be sequential (SSL issue on ONC)
self.api_lock = threading.RLock()
if not secrets_fn.is_file():
self.device.log_status_warn(
f"Missing CalCat secrets file (expected {secrets_fn})"
secrets_fn = pathlib.Path(self._get_param("secretsFile")).expanduser()
try:
with secrets_fn.open("r") as fd:
calcat_secrets = json.load(fd)
except Exception as ex:
raise ValueError(
f"Failed to load CalCat secrets from {secrets_fn}: {ex}"
)
with secrets_fn.open("r") as fd:
calcat_secrets = json.load(fd)
self.caldb_store = pathlib.Path(calcat_secrets["caldb_store_path"])
if not self.caldb_store.is_dir():
......
......@@ -515,9 +515,7 @@ class BaseCorrection(PythonDevice):
"deviceInternalsState", WarningLampType.CALCAT_CONNECTION
) as warn:
try:
self.calcat_friend = self._calcat_friend_class(
self, pathlib.Path.cwd() / "calibration-client-secrets.json"
)
self.calcat_friend = self._calcat_friend_class(self)
except Exception as e:
warn(f"Failed to connect to CalCat: {e}")
# TODO: add raw fallback mode if CalCat fails (raw data still useful)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment