Belle II Software  release-08-01-10
cdb_create_debug_jwt.py
1 
8 
9 
10 from datetime import datetime, timedelta
11 import getpass
12 # requires pyjwt library which is not present by default yet
13 import jwt
14 
15 filename = "./cdb_token"
16 username = "testuser"
17 validity = timedelta(hours=1)
18 secret = getpass.getpass("JWT Secret: ")
19 
20 payload = {
21  "sub": "testuser",
22  "name": "Dr. Test User",
23  "b2cdb:admin": [f"user_{username}_.*", "staging_online", "online"],
24  "b2cdb:create_iov": ["test_creation.*"],
25  "exp": datetime.utcnow() + validity
26 }
27 
28 with open(filename, "bw") as f:
29  token = jwt.encode(payload, secret)
30  f.write(token.encode('utf8'))