34 lines
906 B
Python
34 lines
906 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(map(lambda s: s.isspace(), 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())
|