Advertisement
david98031

Untitled

Apr 16th, 2019
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import jwt
  5. import base64
  6. import httplib
  7. import urllib
  8. import ssl
  9. import json
  10. import time
  11.  
  12. def kronos_req(req_type, path, data_js):
  13.     data = json.loads(data_js)
  14.  
  15.     secret = 'C/E3FX1Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + \
  16.              'xxxxxxxxxxxxxxxxxxxxxx=='
  17.  
  18.     headers = {"Content-type": "application/json",
  19.                "Accept": "application/json",
  20.                "Authorization": "Bearer " +
  21.                jwt.encode(data, base64.b64decode(secret), algorithm = 'HS256') }
  22.  
  23.     conn = httplib.HTTPSConnection(host = 'kronosxtst.valleymed.net', port = 9999,
  24.                                    context=ssl._create_unverified_context())
  25.  
  26.     #data_js = json.dumps(data)
  27.     conn.request(req_type, path, data_js, headers)
  28.  
  29.     r1 = conn.getresponse()
  30.     print "Status:", r1.status, r1.reason
  31.     print r1.getheaders()
  32.     content = r1.read()
  33.  
  34.     if len(content) > 0:
  35.         #print json.loads(content)
  36.         print content
  37.  
  38.     conn.close()
  39.  
  40. sub_data = '{"path": "/mypath/update", "host": "myhost.valleymed.org", "scheme": "https", "port": 443, "apiVersion": "1.0"}'
  41.  
  42. print('cancel old subscription:')
  43. kronos_req('DELETE', '/subscription', sub_data)
  44. print('resubscribe:')
  45. kronos_req('POST', '/subscription', sub_data)
  46. print('get inventory:')
  47. kronos_req('GET', '/inventory', sub_data)
  48. while True:
  49.     print('heartbeat:')
  50.     kronos_req('GET', '/heartbeat', sub_data)
  51.     time.sleep(30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement