JWT authorization token generation for custom scripts to change parameters via the api
19173296 opened this issue · 2 comments
19173296 commented
Hi, I am currently working on a python program that needs to change the operation mode of TART to 'raw' and then back to ''vis' mode after this program is executed. I see that the API allows TART's mode to be changed,but I don't see a way to generate an API Token.
Can you guide me in the right direction to generate a JWT token?
tmolteno commented
Here is an example that should do the trick. The package tart_tools needs to be installed from pip before using. Let me know if this works.
import argparse
from tart_tools.api_handler import AuthorizedAPIhandler
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Change telescope mode', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--api', required=False, default='https://tart.elec.ac.nz/signal', help="Telescope API server URL.")
parser.add_argument('--pw', default='password', type=str, help='API password')
parser.add_argument('--mode', type=str, required=True, help='New mode (vis/raw)')
ARGS = parser.parse_args()
api = AuthorizedAPIhandler(ARGS.api, ARGS.pw)
resp = api.post_payload_with_token(f"mode/{ARGS.mode}", {})
19173296 commented
Thank you for your help. It is working perfectly.