-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
90 lines (63 loc) · 2.12 KB
/
auth.py
File metadata and controls
90 lines (63 loc) · 2.12 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /usr/bin/env python
if __name__ == '__main__':
print "unit testing required"
exit(1)
import sys
import pycurl
import fileinput
import pprint
import simplejson as json
class CreateSession:
def __init__(self):
self.contents = ''
self.json = ''
def body_callback(self, buf):
self.json = self.json + buf
def convert_json(self):
self.contents = json.loads(self.json)
def progress(download_t, download_d, upload_t, upload_d):
print "Total to download", download_t
print "Total downloaded", download_d
print "Total to upload", upload_t
print "Total uploaded", upload_d
def test(debug_type, debug_msg):
print "debug(%d): %s" % (debug_type, debug_msg)
def create(json,config):
if json == None:
print >>sys.stderr, "json is not defined"
exit(111)
if config['debug']:
print >>sys.stderr, 'Create new BookingBug Session', pycurl.version
session_o = CreateSession()
curl_o = pycurl.Curl()
curl_o.setopt(curl_o.URL, config['uri'])
curl_o.setopt(pycurl.HTTPHEADER, ["Accept:application/json", "Content-type:application/json"])
curl_o.setopt(pycurl.USERPWD , "%s:%s" % (config['htuser'], config['htpass']) )
curl_o.setopt(pycurl.POST, 1)
curl_o.setopt(pycurl.POSTFIELDS, json)
curl_o.setopt(curl_o.WRITEFUNCTION, session_o.body_callback)
if config['debug']:
curl_o.setopt(curl_o.PROGRESSFUNCTION, progress)
curl_o.setopt(pycurl.DEBUGFUNCTION, test)
curl_o.setopt(curl_o.NOPROGRESS, 0)
curl_o.setopt(pycurl.VERBOSE, 1)
curl_o.perform()
if config['debug']:
print curl_o.getinfo(pycurl.HTTP_CODE), curl_o.getinfo(pycurl.EFFECTIVE_URL)
curl_o.close()
print session_o.json
session_o.convert_json()
return session_o
def get_json(params_d):
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(params_d)
record_d = (
{
"user":params_d['username'],
"password":params_d['password'],
"company_id":params_d['company_id'],
"ip":params_d['client_ip'],
}
)
json_record_s = json.dumps( record_d, separators=(',',':') )
return json_record_s