From 1ac718efc39523e1336686952e22016bfb2b069a Mon Sep 17 00:00:00 2001 From: Brayan Almonte Date: Thu, 21 Sep 2023 09:58:15 -0400 Subject: [PATCH] feat(api): add settings option to reset ssh authorized keys (#13614) --- api/src/opentrons/config/reset.py | 15 +++++++++++++++ .../test_settings_reset_options_flex.tavern.yaml | 3 +++ 2 files changed, 18 insertions(+) diff --git a/api/src/opentrons/config/reset.py b/api/src/opentrons/config/reset.py index ac5df2a7981..ccba3b2fdcb 100644 --- a/api/src/opentrons/config/reset.py +++ b/api/src/opentrons/config/reset.py @@ -15,6 +15,7 @@ DATA_BOOT_D = Path("/data/boot.d") +AUTHORIZED_KEYS = Path(os.path.expanduser("~/.ssh/authorized_keys")) log = logging.getLogger(__name__) @@ -39,6 +40,7 @@ class ResetOptionId(str, Enum): runs_history = "runsHistory" on_device_display = "onDeviceDisplay" module_calibration = "moduleCalibration" + authorized_keys = "authorizedKeys" _OT_2_RESET_OPTIONS = [ @@ -55,6 +57,7 @@ class ResetOptionId(str, Enum): ResetOptionId.runs_history, ResetOptionId.on_device_display, ResetOptionId.module_calibration, + ResetOptionId.authorized_keys, ] _settings_reset_options = { @@ -92,6 +95,9 @@ class ResetOptionId(str, Enum): ResetOptionId.module_calibration: CommonResetOption( name="Module Calibrations", description="Clear module offset calibrations" ), + ResetOptionId.authorized_keys: CommonResetOption( + name="SSH Authorized Keys", description="Clear the ssh authorized keys" + ), } @@ -132,6 +138,9 @@ def reset(options: Set[ResetOptionId]) -> None: if ResetOptionId.module_calibration in options: reset_module_calibration() + if ResetOptionId.authorized_keys in options: + reset_authorized_keys() + def reset_boot_scripts() -> None: if IS_ROBOT: @@ -170,3 +179,9 @@ def reset_module_calibration() -> None: clear_module_offset_calibrations() except ImportError: log.warning("Tried to clear module offset calibrations on an OT-2") + + +def reset_authorized_keys() -> None: + if IS_ROBOT and os.path.exists(AUTHORIZED_KEYS): + with open(AUTHORIZED_KEYS, "w") as fh: + fh.write("") diff --git a/robot-server/tests/integration/test_settings_reset_options_flex.tavern.yaml b/robot-server/tests/integration/test_settings_reset_options_flex.tavern.yaml index 0cb7f8e3c47..ee84f60ee68 100644 --- a/robot-server/tests/integration/test_settings_reset_options_flex.tavern.yaml +++ b/robot-server/tests/integration/test_settings_reset_options_flex.tavern.yaml @@ -30,6 +30,9 @@ stages: - id: moduleCalibration name: Module Calibrations description: !re_search 'Clear module offset calibrations' + - id: authorizedKeys + name: SSH Authorized Keys + description: !re_search 'Clear the ssh authorized keys' - name: POST Reset gripperOffsetCalibrations true on OT-3 request: