Skip to content

Commit

Permalink
Add experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Nov 17, 2023
1 parent 996e201 commit a8f8cc9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
21 changes: 19 additions & 2 deletions pynitrokey/cli/nk3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pynitrokey.helpers import (
DownloadProgressBar,
Retries,
check_experimental_flag,
local_print,
require_windows_admin,
)
Expand Down Expand Up @@ -505,17 +506,33 @@ def version(ctx: Context) -> None:

@nk3.command()
@click.pass_obj
def factory_reset(ctx: Context) -> None:
@click.option(
"--experimental",
default=False,
is_flag=True,
help="Allow to execute experimental features",
hidden=True,
)
def factory_reset(ctx: Context, experimental: bool) -> None:
"""Factory reset all functionality of the device"""
check_experimental_flag(experimental)
with ctx.connect_device() as device:
device.factory_reset()


@nk3.command()
@click.pass_obj
@click.argument("application", type=click.STRING, required=True)
def factory_reset_app(ctx: Context, application: str) -> None:
@click.option(
"--experimental",
default=False,
is_flag=True,
help="Allow to execute experimental features",
hidden=True,
)
def factory_reset_app(ctx: Context, application: str, experimental: bool) -> None:
"""Factory reset all functionality of an application"""
check_experimental_flag(experimental)
with ctx.connect_device() as device:
device.factory_reset_app(application)

Expand Down
13 changes: 0 additions & 13 deletions pynitrokey/cli/nk3/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,6 @@ def abort_if_not_supported(cond: bool, name: str = "") -> None:
raise click.Abort()


def check_experimental_flag(experimental: bool) -> None:
"""Helper function to show common warning for the experimental features"""
if not experimental:
local_print(" ")
local_print(
"This feature is experimental, which means it was not tested thoroughly.\n"
"Note: data stored with it can be lost in the next firmware update.\n"
"Please pass --experimental switch to force running it anyway."
)
local_print(" ")
raise click.Abort()


def ask_to_touch_if_needed() -> None:
"""Helper function to show common request for the touch if device signalizes it"""
local_print("Please touch the device if it blinks", file=sys.stderr)
Expand Down
13 changes: 13 additions & 0 deletions pynitrokey/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,16 @@ def check_pynitrokey_version() -> None:

if not confirm("Do you still want to continue?", default=False):
raise click.Abort()


def check_experimental_flag(experimental: bool) -> None:
"""Helper function to show common warning for the experimental features"""
if not experimental:
local_print(" ")
local_print(
"This feature is experimental, which means it was not tested thoroughly.\n"
"Note: data stored with it can be lost in the next firmware update.\n"
"Please pass --experimental switch to force running it anyway."
)
local_print(" ")
raise click.Abort()
3 changes: 2 additions & 1 deletion pynitrokey/nk3/admin_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def factory_reset(self) -> None:
reply = self._call(AdminCommand.FACTORY_RESET, response_len=1)
if reply is None:
local_critical(
"Factory reset is not supported by the firmware version on the device", support_hint=False
"Factory reset is not supported by the firmware version on the device",
support_hint=False,
)
return
except OSError as e:
Expand Down

0 comments on commit a8f8cc9

Please sign in to comment.