Add API key generator script

master
Nikola Forró 7 years ago
parent 569c0eaa7d
commit 231ea6a4f3

@ -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()
Loading…
Cancel
Save