Belle II Software development
cdb_create_debug_jwt.py
1
8
9
10from datetime import datetime, timedelta
11import getpass
12# requires pyjwt library which is not present by default yet
13import jwt
14
15filename = "./cdb_token"
16username = "testuser"
17validity = timedelta(hours=1)
18secret = getpass.getpass("JWT Secret: ")
19
20payload = {
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
28with open(filename, "bw") as f:
29 token = jwt.encode(payload, secret)
30 f.write(token.encode('utf8'))