dump-things-service/dump_things_service/commands/hash_token.py
Christian Monch 5bb527a8c7 chore: mark print statements as output
This removes code-linter complains by marking
print statements that produce output or error
messages as such.

It also move return-statements in the `try`-branch
of `try-except` clauses to an `else`-branch.
2026-07-01 11:13:34 +02:00

34 lines
943 B
Python

from __future__ import annotations
import sys
from argparse import ArgumentParser
from dump_things_service.abstract_config import hash_token_representation
parser = ArgumentParser(
prog='Hash a plain text token to create a hashed token in a dump-things server',
description='Hash a token and print the calculated hash value. The hash value '
'can be used to create a hashed token via the `/tokens`-endpoint '
'of a dump-things-server.',
)
parser.add_argument(
'token',
type=str,
help='The plain text token',
)
def main():
arguments = parser.parse_args()
token = arguments.token.strip()
if any(s.isspace() for s in token):
print('Whitespace are not allowed in token', file=sys.stderr, flush=True) # noqa T201 -- cli result output
return 1
print(hash_token_representation(token)) # noqa T201 -- cli result output
return 0
if __name__ == '__main__':
sys.exit(main())