From 231ea6a4f386cf6c1af19c9d950457666100c2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Thu, 10 May 2018 14:48:26 +0200 Subject: [PATCH] Add API key generator script --- api/generate_api_key.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 api/generate_api_key.py diff --git a/api/generate_api_key.py b/api/generate_api_key.py new file mode 100644 index 0000000..fbd415b --- /dev/null +++ b/api/generate_api_key.py @@ -0,0 +1,24 @@ +import argparse +import os + +import itsdangerous + + +def generate(secret_key, username, expiration): + s = itsdangerous.TimedJSONWebSignatureSerializer(secret_key, expires_in=expiration) + return s.dumps(username) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('username', metavar='USERNAME', help='user name') + parser.add_argument('expiration', metavar='EXPIRATION', type=int, + help='expiration time in seconds') + args = parser.parse_args() + secret_key = os.getenv('SECRET_KEY') + api_key = generate(secret_key, args.username, args.expiration) + print(api_key.decode('utf-8')) + + +if __name__ == '__main__': + main()