Last active
July 17, 2018 05:56
-
-
Save aravindavk/728dda0b74a50e1b89dd35cc418ac68e to your computer and use it in GitHub Desktop.
Glusterd2 REST API Authentication Helper script for curl
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/python3 | |
import sys | |
from datetime import datetime, timedelta | |
import jwt | |
def jwt_token(user, secret): | |
claims = dict() | |
claims['iss'] = user | |
claims['iat'] = datetime.utcnow() | |
claims['exp'] = datetime.utcnow() + timedelta(seconds=10) | |
token = jwt.encode(claims, secret, algorithm='HS256') | |
return (b'Authorization: bearer ' + token).decode() | |
if __name__ == "__main__": | |
user = "glustercli" | |
secret_file = sys.argv[1] | |
secret = open(secret_file).read() | |
print(jwt_token(user, secret)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment