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

Redact token in configurator #73

Merged
merged 4 commits into from
Aug 20, 2022
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
18 changes: 14 additions & 4 deletions synadm/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def load(self):
return False
else:
if key == "token":
self.log.debug("Config entry read. %s: SECRET", key)
self.log.debug("Config entry read. %s: REDACTED", key)
else:
self.log.debug("Config entry read. %s: %s", key, value)
if self.output_format_cli: # we have a cli output format override
Expand Down Expand Up @@ -367,6 +367,15 @@ def config_cmd(helper, user, token, base_url, admin_path, matrix_path,
always asked interactively. Command line options override the suggested
defaults in the prompts.
"""
def get_redacted_token_prompt(cli_token):
redacted = "NOT SET" # Show as empty: [].
if cli_token:
redacted = "REDACTED" # Token passed via cli, show [REDACTED]
else:
conf_token = helper.config.get("token", None)
if conf_token:
redacted = "REDACTED" # Token found in config, show [REDACTED]
return f"Synapse admin user token [{redacted}]"

if helper.batch:
if not all([user, token, base_url, admin_path, matrix_path,
Expand Down Expand Up @@ -398,8 +407,9 @@ def config_cmd(helper, user, token, base_url, admin_path, matrix_path,
"Synapse admin user name",
default=user if user else helper.config.get("user", user)),
"token": click.prompt(
"Synapse admin user token",
default=token if token else helper.config.get("token", token)),
get_redacted_token_prompt(token),
default=token if token else helper.config.get("token", token),
show_default=False,),
"base_url": click.prompt(
"Synapse base URL",
default=base_url if base_url else helper.config.get(
Expand All @@ -421,7 +431,7 @@ def config_cmd(helper, user, token, base_url, admin_path, matrix_path,
default=timeout if timeout else helper.config.get(
"timeout", timeout)),
"homeserver": click.prompt(
"Homeserver name, (auto-retrieval or matrix.DOMAIN)",
"Homeserver name (auto-retrieval or matrix.DOMAIN)",
default=homeserver if homeserver else helper.config.get(
"homeserver", homeserver)),
"server_discovery": click.prompt(
Expand Down