summaryrefslogtreecommitdiff
path: root/tools/jwt_producer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/jwt_producer.py')
-rw-r--r--tools/jwt_producer.py39
1 files changed, 27 insertions, 12 deletions
diff --git a/tools/jwt_producer.py b/tools/jwt_producer.py
index a8f9ded..9f30439 100644
--- a/tools/jwt_producer.py
+++ b/tools/jwt_producer.py
@@ -14,11 +14,22 @@ def usage():
sys.exit(0)
-def create_token(private_key, write_domain, read_domain):
+def create_token(private_key, write_domains, read_domains):
+ write_claim = list()
+ read_claim = list()
+
+ if write_domains:
+ write_claim = write_domains.split(',')
+
+ if read_domains:
+ read_claim = read_domains.split(',')
+
payload = {
+ 'sub': 'test',
+ 'fresh': False,
'type': 'access',
- 'write': [write_domain],
- 'read': [read_domain]
+ 'write': write_claim,
+ 'read': read_claim
}
with open(private_key, "r") as fd:
@@ -28,30 +39,34 @@ def create_token(private_key, write_domain, read_domain):
if __name__ == '__main__':
- read_domain = ''
- write_domain = ''
+ read_domains = None
+ write_domains = None
+ private_key = None
try:
opts, args = getopt.getopt(sys.argv[1:], 'p:w:r:h')
except getopt.GetoptError:
usage()
- if len(sys.argv) != 5:
- usage()
-
for opt, arg in opts:
if opt == '-p':
private_key = arg
elif opt == '-w':
- write_domain = arg
+ write_domains = arg
elif opt == '-r':
- read_domain = arg
+ read_domains = arg
elif opt == '-h':
usage()
else:
usage()
- token = create_token(private_key, write_domain,
- read_domain).decode('utf-8')
+ if not private_key:
+ usage()
+
+ if not write_domains and not read_domains:
+ usage()
+
+ token = create_token(private_key, write_domains,
+ read_domains)
print(f'{token}')