File: register

package info (click to toggle)
lomiri-push-service 0.100.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,912 kB
  • sloc: python: 936; ansic: 288; makefile: 96; sh: 61
file content (49 lines) | stat: -rwxr-xr-x 1,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
"""
request a unicast registration
"""
import argparse
import json
import requests
import subprocess
import datetime
import sys


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('deviceid', nargs=1)
    parser.add_argument('appid', nargs=1)
    parser.add_argument('-H', '--host',
                        help="host:port (default: %(default)s)",
                        default="localhost:8080")
    parser.add_argument('--no-https', action='store_true', default=False)
    parser.add_argument('--insecure', action='store_true', default=False,
                         help="don't check host/certs with https")
    parser.add_argument('--unregister', action='store_true', default=False)
    args = parser.parse_args()
    scheme = 'https'
    if args.no_https:
        scheme = 'http'
    if args.unregister:
        op = 'unregister'
    else:
        op = 'register'
    url = "%s://%s/%s" % (scheme, args.host, op)
    body = {
        'deviceid': args.deviceid[0],
        'appid': args.appid[0],
        }
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, data=json.dumps(body), headers=headers,
                      verify=not args.insecure)
    if r.status_code == 200 and not args.unregister:
        print(r.json()['token'])
    else:
        print(r.status_code)
        print(r.text)
    if r.status_code != 200:
        sys.exit(1)

if __name__ == '__main__':
    main()