From c1402229b64d90836a39744888be387a4296bcbf Mon Sep 17 00:00:00 2001 From: Callum Brown Date: Fri, 20 Aug 2021 17:26:33 +0100 Subject: [PATCH 1/5] Add support for registration token management --- README.md | 8 +- doc/source/index_cli_reference.rst | 1 + doc/source/synadm.cli.regtok.rst | 6 ++ synadm/api.py | 108 ++++++++++++++++++++++ synadm/cli/__init__.py | 2 +- synadm/cli/regtok.py | 140 +++++++++++++++++++++++++++++ 6 files changed, 263 insertions(+), 2 deletions(-) create mode 100644 doc/source/synadm.cli.regtok.rst create mode 100644 synadm/cli/regtok.py diff --git a/README.md b/README.md index 64a53dc2..a6505a1f 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,12 @@ python3 setup.py install * [ ] `user create ` (alias of `user modify ...`) * [x] [Server Version](https://matrix-org.github.io/synapse/develop/admin_api/version_api.html) * [x] `version` +* [x] [Registration Tokens](https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/registration_tokens.html) + * [x] `regtok list` + * [x] `regtok details ` + * [x] `regtok new` + * [x] `regtok update ` + * [x] `regtok delete ` @@ -342,4 +348,4 @@ https://github.com/JOJ0/synadm/blob/107d34b38de71d6d21d78141e78a1b19d3dd5379/syn ### Developer's documentation -Have a look at [synadm's module documentation pages on readthedocs](https://synadm.readthedocs.io/en/latest/index_modules.html) \ No newline at end of file +Have a look at [synadm's module documentation pages on readthedocs](https://synadm.readthedocs.io/en/latest/index_modules.html) diff --git a/doc/source/index_cli_reference.rst b/doc/source/index_cli_reference.rst index 58691155..1bb010c7 100644 --- a/doc/source/index_cli_reference.rst +++ b/doc/source/index_cli_reference.rst @@ -13,3 +13,4 @@ Command Line Reference synadm.cli.history synadm.cli.group synadm.cli.matrix + synadm.cli.regtok diff --git a/doc/source/synadm.cli.regtok.rst b/doc/source/synadm.cli.regtok.rst new file mode 100644 index 00000000..d5d0f64b --- /dev/null +++ b/doc/source/synadm.cli.regtok.rst @@ -0,0 +1,6 @@ +Regtok +====== + +.. click:: synadm.cli.regtok:regtok + :prog: synadm regtok + :nested: full diff --git a/synadm/api.py b/synadm/api.py index 4368c53b..1d521ed3 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -651,3 +651,111 @@ def purge_history_status(self, purge_id): The status will be one of active, complete, or failed. """ return self.query("get", f"v1/purge_history_status/{purge_id}") + + def regtok_list(self, valid): + """ List registration tokens + + Args: + valid (bool): list only valid (if True) or invalid (if False) + tokens. Default is to list all tokens regardless of validity. + + Returns: + string: JSON string containing the admin API's response or None if + an exception occured. See Synapse admin API docs for details. + + """ + return self.query("get", "v1/registration_tokens", params={ + "valid": (str(valid).lower() if isinstance(valid, bool) + else None) + }) + + def regtok_details(self, token): + """ Get details about the given registration token + + Args: + token (string): the registration token in question + + Returns: + string: JSON string containing the admin API's response or None if + an exception occured. See Synapse admin API docs for details. + + """ + return self.query("get", f"v1/registration_tokens/{token}") + + def regtok_new(self, token, length, uses_allowed, expiry_time): + """ Create a new registration token + + Args: + token (string): registration token to create. Default is randomly + generated by the server. + length (int): The length of the token to generate if the token is + not provided. + uses_allowed (int): The number of times the token can be used to + complete a registration before it becomes invalid. + expiry_time (int): The latest time the registration token is valid. + Given as the number of milliseconds since + 1970-01-01 00:00:00 UTC. + + Returns: + string: JSON string containing the admin API's response or None if + an exception occured. See Synapse admin API docs for details. + + """ + data={ + "length": length, + "uses_allowed": uses_allowed, + "expiry_time": expiry_time, + } + # The token cannot be null, it must be a string + if isinstance(token, str): + data["token"] = token + return self.query("post", "v1/registration_tokens/new", data=data) + + def regtok_update(self, token, uses_allowed, expiry_time): + """ Update a registration token + + Args: + token (string): registration token to update. + uses_allowed (int): The number of times the token can be used to + complete a registration before it becomes invalid. + expiry_time (int): The latest time the registration token is valid. + Given as the number of milliseconds since + 1970-01-01 00:00:00 UTC. + + Returns: + string: JSON string containing the admin API's response or None if + an exception occured. See Synapse admin API docs for details. + + """ + # If uses_allowed or expiry_time were not provided by the user, + # do not add the corresponding parameter to the request so that + # the server will not modify its value. + data={} + + if uses_allowed == -1: + # A null value indicates unlimited uses + data["uses_allowed"] = None + elif uses_allowed is not None: + data["uses_allowed"] = uses_allowed + + if expiry_time == -1: + # A null value indicates no expiry + data["expiry_time"] = None + elif expiry_time is not None: + data["expiry_time"] = expiry_time + + return self.query("put", f"v1/registration_tokens/{token}", data=data) + + + def regtok_delete(self, token): + """ Delete a registration token + + Args: + token (string): the registration token to delete + + Returns: + string: JSON string containing the admin API's response or None if + an exception occured. See Synapse admin API docs for details. + + """ + return self.query("delete", f"v1/registration_tokens/{token}") diff --git a/synadm/cli/__init__.py b/synadm/cli/__init__.py index bc2d3981..17b9f791 100644 --- a/synadm/cli/__init__.py +++ b/synadm/cli/__init__.py @@ -320,4 +320,4 @@ def version(helper): # Import additional commands -from synadm.cli import room, user, media, group, history, matrix +from synadm.cli import room, user, media, group, history, matrix, regtok diff --git a/synadm/cli/regtok.py b/synadm/cli/regtok.py new file mode 100644 index 00000000..3d609106 --- /dev/null +++ b/synadm/cli/regtok.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +# synadm +# Copyright (C) 2021 Callum Brown +# +# synadm is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# synadm is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +""" Registration token-related CLI commands +""" + +import click +from click_option_group import optgroup, MutuallyExclusiveOptionGroup +from click_option_group import RequiredAnyOptionGroup + +from synadm import cli + + +@cli.root.group() +def regtok(): + """ Manage registration tokens + """ + + +@regtok.command(name="list") +@click.option( + "--valid/--invalid", "-v/-V", default=None, show_default=True, + help="list only valid/invalid tokens.") +@click.pass_obj +def regtok_list_cmd(helper, valid): + """ List registration tokens + """ + regtoks = helper.api.regtok_list(valid) + if regtoks is None: + click.echo("Registration tokens could not be fetched.") + raise SystemExit(1) + if "registration_tokens" not in regtoks: + # Display error + helper.output(regtoks) + elif helper.output_format == "human": + if regtoks["registration_tokens"] == []: + click.echo("No registration tokens.") + else: + helper.output(regtoks["registration_tokens"]) + else: + helper.output(regtoks) + + +@regtok.command(name="details") +@click.argument("token", type=str) +@click.pass_obj +def regtok_details_cmd(helper, token): + """ View details of the given token + """ + regtok = helper.api.regtok_details(token) + if regtok is None: + click.echo("Registration token could not be fetched.") + raise SystemExit(1) + helper.output(regtok) + + +@regtok.command(name="new") +@click.option( + "--token", "-t", type=str, default=None, + help="""Set the registration token. The default is a random value + generated by the server.""", show_default=True) +@click.option( + "--length", "-l", type=int, default=16, + help="""The length of the randomly generated token if the token is not + specified.""", show_default=True) +@click.option( + "--uses-allowed", "-u", type=int, default=None, + help="""The number of times the token can be used to complete a + registration before it becomes invalid. [default: unlimited uses]""", + show_default=True) +@click.option( + "--expiry-time", "-e", type=int, default=None, + help="""The latest time the registration token is valid. + Given as the number of milliseconds since 1970-01-01 00:00:00 UTC. + [default: no expiry]""", + show_default=True) +@click.pass_obj +def regtok_new(helper, token, length, uses_allowed, expiry_time): + """ Create a new registration token + """ + regtok = helper.api.regtok_new(token, length, uses_allowed, expiry_time) + if regtok is None: + click.echo("Registration token could not be created.") + raise SystemExit(1) + helper.output(regtok) + + +@regtok.command(name="update") +@click.argument("token", type=str) +@click.option( + "--uses-allowed", "-u", type=int, default=None, + help="""The number of times the token can be used to complete a + registration before it becomes invalid. Use -1 for an unlimited + number of uses. [default: unchanged]""", + show_default=True) +@click.option( + "--expiry-time", "-e", type=int, default=None, + help="""The latest time the registration token is valid. + Given as the number of milliseconds since 1970-01-01 00:00:00 UTC. + Use -1 for no expiration. [default: unchanged]""", + show_default=True) +@click.pass_obj +def regtok_update(helper, token, uses_allowed, expiry_time): + """ Update a registration token + """ + regtok = helper.api.regtok_update(token, uses_allowed, expiry_time) + if regtok is None: + click.echo("Registration token could not be created.") + raise SystemExit(1) + helper.output(regtok) + + +@regtok.command(name="delete") +@click.argument("token", type=str) +@click.pass_obj +def regtok_delete(helper, token): + """ Delete a registration token + """ + response = helper.api.regtok_delete(token) + if response is None: + click.echo("Registration token could not be deleted.") + raise SystemExit(1) + if response == {}: + click.echo("Registration token successfully deleted.") + else: + helper.output(response) From fcd2f1d7bd110bc8cd82e5de2d7992d9d1356e34 Mon Sep 17 00:00:00 2001 From: Callum Brown Date: Wed, 8 Sep 2021 11:21:53 +0100 Subject: [PATCH 2/5] regtok: human-friendly expiry time input --- synadm/api.py | 50 ++++++++++++++++++++++++++++++-------------- synadm/cli/regtok.py | 24 +++++++++++++++------ 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/synadm/api.py b/synadm/api.py index 1d521ed3..657d5cc6 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -665,8 +665,7 @@ def regtok_list(self, valid): """ return self.query("get", "v1/registration_tokens", params={ - "valid": (str(valid).lower() if isinstance(valid, bool) - else None) + "valid": (str(valid).lower() if isinstance(valid, bool) else None) }) def regtok_details(self, token): @@ -682,7 +681,7 @@ def regtok_details(self, token): """ return self.query("get", f"v1/registration_tokens/{token}") - def regtok_new(self, token, length, uses_allowed, expiry_time): + def regtok_new(self, token, length, uses_allowed, expiry_ts, expire_at): """ Create a new registration token Args: @@ -692,45 +691,59 @@ def regtok_new(self, token, length, uses_allowed, expiry_time): not provided. uses_allowed (int): The number of times the token can be used to complete a registration before it becomes invalid. - expiry_time (int): The latest time the registration token is valid. + expiry_ts (int): The latest time the registration token is valid. Given as the number of milliseconds since 1970-01-01 00:00:00 UTC. + expire_at (click.DateTime): The latest time the registration token + is valid. Returns: string: JSON string containing the admin API's response or None if an exception occured. See Synapse admin API docs for details. """ - data={ + data = { "length": length, "uses_allowed": uses_allowed, - "expiry_time": expiry_time, } + + if expiry_ts: + self.log.debug(f"Received --expiry-ts: {expiry_ts}") + data["expiry_time"] = expiry_ts + elif expire_at: + self.log.debug(f"Received --expire-at: {expire_at}") + data["expiry_time"] = self._timestamp_from_datetime(expire_at) + else: + data["expiry_time"] = None + # The token cannot be null, it must be a string if isinstance(token, str): data["token"] = token + return self.query("post", "v1/registration_tokens/new", data=data) - def regtok_update(self, token, uses_allowed, expiry_time): + def regtok_update(self, token, uses_allowed, expiry_ts, expire_at): """ Update a registration token Args: token (string): registration token to update. uses_allowed (int): The number of times the token can be used to complete a registration before it becomes invalid. - expiry_time (int): The latest time the registration token is valid. + expiry_ts (int): The latest time the registration token is valid. Given as the number of milliseconds since - 1970-01-01 00:00:00 UTC. + 1970-01-01 00:00:00 UTC. -1 indicates no expiry. + expire_at (click.DateTime): The latest time the registration token + is valid. Returns: string: JSON string containing the admin API's response or None if an exception occured. See Synapse admin API docs for details. """ - # If uses_allowed or expiry_time were not provided by the user, + # If uses_allowed or expiry time were not provided by the user, # do not add the corresponding parameter to the request so that # the server will not modify its value. - data={} + data = {} if uses_allowed == -1: # A null value indicates unlimited uses @@ -738,11 +751,16 @@ def regtok_update(self, token, uses_allowed, expiry_time): elif uses_allowed is not None: data["uses_allowed"] = uses_allowed - if expiry_time == -1: - # A null value indicates no expiry - data["expiry_time"] = None - elif expiry_time is not None: - data["expiry_time"] = expiry_time + if expiry_ts: + self.log.debug(f"Received --expiry-ts: {expiry_ts}") + if expiry_ts == -1: + # A null value indicates no expiry + data["expiry_time"] = None + else: + data["expiry_time"] = expiry_ts + elif expire_at: + self.log.debug(f"Received --expire-at: {expire_at}") + data["expiry_time"] = self._timestamp_from_datetime(expire_at) return self.query("put", f"v1/registration_tokens/{token}", data=data) diff --git a/synadm/cli/regtok.py b/synadm/cli/regtok.py index 3d609106..7fa399aa 100644 --- a/synadm/cli/regtok.py +++ b/synadm/cli/regtok.py @@ -83,16 +83,23 @@ def regtok_details_cmd(helper, token): registration before it becomes invalid. [default: unlimited uses]""", show_default=True) @click.option( - "--expiry-time", "-e", type=int, default=None, + "--expiry-ts", "-t", type=int, default=None, help="""The latest time the registration token is valid. Given as the number of milliseconds since 1970-01-01 00:00:00 UTC. [default: no expiry]""", show_default=True) +@click.option( + "--expire-at", "-e", type=click.DateTime(), default=None, + help="""The latest time the registration token is valid. + See above for available date/time formats. [default: no expiry]""", + show_default=True) @click.pass_obj -def regtok_new(helper, token, length, uses_allowed, expiry_time): +def regtok_new(helper, token, length, uses_allowed, expiry_ts, expire_at): """ Create a new registration token """ - regtok = helper.api.regtok_new(token, length, uses_allowed, expiry_time) + regtok = helper.api.regtok_new( + token, length, uses_allowed, expiry_ts, expire_at + ) if regtok is None: click.echo("Registration token could not be created.") raise SystemExit(1) @@ -108,16 +115,21 @@ def regtok_new(helper, token, length, uses_allowed, expiry_time): number of uses. [default: unchanged]""", show_default=True) @click.option( - "--expiry-time", "-e", type=int, default=None, + "--expiry-ts", "-t", type=int, default=None, help="""The latest time the registration token is valid. Given as the number of milliseconds since 1970-01-01 00:00:00 UTC. Use -1 for no expiration. [default: unchanged]""", show_default=True) +@click.option( + "--expire-at", "-e", type=click.DateTime(), default=None, + help="""The latest time the registration token is valid. + See above for available date/time formats. [default: unchanged]""", + show_default=True) @click.pass_obj -def regtok_update(helper, token, uses_allowed, expiry_time): +def regtok_update(helper, token, uses_allowed, expiry_ts, expire_at): """ Update a registration token """ - regtok = helper.api.regtok_update(token, uses_allowed, expiry_time) + regtok = helper.api.regtok_update(token, uses_allowed, expiry_ts, expire_at) if regtok is None: click.echo("Registration token could not be created.") raise SystemExit(1) From f0b6e0087180ec9bdde9ddfdfed54d16cca3ff09 Mon Sep 17 00:00:00 2001 From: Callum Brown Date: Mon, 13 Sep 2021 11:51:29 +0100 Subject: [PATCH 3/5] regtok: Display expiry time as datetime by default --- synadm/api.py | 42 +++++++++++++++++++++++++++++++++--------- synadm/cli/regtok.py | 18 +++++++++++++----- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/synadm/api.py b/synadm/api.py index 657d5cc6..d281ac6a 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -652,40 +652,64 @@ def purge_history_status(self, purge_id): """ return self.query("get", f"v1/purge_history_status/{purge_id}") - def regtok_list(self, valid): + def regtok_list(self, valid, datetime): """ List registration tokens Args: - valid (bool): list only valid (if True) or invalid (if False) + valid (bool): List only valid (if True) or invalid (if False) tokens. Default is to list all tokens regardless of validity. + datetime (bool): If True, replace the expiry_time field with a + human readable datetime. If False, expiry_time will be a unix + timestamp. Returns: string: JSON string containing the admin API's response or None if an exception occured. See Synapse admin API docs for details. """ - return self.query("get", "v1/registration_tokens", params={ + result = self.query("get", "v1/registration_tokens", params={ "valid": (str(valid).lower() if isinstance(valid, bool) else None) }) - def regtok_details(self, token): + # Change expiry_time to a human readable format if requested + if datetime and result is not None and "registration_tokens" in result: + for i, regtok in enumerate(result["registration_tokens"]): + expiry_time = regtok["expiry_time"] + if expiry_time is not None: + datetime = self._datetime_from_timestamp(expiry_time) + result["registration_tokens"][i]["expiry_time"] = datetime + + return result + + def regtok_details(self, token, datetime): """ Get details about the given registration token Args: - token (string): the registration token in question + token (string): The registration token in question + datetime (bool): If True, replace the expiry_time field with a + human readable datetime. If False, expiry_time will be a unix + timestamp. Returns: string: JSON string containing the admin API's response or None if an exception occured. See Synapse admin API docs for details. """ - return self.query("get", f"v1/registration_tokens/{token}") + result = self.query("get", f"v1/registration_tokens/{token}") + + # Change expiry_time to a human readable format if requested + if datetime and result is not None: + if result["expiry_time"] is not None: + datetime = self._datetime_from_timestamp(result["expiry_time"]) + result["expiry_time"] = datetime + + return result def regtok_new(self, token, length, uses_allowed, expiry_ts, expire_at): """ Create a new registration token Args: - token (string): registration token to create. Default is randomly + token (string): Registration token to create. Default is randomly generated by the server. length (int): The length of the token to generate if the token is not provided. @@ -726,7 +750,7 @@ def regtok_update(self, token, uses_allowed, expiry_ts, expire_at): """ Update a registration token Args: - token (string): registration token to update. + token (string): Registration token to update. uses_allowed (int): The number of times the token can be used to complete a registration before it becomes invalid. expiry_ts (int): The latest time the registration token is valid. @@ -769,7 +793,7 @@ def regtok_delete(self, token): """ Delete a registration token Args: - token (string): the registration token to delete + token (string): The registration token to delete Returns: string: JSON string containing the admin API's response or None if diff --git a/synadm/cli/regtok.py b/synadm/cli/regtok.py index 7fa399aa..111b1730 100644 --- a/synadm/cli/regtok.py +++ b/synadm/cli/regtok.py @@ -34,12 +34,16 @@ def regtok(): @regtok.command(name="list") @click.option( "--valid/--invalid", "-v/-V", default=None, show_default=True, - help="list only valid/invalid tokens.") + help="List only valid/invalid tokens.") +@click.option( + "--datetime/--timestamp", "-d/-t", default=True, show_default=False, + help="""Display expiry time in a human readable format, or as a unix + timestamp in milliseconds. [default: datetime].""") @click.pass_obj -def regtok_list_cmd(helper, valid): +def regtok_list_cmd(helper, valid, datetime): """ List registration tokens """ - regtoks = helper.api.regtok_list(valid) + regtoks = helper.api.regtok_list(valid, datetime) if regtoks is None: click.echo("Registration tokens could not be fetched.") raise SystemExit(1) @@ -57,11 +61,15 @@ def regtok_list_cmd(helper, valid): @regtok.command(name="details") @click.argument("token", type=str) +@click.option( + "--datetime/--timestamp", "-d/-t", default=True, show_default=False, + help="""Display expiry time in a human readable format, or as a unix + timestamp in milliseconds. [default: datetime].""") @click.pass_obj -def regtok_details_cmd(helper, token): +def regtok_details_cmd(helper, token, datetime): """ View details of the given token """ - regtok = helper.api.regtok_details(token) + regtok = helper.api.regtok_details(token, datetime) if regtok is None: click.echo("Registration token could not be fetched.") raise SystemExit(1) From 323c33d50c2a2a4cf38cd7503519f5450ac7895d Mon Sep 17 00:00:00 2001 From: Callum Brown Date: Mon, 13 Sep 2021 17:56:36 +0100 Subject: [PATCH 4/5] regtok: Convert datetime to string for output json and pprint output formats don't automatically convert a python datetime object to a string. --- synadm/api.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/synadm/api.py b/synadm/api.py index d281ac6a..86277f6d 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -652,14 +652,14 @@ def purge_history_status(self, purge_id): """ return self.query("get", f"v1/purge_history_status/{purge_id}") - def regtok_list(self, valid, datetime): + def regtok_list(self, valid, readable_expiry): """ List registration tokens Args: valid (bool): List only valid (if True) or invalid (if False) tokens. Default is to list all tokens regardless of validity. - datetime (bool): If True, replace the expiry_time field with a - human readable datetime. If False, expiry_time will be a unix + readable_expiry (bool): If True, replace the expiry_time field with + a human readable datetime. If False, expiry_time will be a unix timestamp. Returns: @@ -672,22 +672,25 @@ def regtok_list(self, valid, datetime): }) # Change expiry_time to a human readable format if requested - if datetime and result is not None and "registration_tokens" in result: + if readable_expiry and result is not None and "registration_tokens" in result: for i, regtok in enumerate(result["registration_tokens"]): expiry_time = regtok["expiry_time"] if expiry_time is not None: - datetime = self._datetime_from_timestamp(expiry_time) - result["registration_tokens"][i]["expiry_time"] = datetime + result["registration_tokens"][i][ + "expiry_time" + ] = self._datetime_from_timestamp(expiry_time).strftime( + "%Y-%m-%d %H:%M:%S" + ) return result - def regtok_details(self, token, datetime): + def regtok_details(self, token, readable_expiry): """ Get details about the given registration token Args: token (string): The registration token in question - datetime (bool): If True, replace the expiry_time field with a - human readable datetime. If False, expiry_time will be a unix + readable_expiry (bool): If True, replace the expiry_time field with + a human readable datetime. If False, expiry_time will be a unix timestamp. Returns: @@ -698,10 +701,11 @@ def regtok_details(self, token, datetime): result = self.query("get", f"v1/registration_tokens/{token}") # Change expiry_time to a human readable format if requested - if datetime and result is not None: + if readable_expiry and result is not None: if result["expiry_time"] is not None: - datetime = self._datetime_from_timestamp(result["expiry_time"]) - result["expiry_time"] = datetime + result["expiry_time"] = self._datetime_from_timestamp( + result["expiry_time"] + ).strftime("%Y-%m-%d %H:%M:%S") return result From ebc22a307d0310c6672ed53949e78f9319e43926 Mon Sep 17 00:00:00 2001 From: Callum Brown Date: Wed, 15 Sep 2021 11:00:54 +0100 Subject: [PATCH 5/5] regtok: Don't show_default where it is hardcoded --- synadm/cli/regtok.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/synadm/cli/regtok.py b/synadm/cli/regtok.py index 111b1730..c74c02a6 100644 --- a/synadm/cli/regtok.py +++ b/synadm/cli/regtok.py @@ -36,7 +36,7 @@ def regtok(): "--valid/--invalid", "-v/-V", default=None, show_default=True, help="List only valid/invalid tokens.") @click.option( - "--datetime/--timestamp", "-d/-t", default=True, show_default=False, + "--datetime/--timestamp", "-d/-t", default=True, help="""Display expiry time in a human readable format, or as a unix timestamp in milliseconds. [default: datetime].""") @click.pass_obj @@ -62,7 +62,7 @@ def regtok_list_cmd(helper, valid, datetime): @regtok.command(name="details") @click.argument("token", type=str) @click.option( - "--datetime/--timestamp", "-d/-t", default=True, show_default=False, + "--datetime/--timestamp", "-d/-t", default=True, help="""Display expiry time in a human readable format, or as a unix timestamp in milliseconds. [default: datetime].""") @click.pass_obj @@ -80,27 +80,24 @@ def regtok_details_cmd(helper, token, datetime): @click.option( "--token", "-t", type=str, default=None, help="""Set the registration token. The default is a random value - generated by the server.""", show_default=True) + generated by the server.""") @click.option( - "--length", "-l", type=int, default=16, + "--length", "-l", type=int, default=16, show_default=True, help="""The length of the randomly generated token if the token is not - specified.""", show_default=True) + specified.""") @click.option( "--uses-allowed", "-u", type=int, default=None, help="""The number of times the token can be used to complete a - registration before it becomes invalid. [default: unlimited uses]""", - show_default=True) + registration before it becomes invalid. [default: unlimited uses]""") @click.option( "--expiry-ts", "-t", type=int, default=None, help="""The latest time the registration token is valid. Given as the number of milliseconds since 1970-01-01 00:00:00 UTC. - [default: no expiry]""", - show_default=True) + [default: no expiry]""") @click.option( "--expire-at", "-e", type=click.DateTime(), default=None, help="""The latest time the registration token is valid. - See above for available date/time formats. [default: no expiry]""", - show_default=True) + See above for available date/time formats. [default: no expiry]""") @click.pass_obj def regtok_new(helper, token, length, uses_allowed, expiry_ts, expire_at): """ Create a new registration token @@ -120,19 +117,16 @@ def regtok_new(helper, token, length, uses_allowed, expiry_ts, expire_at): "--uses-allowed", "-u", type=int, default=None, help="""The number of times the token can be used to complete a registration before it becomes invalid. Use -1 for an unlimited - number of uses. [default: unchanged]""", - show_default=True) + number of uses. [default: unchanged]""") @click.option( "--expiry-ts", "-t", type=int, default=None, help="""The latest time the registration token is valid. Given as the number of milliseconds since 1970-01-01 00:00:00 UTC. - Use -1 for no expiration. [default: unchanged]""", - show_default=True) + Use -1 for no expiration. [default: unchanged]""") @click.option( "--expire-at", "-e", type=click.DateTime(), default=None, help="""The latest time the registration token is valid. - See above for available date/time formats. [default: unchanged]""", - show_default=True) + See above for available date/time formats. [default: unchanged]""") @click.pass_obj def regtok_update(helper, token, uses_allowed, expiry_ts, expire_at): """ Update a registration token