dump-things-service/dump_things_service/commands/hash_token.py
Christian Monch 27458bf13a chore: apply subset of unsafe fixes from hatch check code
This commit applies a subset of the fixes that were applied
via `hatch check code --unsafe-fixes --fix`.
2026-07-01 10:35:08 +02:00

34 lines
875 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)
return 1
print(hash_token_representation(token))
return 0
if __name__ == '__main__':
sys.exit(main())