You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
684 B
25 lines
684 B
7 years ago
|
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()
|