Created
May 16, 2017 18:28
-
-
Save luisdavim/3f7c9b8d69083880cafe35557d2eab82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# usage: | |
# generate-dcos-token.py -m <master_token> -u [email protected] -e 365 | |
# and you get the master_token from /var/lib/dcos/dcos-oauth/auth-token-secret | |
import jwt | |
import time | |
from datetime import datetime | |
from datetime import timedelta | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"-u", | |
"--user", | |
dest="user_email", | |
required=True, | |
help="user email address", | |
metavar="USER" | |
) | |
parser.add_argument( | |
"-m", | |
"--master-secret", | |
dest="master_secret", | |
required=True, | |
help="master secret", | |
metavar="MASTER-SECRET" | |
) | |
parser.add_argument( | |
"-e", | |
"--expiration", | |
dest="expiration", | |
default=365, | |
type=int, | |
help="expiration time in days (default:365)", | |
metavar="EXPIRATION" | |
) | |
options = parser.parse_args() | |
exp_time = time.time() + (3600 * 24 * options.expiration) | |
token = jwt.encode({'exp': exp_time, 'uid': options.user_email}, options.master_secret, algorithm='HS256') | |
print (token.decode(encoding='UTF-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment