Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nk3 set-config: Add warning and confirmation prompt #479

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion pynitrokey/cli/nk3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
# http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
# http://opensource.org/licenses/MIT>, at your option. This file may not be
# copied, modified, or distributed except according to those terms.

import logging
import os.path
import sys
from hashlib import sha256
from typing import BinaryIO, Callable, List, Optional, Type, TypeVar

Expand Down Expand Up @@ -488,7 +490,31 @@ def get_config(ctx: Context, key: str) -> None:
@click.argument("key")
@click.argument("value")
def set_config(ctx: Context, key: str, value: str) -> None:
"""Query a config value."""
"""
Set a config value.

This command should not be used directly as it may have unexpected
side effects, for example resetting an application. It is only intended
for development and testing.
"""

# config fields that don’t have side effects
whitelist = [
"fido.disable_skip_up_timeout",
]

if key not in whitelist:
print(
"Changing configuration values can have unexpected side effects, including data loss.",
file=sys.stderr,
)
print(
"This command should only be used for development and testing.",
file=sys.stderr,
)

click.confirm("Do you want to continue anyway?", abort=True)

with ctx.connect_device() as device:
admin = AdminApp(device)
admin.set_config(key, value)
Expand Down