def summon_query(query_string): url = "http://%s%s?%s" % (config["host"], config["path"], query_string) headers = summon_headers(query_string) #logging.debug("headers: {}".format(headers)) http = httplib2.Http() response, content = http.request(url, 'GET', headers=headers) #logging.debug("content: {}".format(content)) result = jsonbson.load_json_str(content) #logging.debug("result: {}".format(jsonbson.dumps_json(result, True))) return result
def authenticate(username, password): #logging.debug(AUTHENTICATE) auth = {"username": username, "password": password} auth_encoded = urllib.urlencode(auth) url = config["endpoint"] + AUTHENTICATE logging.debug(url) request = urllib2.Request(url, auth_encoded) response = urllib2.urlopen(request) result = jsonbson.load_json_str(response.read()) logging.debug(result) anta_auth = {"token": result["token"], "user_id": username} return anta_auth
def authenticate(username, password): #logging.debug(AUTHENTICATE) data = {"username": username, "password": password} data_encoded = urllib.urlencode(data) url = config["endpoint"] + AUTHENTICATE #logging.debug(url) request = urllib2.Request(url, data_encoded) response = urllib2.urlopen(request) result = jsonbson.load_json_str(response.read()) logging.debug(result) auth_dict = {"token": result["token"], "user_id": username} return auth_dict
def item_upload(anta_auth, item): #logging.debug(ITEMUPLOAD) url = config["endpoint"] + ITEMUPLOAD + USER + anta_auth["user_id"] logging.debug(url) logging.debug(item) item_serialize = phpserialize.serialize(item) item_base64 = base64.b64encode(item_serialize) auth = {"token": anta_auth["token"], "item": item_base64} auth_encoded = urllib.urlencode(auth) request = urllib2.Request(url, auth_encoded) try: response = urllib2.urlopen(request) result = response.read() logging.debug(result) return jsonbson.load_json_str(result) except: logging.debug("*** Error uploading item to anta : %s", item["title"]) return {"status": "ko"}
def document(item): #logging.debug(DOCUMENTS) url = config["endpoint"] + DOCUMENTS #logging.debug(url) #logging.debug(item) if "tags" in item: tags = jsonbson.dumps_json(item["tags"]) del item["tags"] logging.debug(tags) item["tags"] = tags params_encoded = urllib.urlencode(item) logging.debug(params_encoded) request = urllib2.Request(url, params_encoded) response = urllib2.urlopen(request) result = response.read() #logging.debug(result) return jsonbson.load_json_str(result) try: pass except: logging.error("*** Error uploading item to sven : {}".format(item["title"])) return {"status": "error"}
def parse_json_str(input_string): return jsonbson.load_json_str(input_string)