-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen_jwt.py
executable file
·50 lines (41 loc) · 1.47 KB
/
gen_jwt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import argparse
import sys
import os
script_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(script_dir, '..'))
try:
from src.core.auth import Auth
from src.core.config import Config
except Exception as ex:
print('WARNING: Failed to load imports: {0}'.format(ex))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--api-key', help='The API key to encode in the token.')
parser.add_argument('--secret', help='The secret to build the JWT with.')
parser.add_argument('--stage',
choices=Config.Stages.ALL,
help='The stage to load from the config file')
args = parser.parse_args()
api_keys = []
api_key = args.api_key
secret = args.secret
stage = args.stage
if stage:
print('Loading secret and API keys from configuration for: {0}'.format(stage))
ssm_config = Config.open_local('private.ssm.env.json', stage=stage)
secret = ssm_config['JWT_SECRET']
if not api_key:
api_keys = ssm_config['JWT_API_KEYS'].split(',')
else:
if not api_key and not secret:
print('Secret and API key are required when not using --stage.')
return
api_keys.append(api_key)
for key in api_keys:
token = Auth.encode_jwt(secret, key)
print('-' * 80)
print('API Key: {0}'.format(key))
print('JWT: {0}'.format(token))
if __name__ == "__main__":
main()